Search in sources :

Example 6 with Tag

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

the class JsonExporter method appendMember.

private void appendMember(MetricID metricID, String field, Number value) {
    if (mode == Mode.OPTIONS) {
        // nothing to do, metadata written in connection with group update
        return;
    }
    JsonObjectBuilder target = groupObj != null ? groupObj : scopeObj != null ? scopeObj : documentObj;
    String name = field != null ? field : metricID.getName();
    List<Tag> tags = tagsAlphabeticallySorted(metricID);
    if (!tags.isEmpty()) {
        for (Tag tag : tags) {
            name += ';' + tagAsString(tag);
        }
    }
    if (value instanceof Float || value instanceof Double) {
        target.add(name, value.doubleValue());
    } else if (value instanceof BigDecimal) {
        target.add(name, (BigDecimal) value);
    } else if (value instanceof BigInteger) {
        target.add(name, (BigInteger) value);
    } else if (value == null) {
        target.addNull(name);
    } else {
        target.add(name, value.longValue());
    }
}
Also used : BigInteger(java.math.BigInteger) Tag(org.eclipse.microprofile.metrics.Tag) JsonObjectBuilder(javax.json.JsonObjectBuilder) BigDecimal(java.math.BigDecimal)

Example 7 with Tag

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

the class OpenMetricsExporter method exportSampling.

private void exportSampling(MetricID metricID, Sampling sampling, LongSupplier count, Supplier<Number> sum, Metadata metadata) {
    Tag[] tags = metricID.getTagsAsArray();
    Snapshot snapshot = sampling.getSnapshot();
    String mean = globalName(metricID, "_mean", metadata);
    appendTYPE(mean, OpenMetricsType.gauge);
    appendValue(mean, tags, scaleToBaseUnit(snapshot.getMean(), metadata));
    String max = globalName(metricID, "_max", metadata);
    appendTYPE(max, OpenMetricsType.gauge);
    appendValue(max, tags, scaleToBaseUnit(snapshot.getMax(), metadata));
    String min = globalName(metricID, "_min", metadata);
    appendTYPE(min, OpenMetricsType.gauge);
    appendValue(min, tags, scaleToBaseUnit(snapshot.getMin(), metadata));
    String stddev = globalName(metricID, "_stddev", metadata);
    appendTYPE(stddev, OpenMetricsType.gauge);
    appendValue(stddev, tags, scaleToBaseUnit(snapshot.getStdDev(), metadata));
    String summary = globalName(metricID, metadata);
    appendTYPE(summary, OpenMetricsType.summary);
    appendHELP(summary, metadata);
    appendValue(globalName(metricID, metadata, "_count"), tags, count.getAsLong());
    appendValue(globalName(metricID, metadata, "_sum"), tags, sum.get());
    appendValue(summary, tags("quantile", "0.5", tags), scaleToBaseUnit(snapshot.getMedian(), metadata));
    appendValue(summary, tags("quantile", "0.75", tags), scaleToBaseUnit(snapshot.get75thPercentile(), metadata));
    appendValue(summary, tags("quantile", "0.95", tags), scaleToBaseUnit(snapshot.get95thPercentile(), metadata));
    appendValue(summary, tags("quantile", "0.98", tags), scaleToBaseUnit(snapshot.get98thPercentile(), metadata));
    appendValue(summary, tags("quantile", "0.99", tags), scaleToBaseUnit(snapshot.get99thPercentile(), metadata));
    appendValue(summary, tags("quantile", "0.999", tags), scaleToBaseUnit(snapshot.get999thPercentile(), metadata));
}
Also used : Snapshot(org.eclipse.microprofile.metrics.Snapshot) Tag(org.eclipse.microprofile.metrics.Tag)

Example 8 with Tag

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

the class OpenMetricsExporter method tags.

private static Tag[] tags(String name, String value, Tag[] rest) {
    Tag tag = new Tag(name, value);
    if (rest.length == 0) {
        return new Tag[] { tag };
    }
    Tag[] res = Arrays.copyOf(rest, rest.length + 1);
    res[rest.length] = tag;
    return res;
}
Also used : Tag(org.eclipse.microprofile.metrics.Tag)

Example 9 with Tag

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

the class MetricRegistryImplTest method removeMatchingRemovesAllMatchingMetrics.

@Test
public void removeMatchingRemovesAllMatchingMetrics() {
    registry.concurrentGauge(nextName(), new Tag("x", "y"));
    registry.timer(nextName(), new Tag("x", "z"));
    registry.histogram(nextName(), new Tag("x", "y"));
    registry.meter(nextName(), new Tag("z", "a"));
    registry.timer(nextName(), new Tag("h", "i"));
    assertEquals(5, registry.getNames().size());
    registry.removeMatching((id, metric) -> id.getTags().containsValue("y"));
    assertEquals(3, registry.getNames().size());
    assertEquals(2, registry.getTimers().size());
    assertEquals(1, registry.getMeters().size());
    registry.removeMatching((id, metric) -> id.getTags().containsKey("x"));
    assertEquals(2, registry.getNames().size());
    registry.removeMatching(MetricFilter.ALL);
    assertEquals(0, registry.getNames().size());
}
Also used : Tag(org.eclipse.microprofile.metrics.Tag) Test(org.junit.Test)

Example 10 with Tag

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

the class JsonExporterGetTest method multipeRepositoriesAreGroupedByNameMetricOption.

@Test
public void multipeRepositoriesAreGroupedByNameMetricOption() {
    exporter = exporter.in(Type.BASE);
    Gauge<Long> fooVal = () -> 1L;
    MetricID fooValID = new MetricID("fooVal", new Tag("store", "webshop"));
    export(fooValID, fooVal);
    exporter = exporter.in(Type.APPLICATION);
    export(fooValID, fooVal);
    assertOutputEquals("\n" + "{\n" + "    \"base\": {\n" + "        \"fooVal;store=webshop\": 1\n" + "    },\n" + "    \"application\": {\n" + "        \"fooVal;store=webshop\": 1\n" + "    }\n" + "}");
}
Also used : MetricID(org.eclipse.microprofile.metrics.MetricID) Tag(org.eclipse.microprofile.metrics.Tag) 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