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());
}
}
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));
}
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;
}
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());
}
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" + "}");
}
Aggregations