Search in sources :

Example 56 with Metadata

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

the class JsonExporterOptionsTest method multipeRepositoriesAreGroupedByNameMetricOption.

/*
     * Below tests are no examples from the specification
     */
@Test
public void multipeRepositoriesAreGroupedByNameMetricOption() {
    exporter = exporter.in(Type.BASE);
    Gauge<Long> fooVal = () -> 1L;
    MetricID fooValID = new MetricID("fooVal", new Tag("store", "webshop"));
    Metadata fooValMeta = Metadata.builder().withName("fooVal").withDescription("The size of foo after each request").withUnit(MetricUnits.MILLISECONDS).withDisplayName("Size of foo").withType(MetricType.GAUGE).build();
    export(fooValID, fooVal, fooValMeta);
    exporter = exporter.in(Type.APPLICATION);
    export(fooValID, fooVal, fooValMeta);
    assertOutputEqualsFile("Options3.json");
}
Also used : MetricID(org.eclipse.microprofile.metrics.MetricID) Metadata(org.eclipse.microprofile.metrics.Metadata) Tag(org.eclipse.microprofile.metrics.Tag) Test(org.junit.Test)

Example 57 with Metadata

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

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

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

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

the class JsonExporter method exportMetadata.

private void exportMetadata() {
    if (exportedBefore == null) {
        return;
    }
    JsonObjectBuilder target = scopeObj != null ? scopeObj : documentObj;
    JsonObjectBuilder metadataObj = Json.createObjectBuilder();
    Metadata metadata = exportedBeforeMetadata;
    metadataObj.add("unit", metadata.unit().orElse(MetricUnits.NONE));
    metadataObj.add("type", metadata.getTypeRaw().toString());
    if (metadata.description().isPresent()) {
        String desc = metadata.getDescription();
        if (!desc.isEmpty()) {
            metadataObj.add("description", desc);
        }
    }
    String displayName = metadata.getDisplayName();
    String name = exportedBefore.getName();
    if (!displayName.isEmpty() && !displayName.equals(name)) {
        metadataObj.add("displayName", displayName);
    }
    if (tagsArray != null) {
        metadataObj.add("tags", tagsArray.build());
        tagsArray = null;
    }
    target.add(name, metadataObj.build());
}
Also used : Metadata(org.eclipse.microprofile.metrics.Metadata) JsonObjectBuilder(javax.json.JsonObjectBuilder)

Aggregations

Metadata (org.eclipse.microprofile.metrics.Metadata)65 MetricID (org.eclipse.microprofile.metrics.MetricID)31 Test (org.junit.Test)30 Tag (org.eclipse.microprofile.metrics.Tag)12 Counter (org.eclipse.microprofile.metrics.Counter)9 Metric (org.eclipse.microprofile.metrics.Metric)9 MetricRegistry (org.eclipse.microprofile.metrics.MetricRegistry)8 HashMap (java.util.HashMap)6 Map (java.util.Map)4 Histogram (org.eclipse.microprofile.metrics.Histogram)4 ArrayList (java.util.ArrayList)3 Meter (org.eclipse.microprofile.metrics.Meter)3 Gauge (org.eclipse.microprofile.metrics.annotation.Gauge)3 ObjectName (javax.management.ObjectName)2 GET (javax.ws.rs.GET)2 Path (javax.ws.rs.Path)2 Gauge (org.eclipse.microprofile.metrics.Gauge)2 MetricType (org.eclipse.microprofile.metrics.MetricType)2 SimpleTimer (org.eclipse.microprofile.metrics.SimpleTimer)2 Snapshot (org.eclipse.microprofile.metrics.Snapshot)2