Search in sources :

Example 46 with MetricID

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

the class JsonExporterGetTest method exportHistogram.

@Test
public void exportHistogram() {
    Histogram histogram = mock(Histogram.class);
    when(histogram.getCount()).thenReturn(2L);
    when(histogram.getSum()).thenReturn(42L);
    Snapshot snapshot = mock(Snapshot.class);
    when(histogram.getSnapshot()).thenReturn(snapshot);
    when(snapshot.getMin()).thenReturn(-1624L);
    when(snapshot.getMax()).thenReturn(26L);
    when(snapshot.getMean()).thenReturn(-799.0d);
    when(snapshot.getStdDev()).thenReturn(825d);
    when(snapshot.getMedian()).thenReturn(26d);
    when(snapshot.get75thPercentile()).thenReturn(26d);
    when(snapshot.get95thPercentile()).thenReturn(26d);
    when(snapshot.get98thPercentile()).thenReturn(26d);
    when(snapshot.get99thPercentile()).thenReturn(26d);
    when(snapshot.get999thPercentile()).thenReturn(26d);
    // example uses same values for both histograms so we can get away with just one
    // but conceptually those should be two different histogram instances
    export(new MetricID("daily_value_changes"), histogram);
    export(new MetricID("daily_value_changes", new Tag("servlet", "two")), histogram);
    assertOutputEqualsFile("Histogram.json");
}
Also used : Snapshot(org.eclipse.microprofile.metrics.Snapshot) Histogram(org.eclipse.microprofile.metrics.Histogram) MetricID(org.eclipse.microprofile.metrics.MetricID) Tag(org.eclipse.microprofile.metrics.Tag) Test(org.junit.Test)

Example 47 with MetricID

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

the class OpenMetricsExporterTest method unitPerSecondUsesUnscaledValue.

@Test
public void unitPerSecondUsesUnscaledValue() {
    Gauge<Double> perSec = () -> 2.3d;
    MetricID metricID = new MetricID("test7");
    Metadata metadata = Metadata.builder().withName(metricID.getName()).withUnit(MetricUnits.PER_SECOND).build();
    assertOutputEquals("# TYPE application_test7_per_second gauge\n" + "application_test7_per_second 2.3\n", metricID, perSec, metadata);
}
Also used : MetricID(org.eclipse.microprofile.metrics.MetricID) Metadata(org.eclipse.microprofile.metrics.Metadata) Test(org.junit.Test)

Example 48 with MetricID

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

the class OpenMetricsExporterTest method exportHistogram.

@Test
public void exportHistogram() {
    Histogram histogram = mock(Histogram.class);
    when(histogram.getCount()).thenReturn(2037L);
    when(histogram.getSum()).thenReturn(45678L);
    Snapshot snapshot = mock(Snapshot.class);
    when(histogram.getSnapshot()).thenReturn(snapshot);
    when(snapshot.getMin()).thenReturn(180L);
    when(snapshot.getMax()).thenReturn(31716L);
    when(snapshot.getMean()).thenReturn(4738.231d);
    when(snapshot.getStdDev()).thenReturn(1054.7343037063602d);
    when(snapshot.getMedian()).thenReturn(4201d);
    when(snapshot.get75thPercentile()).thenReturn(6175d);
    when(snapshot.get95thPercentile()).thenReturn(13560d);
    when(snapshot.get98thPercentile()).thenReturn(29643d);
    when(snapshot.get99thPercentile()).thenReturn(31716d);
    when(snapshot.get999thPercentile()).thenReturn(31716d);
    MetricID metricID = new MetricID("file_sizes");
    Metadata metadata = Metadata.builder().withName(metricID.getName()).withDescription("Users file size").withUnit(MetricUnits.BYTES).build();
    assertOutputEqualsFile("Histogram.txt", metricID, histogram, metadata);
}
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) Test(org.junit.Test)

Example 49 with MetricID

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

the class OpenMetricsExporterTest method exportCounter.

@Test
public void exportCounter() {
    Counter counter = mock(Counter.class);
    when(counter.getCount()).thenReturn(80L);
    MetricID metricID = new MetricID("visitors");
    Metadata metadata = Metadata.builder().withName(metricID.getName()).withDescription("The number of unique visitors").build();
    assertOutputEqualsFile("Counter.txt", 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 50 with MetricID

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

the class MetricsServiceImpl method collectRegistry.

private static void collectRegistry(String contextName, MetricRegistry registry, MonitoringDataCollector collector) {
    // OBS: this way of iterating the metrics in the registry is optimal because of its internal data organisation
    for (String name : registry.getNames()) {
        for (Entry<MetricID, Metric> entry : ((MetricRegistryImpl) registry).getMetrics(name).entrySet()) {
            MetricID metricID = entry.getKey();
            Metric metric = entry.getValue();
            try {
                MonitoringDataCollector metricCollector = tagCollector(contextName, metricID, collector);
                if (metric instanceof Counting) {
                    metricCollector.collect(toName(metricID, "Count"), ((Counting) metric).getCount());
                }
                if (metric instanceof SimpleTimer) {
                    metricCollector.collect(toName(metricID, "Duration"), ((SimpleTimer) metric).getElapsedTime().toMillis());
                }
                if (metric instanceof Timer) {
                    metricCollector.collect(toName(metricID, "MaxDuration"), ((Timer) metric).getSnapshot().getMax());
                }
                if (metric instanceof Gauge) {
                    Object value = ((Gauge<?>) metric).getValue();
                    if (value instanceof Number) {
                        metricCollector.collect(toName(metricID, getMetricUnitSuffix(registry.getMetadata(name).unit())), ((Number) value));
                    }
                }
            } catch (Exception ex) {
                LOGGER.log(Level.SEVERE, "Failed to retrieve metric: " + metricID);
                ;
            }
        }
    }
}
Also used : MonitoringDataCollector(fish.payara.monitoring.collect.MonitoringDataCollector) MetricID(org.eclipse.microprofile.metrics.MetricID) SimpleTimer(org.eclipse.microprofile.metrics.SimpleTimer) Timer(org.eclipse.microprofile.metrics.Timer) SimpleTimer(org.eclipse.microprofile.metrics.SimpleTimer) Metric(org.eclipse.microprofile.metrics.Metric) Counting(org.eclipse.microprofile.metrics.Counting) FileNotFoundException(java.io.FileNotFoundException) NoSuchRegistryException(fish.payara.microprofile.metrics.exception.NoSuchRegistryException) Gauge(org.eclipse.microprofile.metrics.Gauge)

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