use of org.eclipse.microprofile.metrics.MetricID in project Payara by payara.
the class JsonExporterGetTest method exportHistogram.
@Test
public void exportHistogram() {
Histogram histogram = mock(Histogram.class);
when(histogram.getCount()).thenReturn(2L);
when(histogram.getSum()).thenReturn(42L);
Snapshot snapshot = mock(Snapshot.class);
when(histogram.getSnapshot()).thenReturn(snapshot);
when(snapshot.getMin()).thenReturn(-1624L);
when(snapshot.getMax()).thenReturn(26L);
when(snapshot.getMean()).thenReturn(-799.0d);
when(snapshot.getStdDev()).thenReturn(825d);
when(snapshot.getMedian()).thenReturn(26d);
when(snapshot.get75thPercentile()).thenReturn(26d);
when(snapshot.get95thPercentile()).thenReturn(26d);
when(snapshot.get98thPercentile()).thenReturn(26d);
when(snapshot.get99thPercentile()).thenReturn(26d);
when(snapshot.get999thPercentile()).thenReturn(26d);
// example uses same values for both histograms so we can get away with just one
// but conceptually those should be two different histogram instances
export(new MetricID("daily_value_changes"), histogram);
export(new MetricID("daily_value_changes", new Tag("servlet", "two")), histogram);
assertOutputEqualsFile("Histogram.json");
}
use of org.eclipse.microprofile.metrics.MetricID in project Payara by payara.
the class OpenMetricsExporterTest method unitPerSecondUsesUnscaledValue.
@Test
public void unitPerSecondUsesUnscaledValue() {
Gauge<Double> perSec = () -> 2.3d;
MetricID metricID = new MetricID("test7");
Metadata metadata = Metadata.builder().withName(metricID.getName()).withUnit(MetricUnits.PER_SECOND).build();
assertOutputEquals("# TYPE application_test7_per_second gauge\n" + "application_test7_per_second 2.3\n", metricID, perSec, metadata);
}
use of org.eclipse.microprofile.metrics.MetricID in project Payara by payara.
the class OpenMetricsExporterTest method exportHistogram.
@Test
public void exportHistogram() {
Histogram histogram = mock(Histogram.class);
when(histogram.getCount()).thenReturn(2037L);
when(histogram.getSum()).thenReturn(45678L);
Snapshot snapshot = mock(Snapshot.class);
when(histogram.getSnapshot()).thenReturn(snapshot);
when(snapshot.getMin()).thenReturn(180L);
when(snapshot.getMax()).thenReturn(31716L);
when(snapshot.getMean()).thenReturn(4738.231d);
when(snapshot.getStdDev()).thenReturn(1054.7343037063602d);
when(snapshot.getMedian()).thenReturn(4201d);
when(snapshot.get75thPercentile()).thenReturn(6175d);
when(snapshot.get95thPercentile()).thenReturn(13560d);
when(snapshot.get98thPercentile()).thenReturn(29643d);
when(snapshot.get99thPercentile()).thenReturn(31716d);
when(snapshot.get999thPercentile()).thenReturn(31716d);
MetricID metricID = new MetricID("file_sizes");
Metadata metadata = Metadata.builder().withName(metricID.getName()).withDescription("Users file size").withUnit(MetricUnits.BYTES).build();
assertOutputEqualsFile("Histogram.txt", metricID, histogram, metadata);
}
use of org.eclipse.microprofile.metrics.MetricID in project Payara by payara.
the class OpenMetricsExporterTest method exportCounter.
@Test
public void exportCounter() {
Counter counter = mock(Counter.class);
when(counter.getCount()).thenReturn(80L);
MetricID metricID = new MetricID("visitors");
Metadata metadata = Metadata.builder().withName(metricID.getName()).withDescription("The number of unique visitors").build();
assertOutputEqualsFile("Counter.txt", metricID, counter, metadata);
}
use of org.eclipse.microprofile.metrics.MetricID in project Payara by payara.
the class MetricsServiceImpl method collectRegistry.
private static void collectRegistry(String contextName, MetricRegistry registry, MonitoringDataCollector collector) {
// OBS: this way of iterating the metrics in the registry is optimal because of its internal data organisation
for (String name : registry.getNames()) {
for (Entry<MetricID, Metric> entry : ((MetricRegistryImpl) registry).getMetrics(name).entrySet()) {
MetricID metricID = entry.getKey();
Metric metric = entry.getValue();
try {
MonitoringDataCollector metricCollector = tagCollector(contextName, metricID, collector);
if (metric instanceof Counting) {
metricCollector.collect(toName(metricID, "Count"), ((Counting) metric).getCount());
}
if (metric instanceof SimpleTimer) {
metricCollector.collect(toName(metricID, "Duration"), ((SimpleTimer) metric).getElapsedTime().toMillis());
}
if (metric instanceof Timer) {
metricCollector.collect(toName(metricID, "MaxDuration"), ((Timer) metric).getSnapshot().getMax());
}
if (metric instanceof Gauge) {
Object value = ((Gauge<?>) metric).getValue();
if (value instanceof Number) {
metricCollector.collect(toName(metricID, getMetricUnitSuffix(registry.getMetadata(name).unit())), ((Number) value));
}
}
} catch (Exception ex) {
LOGGER.log(Level.SEVERE, "Failed to retrieve metric: " + metricID);
;
}
}
}
}
Aggregations