@Test public void exportTimers() { OpenMetricsExporter exporter = new OpenMetricsExporter(); MetricRegistry registry = MetricRegistries.get(MetricRegistry.Type.APPLICATION); Metadata metadata = Metadata .builder() .withType(MetricType.TIMER) .withName("mytimer") .withDescription("awesome") .build(); Tag blueTag = new Tag("color", "blue"); Timer blueTimer = registry.timer(metadata, blueTag); Tag greenTag = new Tag("color", "green"); Timer greenTimer = registry.timer(metadata, greenTag); blueTimer.update(Duration.ofSeconds(3)); blueTimer.update(Duration.ofSeconds(4)); greenTimer.update(Duration.ofSeconds(5)); greenTimer.update(Duration.ofSeconds(6)); String result = exporter.exportMetricsByName(MetricRegistry.Type.APPLICATION, "mytimer").toString(); System.out.println(result); assertHasTypeLineExactlyOnce(result, "application_mytimer_seconds", "summary"); assertHasHelpLineExactlyOnce(result, "application_mytimer_seconds", "awesome"); assertHasValueLineExactlyOnce(result, "application_mytimer_elapsedTime_seconds", "7.0", blueTag); assertHasValueLineExactlyOnce(result, "application_mytimer_elapsedTime_seconds", "11.0", greenTag); assertHasValueLineExactlyOnce(result, "application_mytimer_seconds_count", "2.0", blueTag); assertHasValueLineExactlyOnce(result, "application_mytimer_seconds_count", "2.0", greenTag); assertHasTypeLineExactlyOnce(result, "application_mytimer_min_seconds", "gauge"); assertHasValueLineExactlyOnce(result, "application_mytimer_min_seconds", "3.0", blueTag); assertHasValueLineExactlyOnce(result, "application_mytimer_min_seconds", "5.0", greenTag); assertHasTypeLineExactlyOnce(result, "application_mytimer_max_seconds", "gauge"); assertHasValueLineExactlyOnce(result, "application_mytimer_max_seconds", "4.0", blueTag); assertHasValueLineExactlyOnce(result, "application_mytimer_max_seconds", "6.0", greenTag); assertHasTypeLineExactlyOnce(result, "application_mytimer_mean_seconds", "gauge"); assertHasValueLineExactlyOnce(result, "application_mytimer_mean_seconds", "3.5", blueTag); assertHasValueLineExactlyOnce(result, "application_mytimer_mean_seconds", "5.5", greenTag); assertHasTypeLineExactlyOnce(result, "application_mytimer_stddev_seconds", "gauge"); assertHasValueLineExactlyOnce(result, "application_mytimer_stddev_seconds", "0.5", blueTag); assertHasValueLineExactlyOnce(result, "application_mytimer_stddev_seconds", "0.5", greenTag); assertHasTypeLineExactlyOnce(result, "application_mytimer_rate_per_second", "gauge"); assertHasValueLineExactlyOnce(result, "application_mytimer_rate_per_second", "*", blueTag); assertHasValueLineExactlyOnce(result, "application_mytimer_rate_per_second", "*", greenTag); assertHasTypeLineExactlyOnce(result, "application_mytimer_one_min_rate_per_second", "gauge"); assertHasValueLineExactlyOnce(result, "application_mytimer_one_min_rate_per_second", "*", blueTag); assertHasValueLineExactlyOnce(result, "application_mytimer_one_min_rate_per_second", "*", greenTag); assertHasTypeLineExactlyOnce(result, "application_mytimer_five_min_rate_per_second", "gauge"); assertHasValueLineExactlyOnce(result, "application_mytimer_five_min_rate_per_second", "*", blueTag); assertHasValueLineExactlyOnce(result, "application_mytimer_five_min_rate_per_second", "*", greenTag); assertHasTypeLineExactlyOnce(result, "application_mytimer_fifteen_min_rate_per_second", "gauge"); assertHasValueLineExactlyOnce(result, "application_mytimer_fifteen_min_rate_per_second", "*", blueTag); assertHasValueLineExactlyOnce(result, "application_mytimer_fifteen_min_rate_per_second", "*", greenTag); assertHasValueLineExactlyOnce(result, "application_mytimer_seconds", "4.0", blueTag, QUANTILE_0_5); assertHasValueLineExactlyOnce(result, "application_mytimer_seconds", "4.0", blueTag, QUANTILE_0_75); assertHasValueLineExactlyOnce(result, "application_mytimer_seconds", "4.0", blueTag, QUANTILE_0_95); assertHasValueLineExactlyOnce(result, "application_mytimer_seconds", "4.0", blueTag, QUANTILE_0_98); assertHasValueLineExactlyOnce(result, "application_mytimer_seconds", "4.0", blueTag, QUANTILE_0_99); assertHasValueLineExactlyOnce(result, "application_mytimer_seconds", "4.0", blueTag, QUANTILE_0_999); assertHasValueLineExactlyOnce(result, "application_mytimer_seconds", "6.0", greenTag, QUANTILE_0_5); assertHasValueLineExactlyOnce(result, "application_mytimer_seconds", "6.0", greenTag, QUANTILE_0_75); assertHasValueLineExactlyOnce(result, "application_mytimer_seconds", "6.0", greenTag, QUANTILE_0_95); assertHasValueLineExactlyOnce(result, "application_mytimer_seconds", "6.0", greenTag, QUANTILE_0_98); assertHasValueLineExactlyOnce(result, "application_mytimer_seconds", "6.0", greenTag, QUANTILE_0_99); assertHasValueLineExactlyOnce(result, "application_mytimer_seconds", "6.0", greenTag, QUANTILE_0_999); }
@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; }