use of org.eclipse.microprofile.metrics.Tag 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.Tag 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.Tag 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");
}
use of org.eclipse.microprofile.metrics.Tag in project Payara by payara.
the class MetricIDTest method removalTest.
@SuppressWarnings({ "deprecation", "unused" })
@Test
public void removalTest() {
Tag tagEarth = new Tag("planet", "earth");
Tag tagRed = new Tag("colour", "red");
Tag tagBlue = new Tag("colour", "blue");
String counterName = "org.eclipse.microprofile.metrics.tck.MetricIDTest.counterColour";
Counter counterColour = registry.counter(counterName);
Counter counterRed = registry.counter(counterName, tagEarth, tagRed);
Counter counterBlue = registry.counter(counterName, tagEarth, tagBlue);
MetricID counterColourMID = new MetricID(counterName);
MetricID counterRedMID = new MetricID(counterName, tagEarth, tagRed);
MetricID counterBlueMID = new MetricID(counterName, tagEarth, tagRed);
// check multi-dimensional metrics are registered
assertThat("Counter is not registered correctly", registry.getCounter(counterColourMID), notNullValue());
assertThat("Counter is not registered correctly", registry.getCounter(counterRedMID), notNullValue());
assertThat("Counter is not registered correctly", registry.getCounter(counterBlueMID), notNullValue());
// remove one metric
registry.remove(counterColourMID);
assertThat("Registry did not remove metric", registry.getCounters().size(), equalTo(2));
assertThat("Counter is not registered correctly", registry.getCounter(counterColourMID), nullValue());
// remove all metrics with the given name
registry.remove(counterName);
assertThat("Counter is not registered correctly", registry.getCounter(counterRedMID), nullValue());
assertThat("Counter is not registered correctly", registry.getCounter(counterBlueMID), nullValue());
}
use of org.eclipse.microprofile.metrics.Tag in project Payara by payara.
the class JsonExporterGetTest method exportTimer.
@Test
public void exportTimer() {
Timer timer = mock(Timer.class);
when(timer.getElapsedTime()).thenReturn(Duration.ofMillis(45678L));
when(timer.getCount()).thenReturn(29382L);
when(timer.getMeanRate()).thenReturn(12.185627192860734d);
when(timer.getOneMinuteRate()).thenReturn(12.563d);
when(timer.getFiveMinuteRate()).thenReturn(12.364d);
when(timer.getFifteenMinuteRate()).thenReturn(12.126d);
Snapshot snapshot = mock(Snapshot.class);
when(timer.getSnapshot()).thenReturn(snapshot);
when(snapshot.getMin()).thenReturn(169916L);
when(snapshot.getMax()).thenReturn(5608694L);
when(snapshot.getMean()).thenReturn(415041.00024926325d);
when(snapshot.getStdDev()).thenReturn(652907.9633011606d);
when(snapshot.getMedian()).thenReturn(293324.0d);
when(snapshot.get75thPercentile()).thenReturn(344914d);
when(snapshot.get95thPercentile()).thenReturn(543647d);
when(snapshot.get98thPercentile()).thenReturn(2706543d);
when(snapshot.get99thPercentile()).thenReturn(5608694d);
when(snapshot.get999thPercentile()).thenReturn(5608694d);
// example uses same values for both timers so we can get away with just one
// but conceptually those should be two different timer instances
export(new MetricID("responseTime"), timer);
export(new MetricID("responseTime", new Tag("servlet", "two")), timer);
assertOutputEqualsFile("Timer.json");
}
Aggregations