Search in sources :

Example 41 with MetricID

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

the class MetricRegistryImplTest method removeByMetricIdRemovesOnlyMetricsWithThatId.

@Test
public void removeByMetricIdRemovesOnlyMetricsWithThatId() {
    String name = nextName();
    registry.concurrentGauge(withName(name));
    ConcurrentGauge remaining1 = registry.concurrentGauge(withName(name), SOME_TAG);
    String otherName = nextName();
    ConcurrentGauge remaining2 = registry.concurrentGauge(withName(otherName));
    assertEquals(3, registry.getConcurrentGauges().size());
    assertEquals(new TreeSet<>(asList(name, otherName)), registry.getNames());
    assertTrue(registry.remove(new MetricID(name)));
    assertEquals(2, registry.getConcurrentGauges().size());
    assertEquals(new HashSet<>(asList(remaining1, remaining2)), new HashSet<>(registry.getConcurrentGauges().values()));
    assertEquals(new TreeSet<>(asList(name, otherName)), registry.getNames());
    assertTrue(registry.remove(new MetricID(name, SOME_TAG)));
    assertEquals(1, registry.getConcurrentGauges().size());
    assertEquals(new TreeSet<>(asList(otherName)), registry.getNames());
}
Also used : MetricID(org.eclipse.microprofile.metrics.MetricID) ConcurrentGauge(org.eclipse.microprofile.metrics.ConcurrentGauge) Test(org.junit.Test)

Example 42 with MetricID

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

the class MetricIDTest method removalTest.

@SuppressWarnings({ "deprecation", "unused" })
@Test
public void removalTest() {
    Tag tagEarth = new Tag("planet", "earth");
    Tag tagRed = new Tag("colour", "red");
    Tag tagBlue = new Tag("colour", "blue");
    String counterName = "org.eclipse.microprofile.metrics.tck.MetricIDTest.counterColour";
    Counter counterColour = registry.counter(counterName);
    Counter counterRed = registry.counter(counterName, tagEarth, tagRed);
    Counter counterBlue = registry.counter(counterName, tagEarth, tagBlue);
    MetricID counterColourMID = new MetricID(counterName);
    MetricID counterRedMID = new MetricID(counterName, tagEarth, tagRed);
    MetricID counterBlueMID = new MetricID(counterName, tagEarth, tagRed);
    // check multi-dimensional metrics are registered
    assertThat("Counter is not registered correctly", registry.getCounter(counterColourMID), notNullValue());
    assertThat("Counter is not registered correctly", registry.getCounter(counterRedMID), notNullValue());
    assertThat("Counter is not registered correctly", registry.getCounter(counterBlueMID), notNullValue());
    // remove one metric
    registry.remove(counterColourMID);
    assertThat("Registry did not remove metric", registry.getCounters().size(), equalTo(2));
    assertThat("Counter is not registered correctly", registry.getCounter(counterColourMID), nullValue());
    // remove all metrics with the given name
    registry.remove(counterName);
    assertThat("Counter is not registered correctly", registry.getCounter(counterRedMID), nullValue());
    assertThat("Counter is not registered correctly", registry.getCounter(counterBlueMID), nullValue());
}
Also used : MetricID(org.eclipse.microprofile.metrics.MetricID) Counter(org.eclipse.microprofile.metrics.Counter) Tag(org.eclipse.microprofile.metrics.Tag) Test(org.junit.Test)

Example 43 with MetricID

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

the class JsonExporterGetTest method exportTimer.

@Test
public void exportTimer() {
    Timer timer = mock(Timer.class);
    when(timer.getElapsedTime()).thenReturn(Duration.ofMillis(45678L));
    when(timer.getCount()).thenReturn(29382L);
    when(timer.getMeanRate()).thenReturn(12.185627192860734d);
    when(timer.getOneMinuteRate()).thenReturn(12.563d);
    when(timer.getFiveMinuteRate()).thenReturn(12.364d);
    when(timer.getFifteenMinuteRate()).thenReturn(12.126d);
    Snapshot snapshot = mock(Snapshot.class);
    when(timer.getSnapshot()).thenReturn(snapshot);
    when(snapshot.getMin()).thenReturn(169916L);
    when(snapshot.getMax()).thenReturn(5608694L);
    when(snapshot.getMean()).thenReturn(415041.00024926325d);
    when(snapshot.getStdDev()).thenReturn(652907.9633011606d);
    when(snapshot.getMedian()).thenReturn(293324.0d);
    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);
    // example uses same values for both timers so we can get away with just one
    // but conceptually those should be two different timer instances
    export(new MetricID("responseTime"), timer);
    export(new MetricID("responseTime", new Tag("servlet", "two")), timer);
    assertOutputEqualsFile("Timer.json");
}
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) Tag(org.eclipse.microprofile.metrics.Tag) Test(org.junit.Test)

Example 44 with MetricID

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

the class JsonExporterGetTest method exportCounter.

@Test
public void exportCounter() {
    Counter hitCount = mock(Counter.class);
    when(hitCount.getCount()).thenReturn(45L);
    Counter hitCount2 = mock(Counter.class);
    when(hitCount2.getCount()).thenReturn(3L);
    Counter hitCount3 = mock(Counter.class);
    when(hitCount3.getCount()).thenReturn(4L);
    export(new MetricID("hitCount"), hitCount);
    export(new MetricID("hitCount", new Tag("servlet", "two")), hitCount2);
    export(new MetricID("hitCount", new Tag("store", "webshop"), new Tag("servlet", "three")), hitCount3);
    assertOutputEqualsFile("Counter.json");
}
Also used : MetricID(org.eclipse.microprofile.metrics.MetricID) Counter(org.eclipse.microprofile.metrics.Counter) Tag(org.eclipse.microprofile.metrics.Tag) Test(org.junit.Test)

Example 45 with MetricID

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

the class JsonExporterGetTest method exportGauge.

@Test
public void exportGauge() {
    Gauge<Double> responsePercentage1 = () -> 48.45632d;
    Gauge<Double> responsePercentage2 = () -> 26.23654d;
    Gauge<Double> responsePercentage3 = () -> 29.24554d;
    export(new MetricID("responsePercentage"), responsePercentage1);
    export(new MetricID("responsePercentage", new Tag("servlet", "two")), responsePercentage2);
    export(new MetricID("responsePercentage", new Tag("store", "webshop"), new Tag("servlet", "three")), responsePercentage3);
    assertOutputEqualsFile("Gauge.json");
}
Also used : MetricID(org.eclipse.microprofile.metrics.MetricID) Tag(org.eclipse.microprofile.metrics.Tag) 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