Search in sources :

Example 36 with Metadata

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;
}
Also used : Metadata(org.eclipse.microprofile.metrics.Metadata) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 37 with Metadata

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);
    }
}
Also used : NoSuchMetricException(fish.payara.microprofile.metrics.exception.NoSuchMetricException) MetricRegistry(org.eclipse.microprofile.metrics.MetricRegistry) MBeanMetadataHelper.registerMetadata(fish.payara.microprofile.metrics.jmx.MBeanMetadataHelper.registerMetadata) Metadata(org.eclipse.microprofile.metrics.Metadata)

Example 38 with Metadata

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;
}
Also used : Metadata(org.eclipse.microprofile.metrics.Metadata) Metric(org.eclipse.microprofile.metrics.annotation.Metric)

Example 39 with 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();
}
Also used : MetricProducer(fish.payara.microprofile.metrics.cdi.producer.MetricProducer) ProcessProducer(javax.enterprise.inject.spi.ProcessProducer) Producer(javax.enterprise.inject.spi.Producer) MetricRegistryProducer(fish.payara.microprofile.metrics.cdi.producer.MetricRegistryProducer) MetricsService(fish.payara.microprofile.metrics.MetricsService) MetricRegistry(org.eclipse.microprofile.metrics.MetricRegistry) MetricsHelper(fish.payara.microprofile.metrics.cdi.MetricsHelper) AnnotatedMember(javax.enterprise.inject.spi.AnnotatedMember) Metadata(org.eclipse.microprofile.metrics.Metadata) HashMap(java.util.HashMap) Map(java.util.Map)

Example 40 with Metadata

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 });
        }
    }
}
Also used : Meter(org.eclipse.microprofile.metrics.Meter) Metadata(org.eclipse.microprofile.metrics.Metadata) Metric(org.eclipse.microprofile.metrics.Metric) Gauge(org.eclipse.microprofile.metrics.Gauge)

Aggregations

Metadata (org.eclipse.microprofile.metrics.Metadata)65 MetricID (org.eclipse.microprofile.metrics.MetricID)31 Test (org.junit.Test)30 Tag (org.eclipse.microprofile.metrics.Tag)12 Counter (org.eclipse.microprofile.metrics.Counter)9 Metric (org.eclipse.microprofile.metrics.Metric)9 MetricRegistry (org.eclipse.microprofile.metrics.MetricRegistry)8 HashMap (java.util.HashMap)6 Map (java.util.Map)4 Histogram (org.eclipse.microprofile.metrics.Histogram)4 ArrayList (java.util.ArrayList)3 Meter (org.eclipse.microprofile.metrics.Meter)3 Gauge (org.eclipse.microprofile.metrics.annotation.Gauge)3 ObjectName (javax.management.ObjectName)2 GET (javax.ws.rs.GET)2 Path (javax.ws.rs.Path)2 Gauge (org.eclipse.microprofile.metrics.Gauge)2 MetricType (org.eclipse.microprofile.metrics.MetricType)2 SimpleTimer (org.eclipse.microprofile.metrics.SimpleTimer)2 Snapshot (org.eclipse.microprofile.metrics.Snapshot)2