Search in sources :

Example 36 with MetricID

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

the class MetricsWriterImpl method writeMetricFamily.

private void writeMetricFamily(MetricExporter exporter, String contextName, String metricName, MetricRegistryImpl registry) {
    Metadata metadata = registry.getMetadata(metricName);
    for (Entry<MetricID, Metric> metric : registry.getMetrics(metricName).entrySet()) {
        MetricID metricID = metric.getKey();
        if (globalTags.length > 0) {
            Tag[] tagsWithoutGlobal = metricID.getTagsAsArray();
            Tag[] tags = new Tag[tagsWithoutGlobal.length + globalTags.length];
            arraycopy(globalTags, 0, tags, 0, globalTags.length);
            arraycopy(tagsWithoutGlobal, 0, tags, globalTags.length, tagsWithoutGlobal.length);
            metricID = new MetricID(metricName, tags);
        }
        if (!contextName.isEmpty()) {
            Tag[] tagsWithoutApp = metricID.getTagsAsArray();
            Tag[] tags = Arrays.copyOf(tagsWithoutApp, tagsWithoutApp.length + 1);
            tags[tagsWithoutApp.length] = new Tag("_app", contextName);
            metricID = new MetricID(metricName, tags);
        }
        exporter.export(metricID, metric.getValue(), metadata);
    }
}
Also used : MetricID(org.eclipse.microprofile.metrics.MetricID) Metadata(org.eclipse.microprofile.metrics.Metadata) Metric(org.eclipse.microprofile.metrics.Metric) Tag(org.eclipse.microprofile.metrics.Tag)

Example 37 with MetricID

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

the class MetricRegistryImplTest method getMetricById.

@Test
public void getMetricById() {
    String name = nextName();
    Counter c1 = registry.counter(name);
    assertSame(c1, registry.getMetric(new MetricID(name), Counter.class));
}
Also used : MetricID(org.eclipse.microprofile.metrics.MetricID) Counter(org.eclipse.microprofile.metrics.Counter) Test(org.junit.Test)

Example 38 with MetricID

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

the class JsonExporterOptionsTest method gaugesThatThrowIllegalStateExceptionWhenReadDoExportMetadata.

@Test
public void gaugesThatThrowIllegalStateExceptionWhenReadDoExportMetadata() {
    Gauge<Long> gauge = () -> {
        throw new IllegalStateException("test");
    };
    MetricID metricID = new MetricID("test4");
    Metadata metadata = Metadata.builder().withName(metricID.getName()).withType(MetricType.GAUGE).build();
    assertOutputEquals("\n" + "{\n" + "    \"test4\": {\n" + "        \"unit\": \"none\",\n" + "        \"type\": \"gauge\"\n" + "    }\n" + "}", metricID, gauge, metadata);
}
Also used : MetricID(org.eclipse.microprofile.metrics.MetricID) Metadata(org.eclipse.microprofile.metrics.Metadata) Test(org.junit.Test)

Example 39 with MetricID

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

the class JsonExporterOptionsTest method multipleMetricOptionsAreGroupedByName.

@Test
public void multipleMetricOptionsAreGroupedByName() {
    Gauge<Long> fooVal = () -> 1L;
    MetricID fooValID = new MetricID("fooVal", new Tag("store", "webshop"));
    Metadata fooValMeta = Metadata.builder().withName("fooVal").withDescription("The average duration of foo requests during last 5 minutes").withUnit(MetricUnits.MILLISECONDS).withDisplayName("Duration of foo").withType(MetricType.GAUGE).build();
    Gauge<Long> barVal1 = () -> 2L;
    Gauge<Long> barVal2 = () -> 3L;
    MetricID barValID1 = new MetricID("barVal", new Tag("store", "webshop"), new Tag("component", "backend"));
    MetricID barValID2 = new MetricID("barVal", new Tag("store", "webshop"), new Tag("component", "frontend"));
    Metadata barValMeta = Metadata.builder().withName("barVal").withUnit(MetricUnits.MEGABYTES).withType(MetricType.GAUGE).build();
    export(fooValID, fooVal, fooValMeta);
    export(barValID1, barVal1, barValMeta);
    export(barValID2, barVal2, barValMeta);
    assertOutputEqualsFile("Options2.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 40 with MetricID

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

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