Search in sources :

Example 1 with MeterImpl

use of org.wildfly.swarm.microprofile.metrics.runtime.app.MeterImpl in project wildfly-swarm by wildfly-swarm.

the class JsonExporter method writeMetricsForMap.

private void writeMetricsForMap(StringBuilder sb, Map<String, Metric> metricMap, Map<String, Metadata> metadataMap) {
    for (Iterator<Map.Entry<String, Metric>> iterator = metricMap.entrySet().iterator(); iterator.hasNext(); ) {
        Map.Entry<String, Metric> entry = iterator.next();
        String key = entry.getKey();
        Metric value = entry.getValue();
        Metadata metadata = metadataMap.get(key);
        if (metadata == null) {
            throw new IllegalArgumentException("MD is null for " + key);
        }
        switch(metadata.getTypeRaw()) {
            case GAUGE:
            case COUNTER:
                Number val = getValueFromMetric(value, key);
                sb.append("  ").append('"').append(key).append('"').append(" : ").append(val);
                break;
            case METERED:
                MeterImpl meter = (MeterImpl) value;
                writeStartLine(sb, key);
                writeMeterValues(sb, meter);
                writeEndLine(sb);
                break;
            case TIMER:
                TimerImpl timer = (TimerImpl) value;
                writeStartLine(sb, key);
                writeTimerValues(sb, timer, metadata.getUnit());
                writeEndLine(sb);
                break;
            case HISTOGRAM:
                HistogramImpl hist = (HistogramImpl) value;
                writeStartLine(sb, key);
                sb.append("    \"count\": ").append(hist.getCount()).append(COMMA_LF);
                writeSnapshotValues(sb, hist.getSnapshot());
                writeEndLine(sb);
                break;
            default:
                LOG.error("JSE, Not yet supported: " + metadata);
        }
        if (iterator.hasNext()) {
            sb.append(',');
        }
        sb.append(LF);
    }
}
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 2 with MeterImpl

use of org.wildfly.swarm.microprofile.metrics.runtime.app.MeterImpl 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 3 with MeterImpl

use of org.wildfly.swarm.microprofile.metrics.runtime.app.MeterImpl in project wildfly-swarm by wildfly-swarm.

the class MetricsRegistryImpl method get.

private <T extends Metric> T get(Metadata metadata, MetricType type) {
    String name = metadata.getName();
    LOGGER.debugf("Get metric [name: %s, type: %s]", name, type);
    if (name == null || name.isEmpty()) {
        throw new IllegalArgumentException("Name must not be null or empty");
    }
    if (!metadataMap.containsKey(name)) {
        Metric m;
        switch(type) {
            case COUNTER:
                m = new CounterImpl();
                break;
            case GAUGE:
                throw new IllegalArgumentException("Gauge " + name + " was not registered, this should not happen");
            case METERED:
                m = new MeterImpl();
                break;
            case HISTOGRAM:
                m = new HistogramImpl(new ExponentiallyDecayingReservoir());
                break;
            case TIMER:
                m = new TimerImpl(new ExponentiallyDecayingReservoir());
                break;
            case INVALID:
            default:
                throw new IllegalStateException("Must not happen");
        }
        LOGGER.infof("Register metric [name: %s, type: %s]", name, type);
        register(metadata, m);
    } else if (!metadataMap.get(name).getTypeRaw().equals(metadata.getTypeRaw())) {
        throw new IllegalArgumentException("Type of existing previously registered metric " + name + " does not " + "match passed type");
    }
    return (T) metricMap.get(name);
}
Also used : ExponentiallyDecayingReservoir(org.wildfly.swarm.microprofile.metrics.runtime.app.ExponentiallyDecayingReservoir) MeterImpl(org.wildfly.swarm.microprofile.metrics.runtime.app.MeterImpl) Metric(org.eclipse.microprofile.metrics.Metric) HistogramImpl(org.wildfly.swarm.microprofile.metrics.runtime.app.HistogramImpl) CounterImpl(org.wildfly.swarm.microprofile.metrics.runtime.app.CounterImpl) TimerImpl(org.wildfly.swarm.microprofile.metrics.runtime.app.TimerImpl)

Aggregations

Metric (org.eclipse.microprofile.metrics.Metric)3 HistogramImpl (org.wildfly.swarm.microprofile.metrics.runtime.app.HistogramImpl)3 MeterImpl (org.wildfly.swarm.microprofile.metrics.runtime.app.MeterImpl)3 TimerImpl (org.wildfly.swarm.microprofile.metrics.runtime.app.TimerImpl)3 HashMap (java.util.HashMap)2 Map (java.util.Map)2 Metadata (org.eclipse.microprofile.metrics.Metadata)2 CounterImpl (org.wildfly.swarm.microprofile.metrics.runtime.app.CounterImpl)1 ExponentiallyDecayingReservoir (org.wildfly.swarm.microprofile.metrics.runtime.app.ExponentiallyDecayingReservoir)1