@Test public void testHistograms() { JsonExporter exporter = new JsonExporter(); MetricRegistry registry = MetricRegistries.get(MetricRegistry.Type.APPLICATION); Histogram histogramWithoutTags = registry.histogram("myhistogram"); Histogram histogramRed = registry.histogram("myhistogram", new Tag("color", "red")); Histogram histogramBlue = registry.histogram("myhistogram", new Tag("color", "blue"), new Tag("foo", "bar")); histogramWithoutTags.update(1); histogramRed.update(2); histogramBlue.update(3); String result = exporter.exportMetricsByName(MetricRegistry.Type.APPLICATION, "myhistogram").toString(); JsonObject json = Json.createReader(new StringReader(result)).read().asJsonObject(); JsonObject myhistogramObject = json.getJsonObject("myhistogram"); assertEquals(1.0, myhistogramObject.getJsonNumber("count").doubleValue(), 1e-10); assertEquals(1.0, myhistogramObject.getJsonNumber("count;color=red").doubleValue(), 1e-10); assertEquals(1.0, myhistogramObject.getJsonNumber("count;color=blue;foo=bar").doubleValue(), 1e-10); assertEquals(1.0, myhistogramObject.getJsonNumber("p50").doubleValue(), 1e-10); assertEquals(2.0, myhistogramObject.getJsonNumber("p50;color=red").doubleValue(), 1e-10); assertEquals(3.0, myhistogramObject.getJsonNumber("p50;color=blue;foo=bar").doubleValue(), 1e-10); assertEquals(1.0, myhistogramObject.getJsonNumber("p75").doubleValue(), 1e-10); assertEquals(2.0, myhistogramObject.getJsonNumber("p75;color=red").doubleValue(), 1e-10); assertEquals(3.0, myhistogramObject.getJsonNumber("p75;color=blue;foo=bar").doubleValue(), 1e-10); assertEquals(1.0, myhistogramObject.getJsonNumber("p95").doubleValue(), 1e-10); assertEquals(2.0, myhistogramObject.getJsonNumber("p95;color=red").doubleValue(), 1e-10); assertEquals(3.0, myhistogramObject.getJsonNumber("p95;color=blue;foo=bar").doubleValue(), 1e-10); assertEquals(1.0, myhistogramObject.getJsonNumber("p98").doubleValue(), 1e-10); assertEquals(2.0, myhistogramObject.getJsonNumber("p98;color=red").doubleValue(), 1e-10); assertEquals(3.0, myhistogramObject.getJsonNumber("p98;color=blue;foo=bar").doubleValue(), 1e-10); assertEquals(1.0, myhistogramObject.getJsonNumber("p99").doubleValue(), 1e-10); assertEquals(2.0, myhistogramObject.getJsonNumber("p99;color=red").doubleValue(), 1e-10); assertEquals(3.0, myhistogramObject.getJsonNumber("p99;color=blue;foo=bar").doubleValue(), 1e-10); assertEquals(1.0, myhistogramObject.getJsonNumber("p999").doubleValue(), 1e-10); assertEquals(2.0, myhistogramObject.getJsonNumber("p999;color=red").doubleValue(), 1e-10); assertEquals(3.0, myhistogramObject.getJsonNumber("p999;color=blue;foo=bar").doubleValue(), 1e-10); assertEquals(1.0, myhistogramObject.getJsonNumber("min").doubleValue(), 1e-10); assertEquals(2.0, myhistogramObject.getJsonNumber("min;color=red").doubleValue(), 1e-10); assertEquals(3.0, myhistogramObject.getJsonNumber("min;color=blue;foo=bar").doubleValue(), 1e-10); assertEquals(1.0, myhistogramObject.getJsonNumber("mean").doubleValue(), 1e-10); assertEquals(2.0, myhistogramObject.getJsonNumber("mean;color=red").doubleValue(), 1e-10); assertEquals(3.0, myhistogramObject.getJsonNumber("mean;color=blue;foo=bar").doubleValue(), 1e-10); assertEquals(1.0, myhistogramObject.getJsonNumber("max").doubleValue(), 1e-10); assertEquals(2.0, myhistogramObject.getJsonNumber("max;color=red").doubleValue(), 1e-10); assertEquals(3.0, myhistogramObject.getJsonNumber("max;color=blue;foo=bar").doubleValue(), 1e-10); assertEquals(0.0, myhistogramObject.getJsonNumber("stddev").doubleValue(), 1e-10); assertEquals(0.0, myhistogramObject.getJsonNumber("stddev;color=red").doubleValue(), 1e-10); assertEquals(0.0, myhistogramObject.getJsonNumber("stddev;color=blue;foo=bar").doubleValue(), 1e-10); }
@Override public StringBuilder exportMetricsByName(MetricRegistry.Type scope, String name) { MetricRegistry registry = MetricRegistries.get(scope); Map<MetricID, Metric> metricMap = registry.getMetrics() .entrySet() .stream() .filter(e -> e.getKey().getName().equals(name)) .collect(Collectors.toMap( Map.Entry::getKey, Map.Entry::getValue)); Map<String, Metadata> metadataMap = registry.getMetadata(); JsonObjectBuilder root = JsonProviderHolder.get().createObjectBuilder(); exportMetricsForMap(metricMap, metadataMap) .forEach(root::add); return stringify(root.build()); }
JsonExporter implements Exporter { @Override public StringBuilder exportMetricsByName(MetricRegistry.Type scope, String name) { MetricRegistry registry = MetricRegistries.get(scope); Map<MetricID, Metric> metricMap = registry.getMetrics() .entrySet() .stream() .filter(e -> e.getKey().getName().equals(name)) .collect(Collectors.toMap( Map.Entry::getKey, Map.Entry::getValue)); Map<String, Metadata> metadataMap = registry.getMetadata(); JsonObjectBuilder root = JsonProviderHolder.get().createObjectBuilder(); exportMetricsForMap(metricMap, metadataMap) .forEach(root::add); return stringify(root.build()); } }
JsonExporter implements Exporter { @Override public StringBuilder exportMetricsByName(MetricRegistry.Type scope, String name) { MetricRegistry registry = MetricRegistries.get(scope); Map<MetricID, Metric> metricMap = registry.getMetrics() .entrySet() .stream() .filter(e -> e.getKey().getName().equals(name)) .collect(Collectors.toMap( Map.Entry::getKey, Map.Entry::getValue)); Map<String, Metadata> metadataMap = registry.getMetadata(); JsonObjectBuilder root = JsonProviderHolder.get().createObjectBuilder(); exportMetricsForMap(metricMap, metadataMap) .forEach(root::add); return stringify(root.build()); } JsonExporter(); }
JsonExporter implements Exporter { @Override public StringBuilder exportMetricsByName(MetricRegistry.Type scope, String name) { MetricRegistry registry = MetricRegistries.get(scope); Map<MetricID, Metric> metricMap = registry.getMetrics() .entrySet() .stream() .filter(e -> e.getKey().getName().equals(name)) .collect(Collectors.toMap( Map.Entry::getKey, Map.Entry::getValue)); Map<String, Metadata> metadataMap = registry.getMetadata(); JsonObjectBuilder root = JsonProviderHolder.get().createObjectBuilder(); exportMetricsForMap(metricMap, 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 exportMetricsByName(MetricRegistry.Type scope, String name) { MetricRegistry registry = MetricRegistries.get(scope); Map<MetricID, Metric> metricMap = registry.getMetrics() .entrySet() .stream() .filter(e -> e.getKey().getName().equals(name)) .collect(Collectors.toMap( Map.Entry::getKey, Map.Entry::getValue)); Map<String, Metadata> metadataMap = registry.getMetadata(); JsonObjectBuilder root = JsonProviderHolder.get().createObjectBuilder(); exportMetricsForMap(metricMap, 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();  }