Search in sources :

Example 11 with MetricRegistry

use of org.eclipse.microprofile.metrics.MetricRegistry in project Payara by payara.

the class MetricsService method getOrAddRegistry.

/**
 * Returns the Metrics registry based on respective registry name,
 * if not available then add the new MetricRegistry instance
 *
 * @param registryName
 * @return
 */
public MetricRegistry getOrAddRegistry(String registryName) {
    MetricRegistry registry = REGISTRIES.get(registryName.toLowerCase());
    if (registry == null) {
        registry = new MetricRegistryImpl();
        final MetricRegistry raced = REGISTRIES.putIfAbsent(registryName.toLowerCase(), registry);
        if (raced != null) {
            registry = raced;
        }
    }
    return registry;
}
Also used : MetricRegistry(org.eclipse.microprofile.metrics.MetricRegistry) MetricRegistryImpl(fish.payara.microprofile.metrics.impl.MetricRegistryImpl)

Example 12 with MetricRegistry

use of org.eclipse.microprofile.metrics.MetricRegistry 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 13 with MetricRegistry

use of org.eclipse.microprofile.metrics.MetricRegistry 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 14 with MetricRegistry

use of org.eclipse.microprofile.metrics.MetricRegistry in project wildfly-swarm by wildfly-swarm.

the class Helper method countNonEmptyScopes.

static int countNonEmptyScopes() {
    MetricRegistry.Type[] values = MetricRegistry.Type.values();
    int totalNonEmptyScopes = 0;
    for (MetricRegistry.Type scope : values) {
        MetricRegistry registry = MetricRegistryFactory.get(scope);
        if (registry.getNames().size() > 0) {
            totalNonEmptyScopes++;
        }
    }
    return totalNonEmptyScopes;
}
Also used : MetricRegistry(org.eclipse.microprofile.metrics.MetricRegistry)

Example 15 with MetricRegistry

use of org.eclipse.microprofile.metrics.MetricRegistry in project wildfly-swarm by wildfly-swarm.

the class JsonExporter method getMetricsForAScope.

private void getMetricsForAScope(StringBuilder sb, MetricRegistry.Type scope) {
    MetricRegistry registry = MetricRegistryFactory.get(scope);
    Map<String, Metric> metricMap = registry.getMetrics();
    Map<String, Metadata> metadataMap = registry.getMetadata();
    sb.append("{\n");
    writeMetricsForMap(sb, metricMap, metadataMap);
    sb.append("}");
}
Also used : MetricRegistry(org.eclipse.microprofile.metrics.MetricRegistry) Metadata(org.eclipse.microprofile.metrics.Metadata) Metric(org.eclipse.microprofile.metrics.Metric)

Aggregations

MetricRegistry (org.eclipse.microprofile.metrics.MetricRegistry)18 Metadata (org.eclipse.microprofile.metrics.Metadata)7 HashMap (java.util.HashMap)5 Metric (org.eclipse.microprofile.metrics.Metric)5 Map (java.util.Map)3 MetricsService (fish.payara.microprofile.metrics.MetricsService)2 NoSuchMetricException (fish.payara.microprofile.metrics.exception.NoSuchMetricException)2 AnnotatedMember (javax.enterprise.inject.spi.AnnotatedMember)2 MetricsHelper (fish.payara.microprofile.metrics.cdi.MetricsHelper)1 MetricProducer (fish.payara.microprofile.metrics.cdi.producer.MetricProducer)1 MetricRegistryProducer (fish.payara.microprofile.metrics.cdi.producer.MetricRegistryProducer)1 MetricRegistryImpl (fish.payara.microprofile.metrics.impl.MetricRegistryImpl)1 MBeanMetadata (fish.payara.microprofile.metrics.jmx.MBeanMetadata)1 MBeanMetadataHelper.registerMetadata (fish.payara.microprofile.metrics.jmx.MBeanMetadataHelper.registerMetadata)1 MonitoringDataCollector (fish.payara.monitoring.collect.MonitoringDataCollector)1 HttpString (io.undertow.util.HttpString)1 Bean (javax.enterprise.inject.spi.Bean)1 ProcessProducer (javax.enterprise.inject.spi.ProcessProducer)1 Producer (javax.enterprise.inject.spi.Producer)1 MetricID (org.eclipse.microprofile.metrics.MetricID)1