Search in sources :

Example 11 with Tag

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

the class JsonExporterGetTest method exportConcurrentGauge.

@Test
public void exportConcurrentGauge() {
    ConcurrentGauge callCount = mock(ConcurrentGauge.class);
    when(callCount.getCount()).thenReturn(48L);
    when(callCount.getMin()).thenReturn(4L);
    when(callCount.getMax()).thenReturn(50L);
    ConcurrentGauge callCount2 = mock(ConcurrentGauge.class);
    when(callCount2.getCount()).thenReturn(23L);
    when(callCount2.getMin()).thenReturn(1L);
    when(callCount2.getMax()).thenReturn(29L);
    export(new MetricID("callCount"), callCount);
    export(new MetricID("callCount", new Tag("component", "backend")), callCount2);
    assertOutputEqualsFile("ConcurrentGauge.json");
}
Also used : MetricID(org.eclipse.microprofile.metrics.MetricID) ConcurrentGauge(org.eclipse.microprofile.metrics.ConcurrentGauge) Tag(org.eclipse.microprofile.metrics.Tag) Test(org.junit.Test)

Example 12 with Tag

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

the class JsonExporterGetTest method exportMeter.

@Test
public void exportMeter() {
    Meter requests = mock(Meter.class);
    when(requests.getCount()).thenReturn(29382L);
    when(requests.getMeanRate()).thenReturn(12.223d);
    when(requests.getOneMinuteRate()).thenReturn(12.563d);
    when(requests.getFiveMinuteRate()).thenReturn(12.364d);
    when(requests.getFifteenMinuteRate()).thenReturn(12.126d);
    // example uses same values for all three meters so we can get away with just one
    // but conceptually those should be three different meter instances
    export(new MetricID("requests"), requests);
    export(new MetricID("requests", new Tag("servlet", "one")), requests);
    export(new MetricID("requests", new Tag("servlet", "two")), requests);
    assertOutputEqualsFile("Meter.json");
}
Also used : MetricID(org.eclipse.microprofile.metrics.MetricID) Meter(org.eclipse.microprofile.metrics.Meter) Tag(org.eclipse.microprofile.metrics.Tag) Test(org.junit.Test)

Example 13 with Tag

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

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

the class MetricRegistryImplTest method registerByMetadataAcceptsInstancesWithSameNameButDifferentTags.

@Test
public void registerByMetadataAcceptsInstancesWithSameNameButDifferentTags() {
    EnumSet<MetricType> types = EnumSet.allOf(MetricType.class);
    // obviously
    types.remove(MetricType.INVALID);
    // gauges cannot be created
    types.remove(MetricType.GAUGE);
    for (MetricType type : types) {
        String name = nextName();
        for (int i = 0; i < 10; i++) {
            final int n = i;
            MetadataBuilder metadata = withNameAnd(name).withType(type);
            Runnable register = () -> registry.register(metadata.build(), null, new Tag("a", "b" + n));
            // first time should work
            register.run();
            // works again as all metrics are reusable
            register.run();
        }
    }
}
Also used : MetadataBuilder(org.eclipse.microprofile.metrics.MetadataBuilder) MetricType(org.eclipse.microprofile.metrics.MetricType) Tag(org.eclipse.microprofile.metrics.Tag) Test(org.junit.Test)

Example 15 with Tag

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

Aggregations

Tag (org.eclipse.microprofile.metrics.Tag)36 MetricID (org.eclipse.microprofile.metrics.MetricID)25 Test (org.junit.Test)23 Metadata (org.eclipse.microprofile.metrics.Metadata)12 Counter (org.eclipse.microprofile.metrics.Counter)7 Metric (org.eclipse.microprofile.metrics.Metric)5 Snapshot (org.eclipse.microprofile.metrics.Snapshot)5 Histogram (org.eclipse.microprofile.metrics.Histogram)4 ArrayList (java.util.ArrayList)2 InjectionPoint (javax.enterprise.inject.spi.InjectionPoint)2 JsonObjectBuilder (javax.json.JsonObjectBuilder)2 ConcurrentGauge (org.eclipse.microprofile.metrics.ConcurrentGauge)2 Gauge (org.eclipse.microprofile.metrics.Gauge)2 Meter (org.eclipse.microprofile.metrics.Meter)2 SimpleTimer (org.eclipse.microprofile.metrics.SimpleTimer)2 Timer (org.eclipse.microprofile.metrics.Timer)2 TimerImpl (fish.payara.microprofile.metrics.impl.TimerImpl)1 ExtendedMetadata (io.smallrye.metrics.ExtendedMetadata)1 BigDecimal (java.math.BigDecimal)1 BigInteger (java.math.BigInteger)1