@Test public void exportCounters() { OpenMetricsExporter exporter = new OpenMetricsExporter(); MetricRegistry registry = MetricRegistries.get(MetricRegistry.Type.APPLICATION); Metadata metadata = Metadata .builder() .withType(MetricType.COUNTER) .withName("mycounter") .withDescription("awesome") .build(); Tag blueTag = new Tag("color", "blue"); Counter blueCounter = registry.counter(metadata, blueTag); Tag greenTag = new Tag("color", "green"); Counter greenCounter = registry.counter(metadata, greenTag); blueCounter.inc(10); greenCounter.inc(20); String result = exporter.exportMetricsByName(MetricRegistry.Type.APPLICATION, "mycounter").toString(); System.out.println(result); assertHasTypeLineExactlyOnce(result, "application_mycounter_total", "counter"); assertHasHelpLineExactlyOnce(result, "application_mycounter_total", "awesome"); assertHasValueLineExactlyOnce(result, "application_mycounter_total", "10.0", blueTag); assertHasValueLineExactlyOnce(result, "application_mycounter_total", "20.0", greenTag); }
@Override public StringBuilder exportMetricsByName(MetricRegistry.Type scope, String name) { alreadyExportedNames.set(new HashSet<>()); MetricRegistry registry = MetricRegistries.get(scope); Map<MetricID, Metric> metricsToExport = registry.getMetrics() .entrySet() .stream() .filter(entry -> entry.getKey().getName().equals(name)) .collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue)); StringBuilder sb = new StringBuilder(); exposeEntries(scope, sb, registry, metricsToExport); alreadyExportedNames.set(null); return sb; }
OpenMetricsExporter implements Exporter { @Override public StringBuilder exportMetricsByName(MetricRegistry.Type scope, String name) { alreadyExportedNames.set(new HashSet<>()); MetricRegistry registry = MetricRegistries.get(scope); Map<MetricID, Metric> metricsToExport = registry.getMetrics() .entrySet() .stream() .filter(entry -> entry.getKey().getName().equals(name)) .collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue)); StringBuilder sb = new StringBuilder(); exposeEntries(scope, sb, registry, metricsToExport); alreadyExportedNames.set(null); return sb; } }
OpenMetricsExporter implements Exporter { @Override public StringBuilder exportMetricsByName(MetricRegistry.Type scope, String name) { alreadyExportedNames.set(new HashSet<>()); MetricRegistry registry = MetricRegistries.get(scope); Map<MetricID, Metric> metricsToExport = registry.getMetrics() .entrySet() .stream() .filter(entry -> entry.getKey().getName().equals(name)) .collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue)); StringBuilder sb = new StringBuilder(); exposeEntries(scope, sb, registry, metricsToExport); alreadyExportedNames.set(null); return sb; } OpenMetricsExporter(); }
OpenMetricsExporter implements Exporter { @Override public StringBuilder exportMetricsByName(MetricRegistry.Type scope, String name) { alreadyExportedNames.set(new HashSet<>()); MetricRegistry registry = MetricRegistries.get(scope); Map<MetricID, Metric> metricsToExport = registry.getMetrics() .entrySet() .stream() .filter(entry -> entry.getKey().getName().equals(name)) .collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue)); StringBuilder sb = new StringBuilder(); exposeEntries(scope, sb, registry, metricsToExport); alreadyExportedNames.set(null); return sb; } OpenMetricsExporter(); @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(); static String quoteHelpText(String value); static String quoteValue(String value); }
OpenMetricsExporter implements Exporter { @Override public StringBuilder exportMetricsByName(MetricRegistry.Type scope, String name) { alreadyExportedNames.set(new HashSet<>()); MetricRegistry registry = MetricRegistries.get(scope); Map<MetricID, Metric> metricsToExport = registry.getMetrics() .entrySet() .stream() .filter(entry -> entry.getKey().getName().equals(name)) .collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue)); StringBuilder sb = new StringBuilder(); exposeEntries(scope, sb, registry, metricsToExport); alreadyExportedNames.set(null); return sb; } OpenMetricsExporter(); @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(); static String quoteHelpText(String value); static String quoteValue(String value); static final String SMALLRYE_METRICS_USE_PREFIX_FOR_SCOPE; }