Search in sources :

Example 11 with MetricID

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

the class JsonExporterGetTest method exportSimpleTimer.

@Test
public void exportSimpleTimer() {
    SimpleTimer timer = mock(SimpleTimer.class);
    when(timer.getCount()).thenReturn(1L);
    when(timer.getElapsedTime()).thenReturn(Duration.ofMillis(12300000000L));
    when(timer.getMaxTimeDuration()).thenReturn(Duration.ofMillis(3231000000L));
    when(timer.getMinTimeDuration()).thenReturn(Duration.ofMillis(25600000L));
    export(new MetricID("simple_responseTime"), timer);
    assertOutputEqualsFile("SimpleTimer.json");
}
Also used : MetricID(org.eclipse.microprofile.metrics.MetricID) SimpleTimer(org.eclipse.microprofile.metrics.SimpleTimer) Test(org.junit.Test)

Example 12 with MetricID

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

the class OpenMetricsExporterTest method gaugesThatThrowIllegalStateExceptionWhenReadAreNotExported.

@Test
public void gaugesThatThrowIllegalStateExceptionWhenReadAreNotExported() {
    Gauge<Long> gauge = () -> {
        throw new IllegalStateException("test");
    };
    MetricID metricID = new MetricID("test4");
    Metadata metadata = Metadata.builder().withName(metricID.getName()).build();
    assertOutputEquals("", metricID, gauge, metadata);
}
Also used : MetricID(org.eclipse.microprofile.metrics.MetricID) Metadata(org.eclipse.microprofile.metrics.Metadata) Test(org.junit.Test)

Example 13 with MetricID

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

the class OpenMetricsExporterTest method namesAreadyEndingWithSuffixAvoidAppendingSuffixAgain.

@Test
public void namesAreadyEndingWithSuffixAvoidAppendingSuffixAgain() {
    Counter counter = mock(Counter.class);
    when(counter.getCount()).thenReturn(13L);
    MetricID metricID = new MetricID("my_total");
    Metadata metadata = Metadata.builder().withName(metricID.getName()).build();
    assertOutputEquals("# TYPE application_my_total counter\n" + "application_my_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)

Example 14 with MetricID

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

Example 15 with MetricID

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

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