Search in sources :

Example 6 with Snapshot

use of org.eclipse.microprofile.metrics.Snapshot in project Payara by payara.

the class JsonExporterGetTest method exportTimer.

@Test
public void exportTimer() {
    Timer timer = mock(Timer.class);
    when(timer.getElapsedTime()).thenReturn(Duration.ofMillis(45678L));
    when(timer.getCount()).thenReturn(29382L);
    when(timer.getMeanRate()).thenReturn(12.185627192860734d);
    when(timer.getOneMinuteRate()).thenReturn(12.563d);
    when(timer.getFiveMinuteRate()).thenReturn(12.364d);
    when(timer.getFifteenMinuteRate()).thenReturn(12.126d);
    Snapshot snapshot = mock(Snapshot.class);
    when(timer.getSnapshot()).thenReturn(snapshot);
    when(snapshot.getMin()).thenReturn(169916L);
    when(snapshot.getMax()).thenReturn(5608694L);
    when(snapshot.getMean()).thenReturn(415041.00024926325d);
    when(snapshot.getStdDev()).thenReturn(652907.9633011606d);
    when(snapshot.getMedian()).thenReturn(293324.0d);
    when(snapshot.get75thPercentile()).thenReturn(344914d);
    when(snapshot.get95thPercentile()).thenReturn(543647d);
    when(snapshot.get98thPercentile()).thenReturn(2706543d);
    when(snapshot.get99thPercentile()).thenReturn(5608694d);
    when(snapshot.get999thPercentile()).thenReturn(5608694d);
    // example uses same values for both timers so we can get away with just one
    // but conceptually those should be two different timer instances
    export(new MetricID("responseTime"), timer);
    export(new MetricID("responseTime", new Tag("servlet", "two")), timer);
    assertOutputEqualsFile("Timer.json");
}
Also used : Snapshot(org.eclipse.microprofile.metrics.Snapshot) MetricID(org.eclipse.microprofile.metrics.MetricID) Timer(org.eclipse.microprofile.metrics.Timer) SimpleTimer(org.eclipse.microprofile.metrics.SimpleTimer) Tag(org.eclipse.microprofile.metrics.Tag) Test(org.junit.Test)

Example 7 with Snapshot

use of org.eclipse.microprofile.metrics.Snapshot 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");
}
Also used : Snapshot(org.eclipse.microprofile.metrics.Snapshot) Histogram(org.eclipse.microprofile.metrics.Histogram) MetricID(org.eclipse.microprofile.metrics.MetricID) Tag(org.eclipse.microprofile.metrics.Tag) Test(org.junit.Test)

Example 8 with Snapshot

use of org.eclipse.microprofile.metrics.Snapshot 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);
}
Also used : Snapshot(org.eclipse.microprofile.metrics.Snapshot) Histogram(org.eclipse.microprofile.metrics.Histogram) MetricID(org.eclipse.microprofile.metrics.MetricID) Metadata(org.eclipse.microprofile.metrics.Metadata) Test(org.junit.Test)

Example 9 with Snapshot

use of org.eclipse.microprofile.metrics.Snapshot in project wildfly-swarm by wildfly-swarm.

the class PrometheusExporter method writeHistogramValues.

private void writeHistogramValues(StringBuilder sb, MetricRegistry.Type scope, HistogramImpl histogram, Metadata md) {
    Snapshot snapshot = histogram.getSnapshot();
    String unit = md.getUnit();
    unit = PrometheusUnit.getBaseUnitAsPrometheusString(unit);
    String theUnit = unit.equals("none") ? "" : USCORE + unit;
    writeHelpLine(sb, scope, md.getName(), md, SUMMARY);
    writeSnapshotBasics(sb, scope, md, snapshot, theUnit);
    writeTypeLine(sb, scope, md.getName(), md, theUnit, SUMMARY);
    writeValueLine(sb, scope, theUnit + "_count", histogram.getCount(), md, null, false);
    writeSnapshotQuantiles(sb, scope, md, snapshot, theUnit);
}
Also used : Snapshot(org.eclipse.microprofile.metrics.Snapshot)

Example 10 with Snapshot

use of org.eclipse.microprofile.metrics.Snapshot in project wildfly-swarm by wildfly-swarm.

the class PrometheusExporter method writeTimerValues.

private void writeTimerValues(StringBuilder sb, MetricRegistry.Type scope, TimerImpl timer, Metadata md) {
    String unit = md.getUnit();
    unit = PrometheusUnit.getBaseUnitAsPrometheusString(unit);
    String theUnit = unit.equals("none") ? "" : USCORE + unit;
    writeMeterRateValues(sb, scope, timer.getMeter(), md);
    Snapshot snapshot = timer.getSnapshot();
    writeSnapshotBasics(sb, scope, md, snapshot, theUnit);
    String suffix = USCORE + PrometheusUnit.getBaseUnitAsPrometheusString(md.getUnit());
    writeHelpLine(sb, scope, md.getName(), md, suffix);
    writeTypeLine(sb, scope, md.getName(), md, suffix, SUMMARY);
    writeValueLine(sb, scope, suffix + "_count", timer.getCount(), md, null, false);
    writeSnapshotQuantiles(sb, scope, md, snapshot, theUnit);
}
Also used : Snapshot(org.eclipse.microprofile.metrics.Snapshot)

Aggregations

Snapshot (org.eclipse.microprofile.metrics.Snapshot)10 MetricID (org.eclipse.microprofile.metrics.MetricID)6 Test (org.junit.Test)6 Tag (org.eclipse.microprofile.metrics.Tag)5 Histogram (org.eclipse.microprofile.metrics.Histogram)4 Metadata (org.eclipse.microprofile.metrics.Metadata)3 SimpleTimer (org.eclipse.microprofile.metrics.SimpleTimer)2 Timer (org.eclipse.microprofile.metrics.Timer)2