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