@Test void testPrometheus() { final StringBuilder sb = new StringBuilder(); dataSetTimer.prometheusData(sb, dataSetTimerID, true); final String prometheusData = sb.toString(); assertThat(prometheusData, startsWith("# TYPE application_response_time_rate_per_second gauge\n" + "application_response_time_rate_per_second 200.0\n" + "# TYPE application_response_time_one_min_rate_per_second gauge\n" + "application_response_time_one_min_rate_per_second 0.0\n" + "# TYPE application_response_time_five_min_rate_per_second gauge\n" + "application_response_time_five_min_rate_per_second 0.0\n" + "# TYPE application_response_time_fifteen_min_rate_per_second gauge\n" + "application_response_time_fifteen_min_rate_per_second 0.0\n" + "# TYPE application_response_time_mean_seconds gauge\n" + "application_response_time_mean_seconds ")); assertThat(prometheusData, containsString("# TYPE application_response_time_max_seconds gauge\n" + "application_response_time_max_seconds ")); assertThat(prometheusData, containsString("# TYPE application_response_time_seconds summary\n" + "# HELP application_response_time_seconds Server response time for " + "/index.html\n" + "application_response_time_seconds_count 200")); }
@Override public void prometheusData(StringBuilder sb, MetricID metricID, boolean withHelpType) { String nameUnits; String name = metricID.getName(); String tags = prometheusTags(metricID.getTags()); nameUnits = prometheusNameWithUnits(name, Optional.empty()) + "_rate_per_second"; if (withHelpType) { prometheusType(sb, nameUnits, "gauge"); } sb.append(nameUnits) .append(tags) .append(" ") .append(getMeanRate()) .append("\n"); nameUnits = prometheusNameWithUnits(name, Optional.empty()) + "_one_min_rate_per_second"; if (withHelpType) { prometheusType(sb, nameUnits, "gauge"); } sb.append(nameUnits) .append(tags) .append(" ") .append(getOneMinuteRate()) .append("\n"); nameUnits = prometheusNameWithUnits(name, Optional.empty()) + "_five_min_rate_per_second"; if (withHelpType) { prometheusType(sb, nameUnits, "gauge"); } sb.append(nameUnits) .append(tags) .append(" ") .append(getFiveMinuteRate()) .append("\n"); nameUnits = prometheusNameWithUnits(name, Optional.empty()) + "_fifteen_min_rate_per_second"; if (withHelpType) { prometheusType(sb, nameUnits, "gauge"); } sb.append(nameUnits) .append(tags) .append(" ") .append(getFifteenMinuteRate()) .append("\n"); Units units = getUnits(); Optional<String> unit = units.getPrometheusUnit(); Snapshot snap = getSnapshot(); nameUnits = prometheusNameWithUnits(name + "_mean", unit); if (withHelpType) { prometheusType(sb, nameUnits, "gauge"); } sb.append(nameUnits) .append(tags) .append(" ") .append(units.convert(snap.getMean())) .append("\n"); nameUnits = prometheusNameWithUnits(name + "_max", unit); if (withHelpType) { prometheusType(sb, nameUnits, "gauge"); } sb.append(nameUnits) .append(tags) .append(" ") .append(units.convert(snap.getMax())) .append("\n"); nameUnits = prometheusNameWithUnits(name + "_min", unit); if (withHelpType) { prometheusType(sb, nameUnits, "gauge"); } sb.append(nameUnits) .append(tags) .append(" ") .append(units.convert(snap.getMin())) .append("\n"); nameUnits = prometheusNameWithUnits(name + "_stddev", unit); if (withHelpType) { prometheusType(sb, nameUnits, "gauge"); } sb.append(nameUnits) .append(tags) .append(" ") .append(units.convert(snap.getStdDev())) .append("\n"); nameUnits = prometheusNameWithUnits(name, unit); if (withHelpType) { prometheusType(sb, nameUnits, "summary"); prometheusHelp(sb, nameUnits); } nameUnits = prometheusNameWithUnits(name, unit) + "_count"; sb.append(nameUnits) .append(tags) .append(" ") .append(getCount()) .append('\n'); nameUnits = prometheusNameWithUnits(name, unit); prometheusQuantile(sb, tags, units, nameUnits, "0.5", snap::getMedian); prometheusQuantile(sb, tags, units, nameUnits, "0.75", snap::get75thPercentile); prometheusQuantile(sb, tags, units, nameUnits, "0.95", snap::get95thPercentile); prometheusQuantile(sb, tags, units, nameUnits, "0.98", snap::get98thPercentile); prometheusQuantile(sb, tags, units, nameUnits, "0.99", snap::get99thPercentile); prometheusQuantile(sb, tags, units, nameUnits, "0.999", snap::get999thPercentile); }
HelidonTimer extends MetricImpl implements Timer { @Override public void prometheusData(StringBuilder sb, MetricID metricID, boolean withHelpType) { String nameUnits; String name = metricID.getName(); String tags = prometheusTags(metricID.getTags()); nameUnits = prometheusNameWithUnits(name, Optional.empty()) + "_rate_per_second"; if (withHelpType) { prometheusType(sb, nameUnits, "gauge"); } sb.append(nameUnits) .append(tags) .append(" ") .append(getMeanRate()) .append("\n"); nameUnits = prometheusNameWithUnits(name, Optional.empty()) + "_one_min_rate_per_second"; if (withHelpType) { prometheusType(sb, nameUnits, "gauge"); } sb.append(nameUnits) .append(tags) .append(" ") .append(getOneMinuteRate()) .append("\n"); nameUnits = prometheusNameWithUnits(name, Optional.empty()) + "_five_min_rate_per_second"; if (withHelpType) { prometheusType(sb, nameUnits, "gauge"); } sb.append(nameUnits) .append(tags) .append(" ") .append(getFiveMinuteRate()) .append("\n"); nameUnits = prometheusNameWithUnits(name, Optional.empty()) + "_fifteen_min_rate_per_second"; if (withHelpType) { prometheusType(sb, nameUnits, "gauge"); } sb.append(nameUnits) .append(tags) .append(" ") .append(getFifteenMinuteRate()) .append("\n"); Units units = getUnits(); Optional<String> unit = units.getPrometheusUnit(); Snapshot snap = getSnapshot(); nameUnits = prometheusNameWithUnits(name + "_mean", unit); if (withHelpType) { prometheusType(sb, nameUnits, "gauge"); } sb.append(nameUnits) .append(tags) .append(" ") .append(units.convert(snap.getMean())) .append("\n"); nameUnits = prometheusNameWithUnits(name + "_max", unit); if (withHelpType) { prometheusType(sb, nameUnits, "gauge"); } sb.append(nameUnits) .append(tags) .append(" ") .append(units.convert(snap.getMax())) .append("\n"); nameUnits = prometheusNameWithUnits(name + "_min", unit); if (withHelpType) { prometheusType(sb, nameUnits, "gauge"); } sb.append(nameUnits) .append(tags) .append(" ") .append(units.convert(snap.getMin())) .append("\n"); nameUnits = prometheusNameWithUnits(name + "_stddev", unit); if (withHelpType) { prometheusType(sb, nameUnits, "gauge"); } sb.append(nameUnits) .append(tags) .append(" ") .append(units.convert(snap.getStdDev())) .append("\n"); nameUnits = prometheusNameWithUnits(name, unit); if (withHelpType) { prometheusType(sb, nameUnits, "summary"); prometheusHelp(sb, nameUnits); } nameUnits = prometheusNameWithUnits(name, unit) + "_count"; sb.append(nameUnits) .append(tags) .append(" ") .append(getCount()) .append('\n'); nameUnits = prometheusNameWithUnits(name, unit); prometheusQuantile(sb, tags, units, nameUnits, "0.5", snap::getMedian); prometheusQuantile(sb, tags, units, nameUnits, "0.75", snap::get75thPercentile); prometheusQuantile(sb, tags, units, nameUnits, "0.95", snap::get95thPercentile); prometheusQuantile(sb, tags, units, nameUnits, "0.98", snap::get98thPercentile); prometheusQuantile(sb, tags, units, nameUnits, "0.99", snap::get99thPercentile); prometheusQuantile(sb, tags, units, nameUnits, "0.999", snap::get999thPercentile); } }
HelidonTimer extends MetricImpl implements Timer { @Override public void prometheusData(StringBuilder sb, MetricID metricID, boolean withHelpType) { String nameUnits; String name = metricID.getName(); String tags = prometheusTags(metricID.getTags()); nameUnits = prometheusNameWithUnits(name, Optional.empty()) + "_rate_per_second"; if (withHelpType) { prometheusType(sb, nameUnits, "gauge"); } sb.append(nameUnits) .append(tags) .append(" ") .append(getMeanRate()) .append("\n"); nameUnits = prometheusNameWithUnits(name, Optional.empty()) + "_one_min_rate_per_second"; if (withHelpType) { prometheusType(sb, nameUnits, "gauge"); } sb.append(nameUnits) .append(tags) .append(" ") .append(getOneMinuteRate()) .append("\n"); nameUnits = prometheusNameWithUnits(name, Optional.empty()) + "_five_min_rate_per_second"; if (withHelpType) { prometheusType(sb, nameUnits, "gauge"); } sb.append(nameUnits) .append(tags) .append(" ") .append(getFiveMinuteRate()) .append("\n"); nameUnits = prometheusNameWithUnits(name, Optional.empty()) + "_fifteen_min_rate_per_second"; if (withHelpType) { prometheusType(sb, nameUnits, "gauge"); } sb.append(nameUnits) .append(tags) .append(" ") .append(getFifteenMinuteRate()) .append("\n"); Units units = getUnits(); Optional<String> unit = units.getPrometheusUnit(); Snapshot snap = getSnapshot(); nameUnits = prometheusNameWithUnits(name + "_mean", unit); if (withHelpType) { prometheusType(sb, nameUnits, "gauge"); } sb.append(nameUnits) .append(tags) .append(" ") .append(units.convert(snap.getMean())) .append("\n"); nameUnits = prometheusNameWithUnits(name + "_max", unit); if (withHelpType) { prometheusType(sb, nameUnits, "gauge"); } sb.append(nameUnits) .append(tags) .append(" ") .append(units.convert(snap.getMax())) .append("\n"); nameUnits = prometheusNameWithUnits(name + "_min", unit); if (withHelpType) { prometheusType(sb, nameUnits, "gauge"); } sb.append(nameUnits) .append(tags) .append(" ") .append(units.convert(snap.getMin())) .append("\n"); nameUnits = prometheusNameWithUnits(name + "_stddev", unit); if (withHelpType) { prometheusType(sb, nameUnits, "gauge"); } sb.append(nameUnits) .append(tags) .append(" ") .append(units.convert(snap.getStdDev())) .append("\n"); nameUnits = prometheusNameWithUnits(name, unit); if (withHelpType) { prometheusType(sb, nameUnits, "summary"); prometheusHelp(sb, nameUnits); } nameUnits = prometheusNameWithUnits(name, unit) + "_count"; sb.append(nameUnits) .append(tags) .append(" ") .append(getCount()) .append('\n'); nameUnits = prometheusNameWithUnits(name, unit); prometheusQuantile(sb, tags, units, nameUnits, "0.5", snap::getMedian); prometheusQuantile(sb, tags, units, nameUnits, "0.75", snap::get75thPercentile); prometheusQuantile(sb, tags, units, nameUnits, "0.95", snap::get95thPercentile); prometheusQuantile(sb, tags, units, nameUnits, "0.98", snap::get98thPercentile); prometheusQuantile(sb, tags, units, nameUnits, "0.99", snap::get99thPercentile); prometheusQuantile(sb, tags, units, nameUnits, "0.999", snap::get999thPercentile); } private  HelidonTimer(String type, Metadata metadata, Timer delegate); }
HelidonTimer extends MetricImpl implements Timer { @Override public void prometheusData(StringBuilder sb, MetricID metricID, boolean withHelpType) { String nameUnits; String name = metricID.getName(); String tags = prometheusTags(metricID.getTags()); nameUnits = prometheusNameWithUnits(name, Optional.empty()) + "_rate_per_second"; if (withHelpType) { prometheusType(sb, nameUnits, "gauge"); } sb.append(nameUnits) .append(tags) .append(" ") .append(getMeanRate()) .append("\n"); nameUnits = prometheusNameWithUnits(name, Optional.empty()) + "_one_min_rate_per_second"; if (withHelpType) { prometheusType(sb, nameUnits, "gauge"); } sb.append(nameUnits) .append(tags) .append(" ") .append(getOneMinuteRate()) .append("\n"); nameUnits = prometheusNameWithUnits(name, Optional.empty()) + "_five_min_rate_per_second"; if (withHelpType) { prometheusType(sb, nameUnits, "gauge"); } sb.append(nameUnits) .append(tags) .append(" ") .append(getFiveMinuteRate()) .append("\n"); nameUnits = prometheusNameWithUnits(name, Optional.empty()) + "_fifteen_min_rate_per_second"; if (withHelpType) { prometheusType(sb, nameUnits, "gauge"); } sb.append(nameUnits) .append(tags) .append(" ") .append(getFifteenMinuteRate()) .append("\n"); Units units = getUnits(); Optional<String> unit = units.getPrometheusUnit(); Snapshot snap = getSnapshot(); nameUnits = prometheusNameWithUnits(name + "_mean", unit); if (withHelpType) { prometheusType(sb, nameUnits, "gauge"); } sb.append(nameUnits) .append(tags) .append(" ") .append(units.convert(snap.getMean())) .append("\n"); nameUnits = prometheusNameWithUnits(name + "_max", unit); if (withHelpType) { prometheusType(sb, nameUnits, "gauge"); } sb.append(nameUnits) .append(tags) .append(" ") .append(units.convert(snap.getMax())) .append("\n"); nameUnits = prometheusNameWithUnits(name + "_min", unit); if (withHelpType) { prometheusType(sb, nameUnits, "gauge"); } sb.append(nameUnits) .append(tags) .append(" ") .append(units.convert(snap.getMin())) .append("\n"); nameUnits = prometheusNameWithUnits(name + "_stddev", unit); if (withHelpType) { prometheusType(sb, nameUnits, "gauge"); } sb.append(nameUnits) .append(tags) .append(" ") .append(units.convert(snap.getStdDev())) .append("\n"); nameUnits = prometheusNameWithUnits(name, unit); if (withHelpType) { prometheusType(sb, nameUnits, "summary"); prometheusHelp(sb, nameUnits); } nameUnits = prometheusNameWithUnits(name, unit) + "_count"; sb.append(nameUnits) .append(tags) .append(" ") .append(getCount()) .append('\n'); nameUnits = prometheusNameWithUnits(name, unit); prometheusQuantile(sb, tags, units, nameUnits, "0.5", snap::getMedian); prometheusQuantile(sb, tags, units, nameUnits, "0.75", snap::get75thPercentile); prometheusQuantile(sb, tags, units, nameUnits, "0.95", snap::get95thPercentile); prometheusQuantile(sb, tags, units, nameUnits, "0.98", snap::get98thPercentile); prometheusQuantile(sb, tags, units, nameUnits, "0.99", snap::get99thPercentile); prometheusQuantile(sb, tags, units, nameUnits, "0.999", snap::get999thPercentile); } private  HelidonTimer(String type, Metadata metadata, Timer delegate); @Override void update(long duration, TimeUnit unit); @Override T time(Callable<T> event); @Override void time(Runnable event); @Override Context time(); @Override long getCount(); @Override double getFifteenMinuteRate(); @Override double getFiveMinuteRate(); @Override double getMeanRate(); @Override double getOneMinuteRate(); @Override Snapshot getSnapshot(); @Override void prometheusData(StringBuilder sb, MetricID metricID, boolean withHelpType); @Override String prometheusValue(); @Override void jsonData(JsonObjectBuilder builder, MetricID metricID); @Override boolean equals(Object o); @Override int hashCode(); }
HelidonTimer extends MetricImpl implements Timer { @Override public void prometheusData(StringBuilder sb, MetricID metricID, boolean withHelpType) { String nameUnits; String name = metricID.getName(); String tags = prometheusTags(metricID.getTags()); nameUnits = prometheusNameWithUnits(name, Optional.empty()) + "_rate_per_second"; if (withHelpType) { prometheusType(sb, nameUnits, "gauge"); } sb.append(nameUnits) .append(tags) .append(" ") .append(getMeanRate()) .append("\n"); nameUnits = prometheusNameWithUnits(name, Optional.empty()) + "_one_min_rate_per_second"; if (withHelpType) { prometheusType(sb, nameUnits, "gauge"); } sb.append(nameUnits) .append(tags) .append(" ") .append(getOneMinuteRate()) .append("\n"); nameUnits = prometheusNameWithUnits(name, Optional.empty()) + "_five_min_rate_per_second"; if (withHelpType) { prometheusType(sb, nameUnits, "gauge"); } sb.append(nameUnits) .append(tags) .append(" ") .append(getFiveMinuteRate()) .append("\n"); nameUnits = prometheusNameWithUnits(name, Optional.empty()) + "_fifteen_min_rate_per_second"; if (withHelpType) { prometheusType(sb, nameUnits, "gauge"); } sb.append(nameUnits) .append(tags) .append(" ") .append(getFifteenMinuteRate()) .append("\n"); Units units = getUnits(); Optional<String> unit = units.getPrometheusUnit(); Snapshot snap = getSnapshot(); nameUnits = prometheusNameWithUnits(name + "_mean", unit); if (withHelpType) { prometheusType(sb, nameUnits, "gauge"); } sb.append(nameUnits) .append(tags) .append(" ") .append(units.convert(snap.getMean())) .append("\n"); nameUnits = prometheusNameWithUnits(name + "_max", unit); if (withHelpType) { prometheusType(sb, nameUnits, "gauge"); } sb.append(nameUnits) .append(tags) .append(" ") .append(units.convert(snap.getMax())) .append("\n"); nameUnits = prometheusNameWithUnits(name + "_min", unit); if (withHelpType) { prometheusType(sb, nameUnits, "gauge"); } sb.append(nameUnits) .append(tags) .append(" ") .append(units.convert(snap.getMin())) .append("\n"); nameUnits = prometheusNameWithUnits(name + "_stddev", unit); if (withHelpType) { prometheusType(sb, nameUnits, "gauge"); } sb.append(nameUnits) .append(tags) .append(" ") .append(units.convert(snap.getStdDev())) .append("\n"); nameUnits = prometheusNameWithUnits(name, unit); if (withHelpType) { prometheusType(sb, nameUnits, "summary"); prometheusHelp(sb, nameUnits); } nameUnits = prometheusNameWithUnits(name, unit) + "_count"; sb.append(nameUnits) .append(tags) .append(" ") .append(getCount()) .append('\n'); nameUnits = prometheusNameWithUnits(name, unit); prometheusQuantile(sb, tags, units, nameUnits, "0.5", snap::getMedian); prometheusQuantile(sb, tags, units, nameUnits, "0.75", snap::get75thPercentile); prometheusQuantile(sb, tags, units, nameUnits, "0.95", snap::get95thPercentile); prometheusQuantile(sb, tags, units, nameUnits, "0.98", snap::get98thPercentile); prometheusQuantile(sb, tags, units, nameUnits, "0.99", snap::get99thPercentile); prometheusQuantile(sb, tags, units, nameUnits, "0.999", snap::get999thPercentile); } private  HelidonTimer(String type, Metadata metadata, Timer delegate); @Override void update(long duration, TimeUnit unit); @Override T time(Callable<T> event); @Override void time(Runnable event); @Override Context time(); @Override long getCount(); @Override double getFifteenMinuteRate(); @Override double getFiveMinuteRate(); @Override double getMeanRate(); @Override double getOneMinuteRate(); @Override Snapshot getSnapshot(); @Override void prometheusData(StringBuilder sb, MetricID metricID, boolean withHelpType); @Override String prometheusValue(); @Override void jsonData(JsonObjectBuilder builder, MetricID metricID); @Override boolean equals(Object o); @Override int hashCode();  }