@Test public void testExportOfDifferentHistogramImplementations() { JsonExporter exporter = new JsonExporter(); MetricRegistry applicationRegistry = MetricRegistries.get(MetricRegistry.Type.APPLICATION); Histogram[] histograms = { new HistogramImpl(new ExponentiallyDecayingReservoir()), new SomeHistogram() }; int idx = 0; for (Histogram h : histograms) { String name = "histo_" + idx++; applicationRegistry.register(name, h); StringBuilder out = exporter.exportOneMetric(MetricRegistry.Type.APPLICATION, new MetricID(name)); assertNotNull(out); System.out.println(out.toString()); List<String> lines = Arrays.asList(out.toString().split(LINE_SEPARATOR)); assertEquals(1, lines.stream().filter(line -> line.contains("\"" + name + "\"")).count()); assertEquals(1, lines.stream().filter(line -> line.contains("\"count\": 0")).count()); } }
@Override public StringBuilder exportOneMetric(MetricRegistry.Type scope, MetricID metricID) { MetricRegistry registry = MetricRegistries.get(scope); Map<MetricID, Metric> metricMap = registry.getMetrics(); Map<String, Metadata> metadataMap = registry.getMetadata(); Metric m = metricMap.get(metricID); Map<MetricID, Metric> outMap = new HashMap<>(1); outMap.put(metricID, m); JsonObjectBuilder root = JsonProviderHolder.get().createObjectBuilder(); exportMetricsForMap(outMap, metadataMap) .forEach(root::add); return stringify(root.build()); }
JsonExporter implements Exporter { @Override public StringBuilder exportOneMetric(MetricRegistry.Type scope, MetricID metricID) { MetricRegistry registry = MetricRegistries.get(scope); Map<MetricID, Metric> metricMap = registry.getMetrics(); Map<String, Metadata> metadataMap = registry.getMetadata(); Metric m = metricMap.get(metricID); Map<MetricID, Metric> outMap = new HashMap<>(1); outMap.put(metricID, m); JsonObjectBuilder root = JsonProviderHolder.get().createObjectBuilder(); exportMetricsForMap(outMap, metadataMap) .forEach(root::add); return stringify(root.build()); } }
JsonExporter implements Exporter { @Override public StringBuilder exportOneMetric(MetricRegistry.Type scope, MetricID metricID) { MetricRegistry registry = MetricRegistries.get(scope); Map<MetricID, Metric> metricMap = registry.getMetrics(); Map<String, Metadata> metadataMap = registry.getMetadata(); Metric m = metricMap.get(metricID); Map<MetricID, Metric> outMap = new HashMap<>(1); outMap.put(metricID, m); JsonObjectBuilder root = JsonProviderHolder.get().createObjectBuilder(); exportMetricsForMap(outMap, metadataMap) .forEach(root::add); return stringify(root.build()); } JsonExporter(); }
JsonExporter implements Exporter { @Override public StringBuilder exportOneMetric(MetricRegistry.Type scope, MetricID metricID) { MetricRegistry registry = MetricRegistries.get(scope); Map<MetricID, Metric> metricMap = registry.getMetrics(); Map<String, Metadata> metadataMap = registry.getMetadata(); Metric m = metricMap.get(metricID); Map<MetricID, Metric> outMap = new HashMap<>(1); outMap.put(metricID, m); JsonObjectBuilder root = JsonProviderHolder.get().createObjectBuilder(); exportMetricsForMap(outMap, metadataMap) .forEach(root::add); return stringify(root.build()); } JsonExporter(); @Override StringBuilder exportOneScope(MetricRegistry.Type scope); @Override StringBuilder exportAllScopes(); @Override StringBuilder exportOneMetric(MetricRegistry.Type scope, MetricID metricID); @Override StringBuilder exportMetricsByName(MetricRegistry.Type scope, String name); @Override String getContentType(); }
JsonExporter implements Exporter { @Override public StringBuilder exportOneMetric(MetricRegistry.Type scope, MetricID metricID) { MetricRegistry registry = MetricRegistries.get(scope); Map<MetricID, Metric> metricMap = registry.getMetrics(); Map<String, Metadata> metadataMap = registry.getMetadata(); Metric m = metricMap.get(metricID); Map<MetricID, Metric> outMap = new HashMap<>(1); outMap.put(metricID, m); JsonObjectBuilder root = JsonProviderHolder.get().createObjectBuilder(); exportMetricsForMap(outMap, metadataMap) .forEach(root::add); return stringify(root.build()); } JsonExporter(); @Override StringBuilder exportOneScope(MetricRegistry.Type scope); @Override StringBuilder exportAllScopes(); @Override StringBuilder exportOneMetric(MetricRegistry.Type scope, MetricID metricID); @Override StringBuilder exportMetricsByName(MetricRegistry.Type scope, String name); @Override String getContentType();  }