Search in sources :

Example 16 with MetricID

use of org.eclipse.microprofile.metrics.MetricID 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 17 with MetricID

use of org.eclipse.microprofile.metrics.MetricID 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 18 with MetricID

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

the class MetricRegistryImplTest method registerByMetadataAllowsToRegisterMetricsOfSameNameWithDifferentTagsButSameType.

@Test
public void registerByMetadataAllowsToRegisterMetricsOfSameNameWithDifferentTagsButSameType() {
    String name = nextName();
    Tag ab = new Tag("a", "b");
    Tag ac = new Tag("a", "c");
    MetricID metricAb = new MetricID(name, ab);
    MetricID metricAc = new MetricID(name, ac);
    registry.register(withName(name), new TimerImpl(), ab);
    registry.register(withName(name), new TimerImpl(), ac);
    assertEquals(2, registry.getTimers().size());
    Map<MetricID, Metric> metrics = registry.getMetrics((metricID, metric) -> metricID.getName().equals(name));
    assertEquals(2, metrics.size());
    assertTrue(metrics.containsKey(metricAb));
    assertTrue(metrics.containsKey(metricAc));
    assertEquals(new TreeSet<>(asList(metricAb, metricAc)), registry.getMetricIDs());
    assertEquals(new TreeSet<>(asList(name)), registry.getNames());
    assertEquals(1, registry.getTimers((id, metric) -> id.equals(metricAc)).size());
}
Also used : MetricID(org.eclipse.microprofile.metrics.MetricID) Metric(org.eclipse.microprofile.metrics.Metric) Tag(org.eclipse.microprofile.metrics.Tag) TimerImpl(fish.payara.microprofile.metrics.impl.TimerImpl) Test(org.junit.Test)

Example 19 with MetricID

use of org.eclipse.microprofile.metrics.MetricID 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 20 with MetricID

use of org.eclipse.microprofile.metrics.MetricID 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

MetricID (org.eclipse.microprofile.metrics.MetricID)53 Test (org.junit.Test)41 Metadata (org.eclipse.microprofile.metrics.Metadata)31 Tag (org.eclipse.microprofile.metrics.Tag)25 Counter (org.eclipse.microprofile.metrics.Counter)10 Metric (org.eclipse.microprofile.metrics.Metric)6 SimpleTimer (org.eclipse.microprofile.metrics.SimpleTimer)6 Snapshot (org.eclipse.microprofile.metrics.Snapshot)6 Histogram (org.eclipse.microprofile.metrics.Histogram)5 ConcurrentGauge (org.eclipse.microprofile.metrics.ConcurrentGauge)4 Timer (org.eclipse.microprofile.metrics.Timer)4 Gauge (org.eclipse.microprofile.metrics.Gauge)3 MonitoringDataCollector (fish.payara.monitoring.collect.MonitoringDataCollector)2 ArrayList (java.util.ArrayList)2 Meter (org.eclipse.microprofile.metrics.Meter)2 NoSuchRegistryException (fish.payara.microprofile.metrics.exception.NoSuchRegistryException)1 TimerImpl (fish.payara.microprofile.metrics.impl.TimerImpl)1 MBeanMetadata (fish.payara.microprofile.metrics.jmx.MBeanMetadata)1 FileNotFoundException (java.io.FileNotFoundException)1 Collections.emptyMap (java.util.Collections.emptyMap)1