@Test public void exportHistograms() { OpenMetricsExporter exporter = new OpenMetricsExporter(); MetricRegistry registry = MetricRegistries.get(MetricRegistry.Type.APPLICATION); Metadata metadata = Metadata .builder() .withType(MetricType.HISTOGRAM) .withName("MyHisto") .withDescription("awesome") .build(); Tag blueTag = new Tag("color", "blue"); Histogram histogram1 = registry.histogram(metadata, blueTag); Tag greenTag = new Tag("color", "green"); Histogram histogram2 = registry.histogram(metadata, greenTag); histogram1.update(5); histogram1.update(9); histogram2.update(10); histogram2.update(12); String result = exporter.exportMetricsByName(MetricRegistry.Type.APPLICATION, "MyHisto").toString(); System.out.println(result); assertHasValueLineExactlyOnce(result, "application_MyHisto_min", "5.0", blueTag); assertHasValueLineExactlyOnce(result, "application_MyHisto_max", "9.0", blueTag); assertHasValueLineExactlyOnce(result, "application_MyHisto_mean", "7.0", blueTag); assertHasValueLineExactlyOnce(result, "application_MyHisto_stddev", "2.0", blueTag); assertHasValueLineExactlyOnce(result, "application_MyHisto_count", "2.0", blueTag); assertHasValueLineExactlyOnce(result, "application_MyHisto", "9.0", blueTag, QUANTILE_0_5); assertHasValueLineExactlyOnce(result, "application_MyHisto", "9.0", blueTag, QUANTILE_0_75); assertHasValueLineExactlyOnce(result, "application_MyHisto", "9.0", blueTag, QUANTILE_0_95); assertHasValueLineExactlyOnce(result, "application_MyHisto", "9.0", blueTag, QUANTILE_0_98); assertHasValueLineExactlyOnce(result, "application_MyHisto", "9.0", blueTag, QUANTILE_0_99); assertHasValueLineExactlyOnce(result, "application_MyHisto", "9.0", blueTag, QUANTILE_0_999); assertHasValueLineExactlyOnce(result, "application_MyHisto_min", "10.0", greenTag); assertHasValueLineExactlyOnce(result, "application_MyHisto_max", "12.0", greenTag); assertHasValueLineExactlyOnce(result, "application_MyHisto_mean", "11.0", greenTag); assertHasValueLineExactlyOnce(result, "application_MyHisto_stddev", "1.0", greenTag); assertHasValueLineExactlyOnce(result, "application_MyHisto_count", "2.0", greenTag); assertHasValueLineExactlyOnce(result, "application_MyHisto", "12.0", greenTag, QUANTILE_0_5); assertHasValueLineExactlyOnce(result, "application_MyHisto", "12.0", greenTag, QUANTILE_0_75); assertHasValueLineExactlyOnce(result, "application_MyHisto", "12.0", greenTag, QUANTILE_0_95); assertHasValueLineExactlyOnce(result, "application_MyHisto", "12.0", greenTag, QUANTILE_0_98); assertHasValueLineExactlyOnce(result, "application_MyHisto", "12.0", greenTag, QUANTILE_0_99); assertHasValueLineExactlyOnce(result, "application_MyHisto", "12.0", greenTag, QUANTILE_0_999); assertHasTypeLineExactlyOnce(result, "application_MyHisto_min", "gauge"); assertHasTypeLineExactlyOnce(result, "application_MyHisto_max", "gauge"); assertHasTypeLineExactlyOnce(result, "application_MyHisto_mean", "gauge"); assertHasTypeLineExactlyOnce(result, "application_MyHisto_stddev", "gauge"); assertHasTypeLineExactlyOnce(result, "application_MyHisto", "summary"); assertHasHelpLineExactlyOnce(result, "application_MyHisto", "awesome"); }
@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; }