@Test public void testMeters() { JsonExporter exporter = new JsonExporter(); MetricRegistry registry = MetricRegistries.get(MetricRegistry.Type.APPLICATION); Meter meterWithoutTags = registry.meter("mymeter"); Meter meterRed = registry.meter("mymeter", new Tag("color", "red")); Meter meterBlue = registry.meter("mymeter", new Tag("color", "blue"), new Tag("foo", "bar")); meterWithoutTags.mark(1); meterRed.mark(2); meterBlue.mark(3); String result = exporter.exportMetricsByName(MetricRegistry.Type.APPLICATION, "mymeter").toString(); JsonObject json = Json.createReader(new StringReader(result)).read().asJsonObject(); JsonObject myMeterObject = json.getJsonObject("mymeter"); assertEquals(1, myMeterObject.getInt("count")); assertEquals(2, myMeterObject.getInt("count;color=red")); assertEquals(3, myMeterObject.getInt("count;color=blue;foo=bar")); assertNotNull(myMeterObject.getJsonNumber("meanRate")); assertNotNull(myMeterObject.getJsonNumber("meanRate;color=red")); assertNotNull(myMeterObject.getJsonNumber("meanRate;color=blue;foo=bar")); assertNotNull(myMeterObject.getJsonNumber("oneMinRate")); assertNotNull(myMeterObject.getJsonNumber("oneMinRate;color=red")); assertNotNull(myMeterObject.getJsonNumber("oneMinRate;color=blue;foo=bar")); assertNotNull(myMeterObject.getJsonNumber("fiveMinRate")); assertNotNull(myMeterObject.getJsonNumber("fiveMinRate;color=red")); assertNotNull(myMeterObject.getJsonNumber("fiveMinRate;color=blue;foo=bar")); assertNotNull(myMeterObject.getJsonNumber("fifteenMinRate")); assertNotNull(myMeterObject.getJsonNumber("fifteenMinRate;color=red")); assertNotNull(myMeterObject.getJsonNumber("fifteenMinRate;color=blue;foo=bar")); }
@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();  }