@Test public void exportByMetricNameWithOneMetricSingleTag() { JsonMetadataExporter exporter = new JsonMetadataExporter(); MetricRegistry applicationRegistry = MetricRegistries.get(MetricRegistry.Type.APPLICATION); applicationRegistry.counter("counter1", new Tag("key1", "value1")); String result = exporter.exportMetricsByName(MetricRegistry.Type.APPLICATION, "counter1").toString(); JsonObject json = Json.createReader(new StringReader(result)).read().asJsonObject(); JsonArray outerTagsArray = json.getJsonObject("counter1").getJsonArray("tags"); assertEquals(1, outerTagsArray.size()); JsonArray innerArray = outerTagsArray.getJsonArray(0); assertEquals(1, innerArray.size()); assertEquals("key1=value1", innerArray.getString(0)); }
@Override public StringBuilder exportMetricsByName(MetricRegistry.Type scope, String name) { MetricRegistry registry = MetricRegistries.get(scope); if (registry == null) { return null; } Metadata metadata = registry.getMetadata().get(name); if (metadata == null) { return null; } JsonObjectBuilder builder = JsonProviderHolder.get().createObjectBuilder(); metricJSON(builder, name, metadata, getKnownTagsByMetricName(registry, name)); return stringify(builder.build()); }
JsonMetadataExporter implements Exporter { @Override public StringBuilder exportMetricsByName(MetricRegistry.Type scope, String name) { MetricRegistry registry = MetricRegistries.get(scope); if (registry == null) { return null; } Metadata metadata = registry.getMetadata().get(name); if (metadata == null) { return null; } JsonObjectBuilder builder = JsonProviderHolder.get().createObjectBuilder(); metricJSON(builder, name, metadata, getKnownTagsByMetricName(registry, name)); return stringify(builder.build()); } }
JsonMetadataExporter implements Exporter { @Override public StringBuilder exportMetricsByName(MetricRegistry.Type scope, String name) { MetricRegistry registry = MetricRegistries.get(scope); if (registry == null) { return null; } Metadata metadata = registry.getMetadata().get(name); if (metadata == null) { return null; } JsonObjectBuilder builder = JsonProviderHolder.get().createObjectBuilder(); metricJSON(builder, name, metadata, getKnownTagsByMetricName(registry, name)); return stringify(builder.build()); } JsonMetadataExporter(); }
JsonMetadataExporter implements Exporter { @Override public StringBuilder exportMetricsByName(MetricRegistry.Type scope, String name) { MetricRegistry registry = MetricRegistries.get(scope); if (registry == null) { return null; } Metadata metadata = registry.getMetadata().get(name); if (metadata == null) { return null; } JsonObjectBuilder builder = JsonProviderHolder.get().createObjectBuilder(); metricJSON(builder, name, metadata, getKnownTagsByMetricName(registry, name)); return stringify(builder.build()); } JsonMetadataExporter(); @Override String getContentType(); @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); }
JsonMetadataExporter implements Exporter { @Override public StringBuilder exportMetricsByName(MetricRegistry.Type scope, String name) { MetricRegistry registry = MetricRegistries.get(scope); if (registry == null) { return null; } Metadata metadata = registry.getMetadata().get(name); if (metadata == null) { return null; } JsonObjectBuilder builder = JsonProviderHolder.get().createObjectBuilder(); metricJSON(builder, name, metadata, getKnownTagsByMetricName(registry, name)); return stringify(builder.build()); } JsonMetadataExporter(); @Override String getContentType(); @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);  }