use of org.eclipse.microprofile.metrics.Metadata in project tomee by apache.
the class WeatherService method getTemperatures.
@Path("/histogram")
@GET
@Produces(MediaType.APPLICATION_JSON)
public Histogram getTemperatures() {
Metadata metadata = new Metadata("temperatures", MetricType.HISTOGRAM, "degrees F");
metadata.setDescription("A histogram of recent New York temperatures.");
histogram = registry.histogram(metadata);
for (int temp : RECENT_NEW_YORK_TEMPS) {
histogram.update(temp);
}
return histogram;
}
use of org.eclipse.microprofile.metrics.Metadata in project Payara by payara.
the class MetricsService method getMetadataAsMap.
public Map<String, Metadata> getMetadataAsMap(String registryName, String metricName) throws NoSuchRegistryException, NoSuchMetricException {
MetricRegistry registry = getRegistry(registryName);
Map<String, Metadata> metricMetadataMap = registry.getMetadata();
if (metricMetadataMap.containsKey(metricName)) {
return singletonMap(metricName, metricMetadataMap.get(metricName));
} else {
throw new NoSuchMetricException(metricName);
}
}
use of org.eclipse.microprofile.metrics.Metadata in project Payara by payara.
the class MetricsHelper method metadataOf.
private Metadata metadataOf(Annotated annotated, Class<?> type, String name) {
Metadata metadata = new Metadata(name, MetricType.from(type));
if (annotated.isAnnotationPresent(Metric.class)) {
Metric metric = annotated.getAnnotation(Metric.class);
metadata.setDescription(metric.description() == null || metric.description().trim().isEmpty() ? null : metric.description());
metadata.setDisplayName(metric.displayName() == null || metric.displayName().trim().isEmpty() ? null : metric.displayName());
metadata.setUnit(metric.unit() == null || metric.unit().trim().isEmpty() ? null : metric.unit());
for (String tag : metric.tags()) {
metadata.addTag(tag);
}
}
return metadata;
}
use of org.eclipse.microprofile.metrics.Metadata in project Payara by payara.
the class MetricCDIExtension method registerCustomMetrics.
private void registerCustomMetrics(@Observes AfterDeploymentValidation adv, BeanManager manager) {
MetricsService metricsService = Globals.getDefaultBaseServiceLocator().getService(MetricsService.class);
MetricRegistry registry = metricsService.getOrAddRegistry(metricsService.getApplicationName());
MetricsHelper helper = getReference(manager, MetricsHelper.class);
for (Map.Entry<Producer<?>, AnnotatedMember<?>> entry : metrics.entrySet()) {
AnnotatedMember<?> annotatedMember = entry.getValue();
Producer<?> prod = entry.getKey();
if (hasInjectionPoints(annotatedMember)) {
continue;
}
Metadata metadata = helper.metadataOf(annotatedMember);
registry.register(metadata.getName(), (Metric) prod.produce(manager.createCreationalContext(null)), metadata);
}
metrics.clear();
}
use of org.eclipse.microprofile.metrics.Metadata in project Payara by payara.
the class PrometheusWriter method writeMetricMap.
private void writeMetricMap(StringBuilder builder, String registryName, Map<String, Metric> metricMap, Map<String, Metadata> metricMetadataMap) {
for (Entry<String, Metric> entry : metricMap.entrySet()) {
String metricName = entry.getKey();
// Scope and name are separated by colon (:)
if (!BASE.getName().equals(registryName) && !VENDOR.getName().equals(registryName)) {
registryName = APPLICATION.getName();
}
String name = registryName + ":" + metricName;
Metric metric = entry.getValue();
Metadata metricMetadata = metricMetadataMap.get(metricName);
String description = metricMetadata.getDescription() == null || metricMetadata.getDescription().trim().isEmpty() ? EMPTY_STRING : metricMetadata.getDescription();
String tags = metricMetadata.getTagsAsString();
String unit = metricMetadata.getUnit();
PrometheusExporter exporter = new PrometheusExporter(builder);
if (Counter.class.isInstance(metric)) {
exporter.exportCounter((Counter) metric, name, description, tags);
} else if (Gauge.class.isInstance(metric)) {
exporter.exportGauge((Gauge) metric, name, description, tags, unit);
} else if (Histogram.class.isInstance(metric)) {
exporter.exportHistogram((Histogram) metric, name, description, tags, unit);
} else if (Meter.class.isInstance(metric)) {
exporter.exportMeter((Meter) metric, name, description, tags);
} else if (Timer.class.isInstance(metric)) {
exporter.exportTimer((Timer) metric, name, description, tags, unit);
} else {
LOGGER.log(Level.WARNING, "Metric type {0} for {1} is invalid", new Object[] { metric.getClass(), metricName });
}
}
}
Aggregations