@ManagedAttribute public Map<String, Object> getStats() { Map<String, Object> stats = new HashMap<String, Object>(); MetricsRegistry registry = Metrics.defaultRegistry(); for (Entry<MetricName, Metric> e : registry.allMetrics().entrySet()) { MetricName name = e.getKey(); Metric metric = e.getValue(); if (metric instanceof Meter) { Meter m = (Meter) metric; stats.put(name.toString(), new MeterPOJO(m)); } else if (metric instanceof Gauge) { Gauge<?> g = (Gauge<?>) metric; stats.put(name.toString(), g.value()); } } return stats; } }
private boolean maybeIngestLog( BiFunction<MetricName, MetricMatcher, Metric> metricLoader, MetricMatcher metricMatcher, LogsMessage logsMessage) { Double[] output = {null}; TimeSeries timeSeries = metricMatcher.timeSeries(logsMessage, output); if (timeSeries == null) return false; MetricName metricName = TimeSeriesUtils.toMetricName(timeSeries); Metric metric = metricLoader.apply(metricName, metricMatcher); try { metric.processWith(readProcessor, metricName, new ReadProcessorContext(output[0])); } catch (Exception e) { logger.log(Level.SEVERE, "Could not process metric " + metricName.toString(), e); } return true; } }
private boolean maybeIngestLog( BiFunction<MetricName, MetricMatcher, Metric> metricLoader, MetricMatcher metricMatcher, LogsMessage logsMessage) { Double[] output = {null}; TimeSeries timeSeries = metricMatcher.timeSeries(logsMessage, output); if (timeSeries == null) return false; MetricName metricName = TimeSeriesUtils.toMetricName(timeSeries); Metric metric = metricLoader.apply(metricName, metricMatcher); try { metric.processWith(readProcessor, metricName, new ReadProcessorContext(output[0])); } catch (Exception e) { logger.log(Level.SEVERE, "Could not process metric " + metricName.toString(), e); } return true; } }