Search in sources :

Example 61 with Metadata

use of org.eclipse.microprofile.metrics.Metadata 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)

Example 62 with Metadata

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

the class PrometheusExporter method exposeEntries.

private void exposeEntries(MetricRegistry.Type scope, StringBuilder sb, MetricRegistry registry, Map<String, Metric> metricMap) {
    for (Map.Entry<String, Metric> entry : metricMap.entrySet()) {
        String key = entry.getKey();
        Metadata md = registry.getMetadata().get(key);
        Metric metric = entry.getValue();
        switch(md.getTypeRaw()) {
            case GAUGE:
            case COUNTER:
                key = getPrometheusMetricName(md, key);
                String suffix = null;
                if (!md.getUnit().equals(MetricUnits.NONE)) {
                    suffix = USCORE + PrometheusUnit.getBaseUnitAsPrometheusString(md.getUnit());
                }
                writeHelpLine(sb, scope, key, md, suffix);
                writeTypeLine(sb, scope, key, md, suffix, null);
                createSimpleValueLine(sb, scope, key, md, metric);
                break;
            case METERED:
                MeterImpl meter = (MeterImpl) metric;
                writeMeterValues(sb, scope, meter, md);
                break;
            case TIMER:
                TimerImpl timer = (TimerImpl) metric;
                writeTimerValues(sb, scope, timer, md);
                break;
            case HISTOGRAM:
                HistogramImpl histogram = (HistogramImpl) metric;
                writeHistogramValues(sb, scope, histogram, md);
                break;
            default:
                throw new IllegalArgumentException("Not supported: " + key);
        }
    }
}
Also used : Metadata(org.eclipse.microprofile.metrics.Metadata) MeterImpl(org.wildfly.swarm.microprofile.metrics.runtime.app.MeterImpl) Metric(org.eclipse.microprofile.metrics.Metric) HistogramImpl(org.wildfly.swarm.microprofile.metrics.runtime.app.HistogramImpl) TimerImpl(org.wildfly.swarm.microprofile.metrics.runtime.app.TimerImpl) HashMap(java.util.HashMap) Map(java.util.Map)

Example 63 with Metadata

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

the class AMetricRegistryFactory method getMetadata.

private Metadata getMetadata(InjectionPoint ip, MetricType type) {
    Metadata metadata = new Metadata(metricName.of(ip), type);
    Metric metric = ip.getAnnotated().getAnnotation(Metric.class);
    if (metric != null) {
        if (!metric.unit().isEmpty()) {
            metadata.setUnit(metric.unit());
        }
        if (!metric.description().isEmpty()) {
            metadata.setDescription(metric.description());
        }
        if (!metric.displayName().isEmpty()) {
            metadata.setDisplayName(metric.displayName());
        }
        if (metric.tags().length > 0) {
            for (String tag : metric.tags()) {
                metadata.addTags(tag);
            }
        }
    }
    return metadata;
}
Also used : Metadata(org.eclipse.microprofile.metrics.Metadata) Metric(org.eclipse.microprofile.metrics.annotation.Metric)

Example 64 with Metadata

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

the class MetricsInterceptor method registerMetrics.

private <E extends Member & AnnotatedElement> void registerMetrics(Class<?> bean, E element) {
    MetricResolver.Of<Counted> counted = resolver.counted(bean, element);
    if (counted.isPresent()) {
        Counted t = counted.metricAnnotation();
        Metadata metadata = getMetadata(counted.metricName(), t.unit(), t.description(), t.displayName(), MetricType.COUNTER, t.tags());
        registry.counter(metadata);
    }
    MetricResolver.Of<Metered> metered = resolver.metered(bean, element);
    if (metered.isPresent()) {
        Metered t = metered.metricAnnotation();
        Metadata metadata = getMetadata(metered.metricName(), t.unit(), t.description(), t.displayName(), MetricType.METERED, t.tags());
        registry.meter(metadata);
    }
    MetricResolver.Of<Timed> timed = resolver.timed(bean, element);
    if (timed.isPresent()) {
        Timed t = timed.metricAnnotation();
        Metadata metadata = getMetadata(timed.metricName(), t.unit(), t.description(), t.displayName(), MetricType.TIMER, t.tags());
        registry.timer(metadata);
    }
}
Also used : Counted(org.eclipse.microprofile.metrics.annotation.Counted) Metered(org.eclipse.microprofile.metrics.annotation.Metered) Timed(org.eclipse.microprofile.metrics.annotation.Timed) Metadata(org.eclipse.microprofile.metrics.Metadata)

Example 65 with Metadata

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

the class JmxWorker method expandMultiValueEntries.

/**
 * We need to expand entries that are marked with the <b>multi</b> flag
 * into the actual MBeans. This is done by replacing a placeholder of <b>%s</b>
 * in the name and MBean name with the real Mbean key-value.
 *
 * @param entries List of entries
 */
void expandMultiValueEntries(List<ExtendedMetadata> entries) {
    List<ExtendedMetadata> result = new ArrayList<>();
    List<Metadata> toBeRemoved = new ArrayList<>(entries.size());
    MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();
    for (ExtendedMetadata entry : entries) {
        if (entry.isMulti()) {
            String name = entry.getMbean().replace(PLACEHOLDER, "*");
            String attName;
            String queryableName;
            int slashIndex = name.indexOf('/');
            // MBeanName is invalid, lets skip this altogether
            if (slashIndex < 0) {
                toBeRemoved.add(entry);
                continue;
            }
            queryableName = name.substring(0, slashIndex);
            attName = name.substring(slashIndex + 1);
            try {
                ObjectName objectName = new ObjectName(queryableName);
                String keyHolder = findKeyForValueToBeReplaced(objectName);
                Set<ObjectName> objNames = mbs.queryNames(objectName, null);
                for (ObjectName oName : objNames) {
                    String keyValue = oName.getKeyPropertyList().get(keyHolder);
                    String newName = entry.getName();
                    if (!newName.contains(PLACEHOLDER)) {
                        LOG.warn("Name [" + newName + "] did not contain a %s, no replacement will be done, check" + " the configuration");
                    }
                    newName = newName.replace(PLACEHOLDER, keyValue);
                    String newDisplayName = entry.getDisplayName().replace(PLACEHOLDER, keyValue);
                    String newDescription = entry.getDescription().replace(PLACEHOLDER, keyValue);
                    ExtendedMetadata newEntry = new ExtendedMetadata(newName, newDisplayName, newDescription, entry.getTypeRaw(), entry.getUnit());
                    String newObjectName = oName.getCanonicalName() + "/" + attName;
                    newEntry.setMbean(newObjectName);
                    result.add(newEntry);
                }
                toBeRemoved.add(entry);
            } catch (MalformedObjectNameException e) {
                // TODO: Customise this generated block
                e.printStackTrace();
            }
        }
    }
    entries.removeAll(toBeRemoved);
    entries.addAll(result);
    LOG.info("Converted [" + toBeRemoved.size() + "] config entries and added [" + result.size() + "] replacements");
}
Also used : MalformedObjectNameException(javax.management.MalformedObjectNameException) ArrayList(java.util.ArrayList) Metadata(org.eclipse.microprofile.metrics.Metadata) MBeanServer(javax.management.MBeanServer) ObjectName(javax.management.ObjectName)

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