use of org.eclipse.microprofile.metrics.Snapshot in project Payara by payara.
the class BulkheadMetricTckTest method bulkheadMetricHistogramTest.
/**
* Scenario is equivalent to the TCK test of same name but not 100% identical
*/
@Test(timeout = 3000)
public void bulkheadMetricHistogramTest() {
callMethodWithNewThreadAndWaitFor(commonWaiter);
callMethodWithNewThreadAndWaitFor(commonWaiter);
waitUntilPermitsAquired(2, 0);
assertFurtherThreadThrowsBulkheadException(1);
waitSome(100);
commonWaiter.complete(null);
waitUntilPermitsAquired(0, 0);
Histogram executionTimes = registry.getHistogram(new MetricID("ft.bulkhead.runningDuration", new Tag("method", "fish.payara.microprofile.faulttolerance.policy.BulkheadMetricTckTest.bulkheadMetricHistogramTest_Method")));
Snapshot snap = executionTimes.getSnapshot();
assertNotNull(executionTimes);
assertEquals(2, executionTimes.getCount());
assertApproxMillis(100, Math.round(snap.getMedian()));
assertApproxMillis(100, Math.round(snap.getMean()));
// Now let's put some quick results through the bulkhead
callMethodDirectly(null);
callMethodDirectly(null);
assertEquals(4, executionTimes.getCount());
snap = executionTimes.getSnapshot();
assertApproxMillis(50, Math.round(snap.getMean()));
}
use of org.eclipse.microprofile.metrics.Snapshot in project Payara by payara.
the class JsonExporter method exportSampling.
private void exportSampling(MetricID metricID, Sampling sampling) {
Snapshot snapshot = sampling.getSnapshot();
appendMember(metricID, "min", snapshot.getMin());
appendMember(metricID, "max", snapshot.getMax());
appendMember(metricID, "mean", snapshot.getMean());
appendMember(metricID, "stddev", snapshot.getStdDev());
appendMember(metricID, "p50", snapshot.getMedian());
appendMember(metricID, "p75", snapshot.get75thPercentile());
appendMember(metricID, "p95", snapshot.get95thPercentile());
appendMember(metricID, "p98", snapshot.get98thPercentile());
appendMember(metricID, "p99", snapshot.get99thPercentile());
appendMember(metricID, "p999", snapshot.get999thPercentile());
}
use of org.eclipse.microprofile.metrics.Snapshot in project Payara by payara.
the class OpenMetricsExporter method exportSampling.
private void exportSampling(MetricID metricID, Sampling sampling, LongSupplier count, Supplier<Number> sum, Metadata metadata) {
Tag[] tags = metricID.getTagsAsArray();
Snapshot snapshot = sampling.getSnapshot();
String mean = globalName(metricID, "_mean", metadata);
appendTYPE(mean, OpenMetricsType.gauge);
appendValue(mean, tags, scaleToBaseUnit(snapshot.getMean(), metadata));
String max = globalName(metricID, "_max", metadata);
appendTYPE(max, OpenMetricsType.gauge);
appendValue(max, tags, scaleToBaseUnit(snapshot.getMax(), metadata));
String min = globalName(metricID, "_min", metadata);
appendTYPE(min, OpenMetricsType.gauge);
appendValue(min, tags, scaleToBaseUnit(snapshot.getMin(), metadata));
String stddev = globalName(metricID, "_stddev", metadata);
appendTYPE(stddev, OpenMetricsType.gauge);
appendValue(stddev, tags, scaleToBaseUnit(snapshot.getStdDev(), metadata));
String summary = globalName(metricID, metadata);
appendTYPE(summary, OpenMetricsType.summary);
appendHELP(summary, metadata);
appendValue(globalName(metricID, metadata, "_count"), tags, count.getAsLong());
appendValue(globalName(metricID, metadata, "_sum"), tags, sum.get());
appendValue(summary, tags("quantile", "0.5", tags), scaleToBaseUnit(snapshot.getMedian(), metadata));
appendValue(summary, tags("quantile", "0.75", tags), scaleToBaseUnit(snapshot.get75thPercentile(), metadata));
appendValue(summary, tags("quantile", "0.95", tags), scaleToBaseUnit(snapshot.get95thPercentile(), metadata));
appendValue(summary, tags("quantile", "0.98", tags), scaleToBaseUnit(snapshot.get98thPercentile(), metadata));
appendValue(summary, tags("quantile", "0.99", tags), scaleToBaseUnit(snapshot.get99thPercentile(), metadata));
appendValue(summary, tags("quantile", "0.999", tags), scaleToBaseUnit(snapshot.get999thPercentile(), metadata));
}
use of org.eclipse.microprofile.metrics.Snapshot in project Payara by payara.
the class OpenMetricsExporterTest method quantilesAreAppendedOtherTags.
@Test
public void quantilesAreAppendedOtherTags() {
Histogram histogram = mock(Histogram.class);
Snapshot snapshot = mock(Snapshot.class);
when(histogram.getSnapshot()).thenReturn(snapshot);
MetricID metricID = new MetricID("test6", new Tag("custom", "tag-value"));
Metadata metadata = Metadata.builder().withName(metricID.getName()).withUnit(MetricUnits.MILLISECONDS).build();
exporter.export(metricID, histogram, metadata);
String actualOutput = actual.getBuffer().toString();
assertTrue(actualOutput.contains("application_test6_seconds{custom=\"tag-value\",quantile=\"0.5\"} 0"));
}
use of org.eclipse.microprofile.metrics.Snapshot in project Payara by payara.
the class OpenMetricsExporterTest method exportTimer.
@Test
public void exportTimer() {
Timer timer = mock(Timer.class);
when(timer.getElapsedTime()).thenReturn(Duration.ofMillis(23L));
when(timer.getCount()).thenReturn(80L);
when(timer.getMeanRate()).thenReturn(0.004292520715985437d);
when(timer.getOneMinuteRate()).thenReturn(2.794076465421066E-14d);
when(timer.getFiveMinuteRate()).thenReturn(4.800392614619373E-4d);
when(timer.getFifteenMinuteRate()).thenReturn(0.01063191047532505d);
Snapshot snapshot = mock(Snapshot.class);
when(timer.getSnapshot()).thenReturn(snapshot);
when(snapshot.getMin()).thenReturn(169916L);
when(snapshot.getMax()).thenReturn(560869L);
when(snapshot.getMean()).thenReturn(415041d);
when(snapshot.getStdDev()).thenReturn(652907d);
when(snapshot.getMedian()).thenReturn(293324d);
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);
MetricID metricID = new MetricID("response_time");
Metadata metadata = Metadata.builder().withName(metricID.getName()).withDescription("Server response time for /index.html").withUnit(MetricUnits.NANOSECONDS).build();
assertOutputEqualsFile("Timer.txt", metricID, timer, metadata);
}
Aggregations