Search in sources :

Example 11 with Metadata

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

the class OpenMetricsExporterTest method assertUnitConversion.

private void assertUnitConversion(String inputUnit, Number inputValue, String expectedUnit, String expectedValue) {
    Gauge<Number> gauge = () -> inputValue;
    String name = "test" + nextNameId.incrementAndGet();
    MetricID metricID = new MetricID(name);
    Metadata metadata = Metadata.builder().withName(metricID.getName()).withUnit(inputUnit).build();
    assertOutputEquals("# TYPE application_" + name + "_" + expectedUnit + " gauge\n" + "application_" + name + "_" + expectedUnit + " " + expectedValue + "\n", metricID, gauge, metadata);
    // clean output so far to allow multiple usages of this in a single test
    actual.getBuffer().setLength(0);
}
Also used : MetricID(org.eclipse.microprofile.metrics.MetricID) Metadata(org.eclipse.microprofile.metrics.Metadata)

Example 12 with Metadata

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

the class OpenMetricsExporterTest method exportConcurrentGauge.

@Test
public void exportConcurrentGauge() {
    ConcurrentGauge gauge = mock(ConcurrentGauge.class);
    when(gauge.getCount()).thenReturn(80L);
    when(gauge.getMin()).thenReturn(20L);
    when(gauge.getMax()).thenReturn(100L);
    MetricID metricID = new MetricID("method_a_invocations");
    Metadata metadata = Metadata.builder().withName(metricID.getName()).withDescription("The number of parallel invocations of methodA()").build();
    assertOutputEqualsFile("ConcurrentGauge.txt", metricID, gauge, metadata);
}
Also used : MetricID(org.eclipse.microprofile.metrics.MetricID) ConcurrentGauge(org.eclipse.microprofile.metrics.ConcurrentGauge) Metadata(org.eclipse.microprofile.metrics.Metadata) Test(org.junit.Test)

Example 13 with Metadata

use of org.eclipse.microprofile.metrics.Metadata 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);
}
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) Metadata(org.eclipse.microprofile.metrics.Metadata) Test(org.junit.Test)

Example 14 with Metadata

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

the class OpenMetricsExporterTest method exportMeter.

@Test
public void exportMeter() {
    Meter meter = mock(Meter.class);
    when(meter.getCount()).thenReturn(29382L);
    when(meter.getMeanRate()).thenReturn(12.223d);
    when(meter.getOneMinuteRate()).thenReturn(12.563d);
    when(meter.getFiveMinuteRate()).thenReturn(12.364d);
    when(meter.getFifteenMinuteRate()).thenReturn(12.126d);
    MetricID metricID = new MetricID("requests");
    Metadata metadata = Metadata.builder().withName(metricID.getName()).withDescription("Tracks the number of requests to the server").build();
    assertOutputEqualsFile("Meter.txt", metricID, meter, metadata);
}
Also used : MetricID(org.eclipse.microprofile.metrics.MetricID) Meter(org.eclipse.microprofile.metrics.Meter) Metadata(org.eclipse.microprofile.metrics.Metadata) Test(org.junit.Test)

Example 15 with Metadata

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

the class OpenMetricsExporterTest method emptyDescriptionDoesNotPrintHelpLine.

@Test
public void emptyDescriptionDoesNotPrintHelpLine() {
    Counter counter = mock(Counter.class);
    when(counter.getCount()).thenReturn(13L);
    MetricID metricID = new MetricID("test1");
    Metadata metadata = Metadata.builder().withName(metricID.getName()).withDescription("").build();
    assertOutputEquals("# TYPE application_test1_total counter\n" + "application_test1_total 13\n", metricID, counter, metadata);
}
Also used : MetricID(org.eclipse.microprofile.metrics.MetricID) Counter(org.eclipse.microprofile.metrics.Counter) Metadata(org.eclipse.microprofile.metrics.Metadata) Test(org.junit.Test)

Aggregations

Metadata (org.eclipse.microprofile.metrics.Metadata)65 MetricID (org.eclipse.microprofile.metrics.MetricID)31 Test (org.junit.Test)30 Tag (org.eclipse.microprofile.metrics.Tag)12 Counter (org.eclipse.microprofile.metrics.Counter)9 Metric (org.eclipse.microprofile.metrics.Metric)9 MetricRegistry (org.eclipse.microprofile.metrics.MetricRegistry)8 HashMap (java.util.HashMap)6 Map (java.util.Map)4 Histogram (org.eclipse.microprofile.metrics.Histogram)4 ArrayList (java.util.ArrayList)3 Meter (org.eclipse.microprofile.metrics.Meter)3 Gauge (org.eclipse.microprofile.metrics.annotation.Gauge)3 ObjectName (javax.management.ObjectName)2 GET (javax.ws.rs.GET)2 Path (javax.ws.rs.Path)2 Gauge (org.eclipse.microprofile.metrics.Gauge)2 MetricType (org.eclipse.microprofile.metrics.MetricType)2 SimpleTimer (org.eclipse.microprofile.metrics.SimpleTimer)2 Snapshot (org.eclipse.microprofile.metrics.Snapshot)2