use of org.eclipse.microprofile.metrics.Metadata 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.Metadata in project Payara by payara.
the class OpenMetricsExporterTest method unitPerSecondUsesUnscaledValue.
@Test
public void unitPerSecondUsesUnscaledValue() {
Gauge<Double> perSec = () -> 2.3d;
MetricID metricID = new MetricID("test7");
Metadata metadata = Metadata.builder().withName(metricID.getName()).withUnit(MetricUnits.PER_SECOND).build();
assertOutputEquals("# TYPE application_test7_per_second gauge\n" + "application_test7_per_second 2.3\n", metricID, perSec, metadata);
}
use of org.eclipse.microprofile.metrics.Metadata in project Payara by payara.
the class OpenMetricsExporterTest method exportHistogram.
@Test
public void exportHistogram() {
Histogram histogram = mock(Histogram.class);
when(histogram.getCount()).thenReturn(2037L);
when(histogram.getSum()).thenReturn(45678L);
Snapshot snapshot = mock(Snapshot.class);
when(histogram.getSnapshot()).thenReturn(snapshot);
when(snapshot.getMin()).thenReturn(180L);
when(snapshot.getMax()).thenReturn(31716L);
when(snapshot.getMean()).thenReturn(4738.231d);
when(snapshot.getStdDev()).thenReturn(1054.7343037063602d);
when(snapshot.getMedian()).thenReturn(4201d);
when(snapshot.get75thPercentile()).thenReturn(6175d);
when(snapshot.get95thPercentile()).thenReturn(13560d);
when(snapshot.get98thPercentile()).thenReturn(29643d);
when(snapshot.get99thPercentile()).thenReturn(31716d);
when(snapshot.get999thPercentile()).thenReturn(31716d);
MetricID metricID = new MetricID("file_sizes");
Metadata metadata = Metadata.builder().withName(metricID.getName()).withDescription("Users file size").withUnit(MetricUnits.BYTES).build();
assertOutputEqualsFile("Histogram.txt", metricID, histogram, metadata);
}
use of org.eclipse.microprofile.metrics.Metadata in project Payara by payara.
the class OpenMetricsExporterTest method exportCounter.
@Test
public void exportCounter() {
Counter counter = mock(Counter.class);
when(counter.getCount()).thenReturn(80L);
MetricID metricID = new MetricID("visitors");
Metadata metadata = Metadata.builder().withName(metricID.getName()).withDescription("The number of unique visitors").build();
assertOutputEqualsFile("Counter.txt", metricID, counter, metadata);
}
use of org.eclipse.microprofile.metrics.Metadata in project Payara by payara.
the class JsonExporter method exportMetadata.
private void exportMetadata() {
if (exportedBefore == null) {
return;
}
JsonObjectBuilder target = scopeObj != null ? scopeObj : documentObj;
JsonObjectBuilder metadataObj = Json.createObjectBuilder();
Metadata metadata = exportedBeforeMetadata;
metadataObj.add("unit", metadata.unit().orElse(MetricUnits.NONE));
metadataObj.add("type", metadata.getTypeRaw().toString());
if (metadata.description().isPresent()) {
String desc = metadata.getDescription();
if (!desc.isEmpty()) {
metadataObj.add("description", desc);
}
}
String displayName = metadata.getDisplayName();
String name = exportedBefore.getName();
if (!displayName.isEmpty() && !displayName.equals(name)) {
metadataObj.add("displayName", displayName);
}
if (tagsArray != null) {
metadataObj.add("tags", tagsArray.build());
tagsArray = null;
}
target.add(name, metadataObj.build());
}
Aggregations