Search in sources :

Example 6 with MetricRegistry

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

the class JsonMetadataExporter method exportAllScopes.

@Override
public StringBuilder exportAllScopes() {
    StringBuilder sb = new StringBuilder();
    sb.append("{");
    MetricRegistry.Type[] values = MetricRegistry.Type.values();
    int totalNonEmptyScopes = Helper.countNonEmptyScopes();
    int scopes = 0;
    for (int i = 0; i < values.length; i++) {
        MetricRegistry.Type scope = values[i];
        MetricRegistry registry = MetricRegistryFactory.get(scope);
        if (registry.getNames().size() > 0) {
            sb.append('"').append(scope.getName().toLowerCase()).append('"').append(" :\n");
            getDataForOneScope(scope, sb);
            sb.append(LF);
            scopes++;
            if (scopes < totalNonEmptyScopes) {
                sb.append(',');
            }
        }
    }
    sb.append("}");
    return sb;
}
Also used : MetricRegistry(org.eclipse.microprofile.metrics.MetricRegistry)

Example 7 with MetricRegistry

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

the class JsonMetadataExporter method getDataForOneScope.

private void getDataForOneScope(MetricRegistry.Type scope, StringBuilder sb) {
    MetricRegistry registry = MetricRegistryFactory.get(scope);
    Map<String, Metadata> theMetadata = registry.getMetadata();
    sb.append("{");
    writeMetadataForMap(sb, theMetadata);
    sb.append("}");
}
Also used : MetricRegistry(org.eclipse.microprofile.metrics.MetricRegistry) Metadata(org.eclipse.microprofile.metrics.Metadata)

Example 8 with MetricRegistry

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

the class JsonMetadataExporter method exportOneMetric.

@Override
public StringBuilder exportOneMetric(MetricRegistry.Type scope, String metricName) {
    MetricRegistry registry = MetricRegistryFactory.get(scope);
    Map<String, Metadata> metadataMap = registry.getMetadata();
    Metadata m = metadataMap.get(metricName);
    Map<String, Metadata> outMap = new HashMap<>(1);
    outMap.put(metricName, m);
    StringBuilder sb = new StringBuilder();
    sb.append("{");
    writeMetadataForMap(sb, outMap);
    sb.append("}");
    sb.append(LF);
    return sb;
}
Also used : HashMap(java.util.HashMap) MetricRegistry(org.eclipse.microprofile.metrics.MetricRegistry) Metadata(org.eclipse.microprofile.metrics.Metadata)

Example 9 with MetricRegistry

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

the class FaultToleranceServiceImpl method createMethodContext.

private FaultToleranceMethodContextImpl createMethodContext(MethodKey methodKey, InvocationContext context, RequestContextController requestContextController) {
    MetricsService.MetricsContext metricsContext = getMetricsContext();
    MetricRegistry metricRegistry = metricsContext != null ? metricsContext.getBaseRegistry() : null;
    String appName = metricsContext != null ? metricsContext.getName() : "";
    FaultToleranceMetrics metrics = metricRegistry == null ? FaultToleranceMetrics.DISABLED : new MethodFaultToleranceMetrics(metricRegistry, FaultToleranceUtils.getCanonicalMethodName(context));
    logger.log(Level.FINE, "Creating FT method context for {0}", methodKey);
    return new FaultToleranceMethodContextImpl(requestContextController, this, metrics, asyncExecutorService, delayExecutorService, appName);
}
Also used : MetricsService(fish.payara.microprofile.metrics.MetricsService) MetricRegistry(org.eclipse.microprofile.metrics.MetricRegistry)

Example 10 with MetricRegistry

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

the class MetricsServiceImpl method processMetadataToAnnotations.

private static void processMetadataToAnnotations(MetricsContextImpl context, MonitoringDataCollector collector) {
    RegisteredMetric metric = context.pollNewlyRegistered();
    while (metric != null) {
        MetricID metricID = metric.id;
        Type scope = metric.scope;
        MetricRegistry registry = context.getRegistry(scope);
        MonitoringDataCollector metricCollector = tagCollector(context.getName(), metricID, collector);
        Metadata metadata = registry.getMetadata(metricID.getName());
        String suffix = "Count";
        String property = "Count";
        boolean isGauge = metadata.getTypeRaw() == MetricType.GAUGE;
        if (isGauge) {
            suffix = getMetricUnitSuffix(metadata.unit());
            property = "Value";
        }
        // Note that by convention an annotation with value 0 done before the series collected any value is considered permanent
        metricCollector.annotate(toName(metricID, suffix), 0, false, metadataToAnnotations(context.getName(), scope, metadata, property));
        metric = context.pollNewlyRegistered();
    }
}
Also used : MonitoringDataCollector(fish.payara.monitoring.collect.MonitoringDataCollector) MetricID(org.eclipse.microprofile.metrics.MetricID) MetricType(org.eclipse.microprofile.metrics.MetricType) Type(org.eclipse.microprofile.metrics.MetricRegistry.Type) MetricRegistry(org.eclipse.microprofile.metrics.MetricRegistry) Metadata(org.eclipse.microprofile.metrics.Metadata) MBeanMetadata(fish.payara.microprofile.metrics.jmx.MBeanMetadata)

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