Search in sources :

Example 31 with Metadata

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

the class JsonMetadataExporter method writeMetadataForMap.

private void writeMetadataForMap(StringBuilder sb, Map<String, Metadata> theMetadata) {
    Iterator<Map.Entry<String, Metadata>> iter = theMetadata.entrySet().iterator();
    while (iter.hasNext()) {
        Metadata entry = iter.next().getValue();
        sb.append('"').append(entry.getName()).append('"').append(": {\n");
        sb.append("  \"unit\": \"").append(entry.getUnit()).append(QUOTE_COMMA_LF);
        sb.append("  \"type\": \"").append(entry.getType()).append(QUOTE_COMMA_LF);
        if (entry.getDescription() != null) {
            sb.append("  \"description\": \"").append(entry.getDescription()).append(QUOTE_COMMA_LF);
        }
        if (!entry.getTags().isEmpty()) {
            sb.append("  \"tags\": \"");
            sb.append(getTagsAsString(entry.getTags()));
            sb.append(QUOTE_COMMA_LF);
        }
        sb.append("  \"displayName\": \"").append(entry.getDisplayName()).append("\"\n");
        if (iter.hasNext()) {
            sb.append("  },\n");
        } else {
            sb.append("  }\n");
        }
    }
}
Also used : Metadata(org.eclipse.microprofile.metrics.Metadata)

Example 32 with Metadata

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

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

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

the class MicroProfileVendorMetricRegistry method registerMetric.

@Override
public void registerMetric(org.wildfly.extension.metrics.Metric metric, MetricMetadata metadata) {
    final Metric mpMetric;
    if (metadata.getType() == COUNTER) {
        mpMetric = new Counter() {

            @Override
            public void inc() {
            }

            @Override
            public void inc(long n) {
            }

            @Override
            public long getCount() {
                OptionalDouble value = metric.getValue();
                if (!value.isPresent()) {
                    // RuntimeException, after logging at DEBUG. That's what we want.
                    throw LOGGER.metricUnavailable();
                }
                return (long) value.getAsDouble();
            }
        };
    } else {
        mpMetric = new Gauge<Number>() {

            @Override
            public Double getValue() {
                OptionalDouble value = metric.getValue();
                if (!value.isPresent()) {
                    // RuntimeException, after logging at DEBUG. That's what we want.
                    throw LOGGER.metricUnavailable();
                }
                return value.getAsDouble();
            }
        };
    }
    lock.writeLock().lock();
    try {
        synchronized (vendorRegistry) {
            // TODO does the writeLock eliminate the need for this synchronized?
            final Metadata mpMetadata;
            Metadata existingMetadata = vendorRegistry.getMetadata().get(metadata.getMetricName());
            if (existingMetadata != null) {
                mpMetadata = existingMetadata;
            } else {
                mpMetadata = new ExtendedMetadata(metadata.getMetricName(), metadata.getMetricName(), metadata.getDescription(), metadata.getType() == COUNTER ? MetricType.COUNTER : MetricType.GAUGE, metricUnit(metadata.getMeasurementUnit()), null, false, // so that the name of the metric does not change ("vendor_" will not be prepended to it).
                Optional.of(false));
            }
            Tag[] mpTags = toMicroProfileMetricsTags(metadata.getTags());
            vendorRegistry.register(mpMetadata, mpMetric, mpTags);
        }
    } finally {
        lock.writeLock().unlock();
    }
}
Also used : Counter(org.eclipse.microprofile.metrics.Counter) MetricMetadata(org.wildfly.extension.metrics.MetricMetadata) Metadata(org.eclipse.microprofile.metrics.Metadata) ExtendedMetadata(io.smallrye.metrics.ExtendedMetadata) WildFlyMetricMetadata(org.wildfly.extension.metrics.WildFlyMetricMetadata) Metric(org.eclipse.microprofile.metrics.Metric) ExtendedMetadata(io.smallrye.metrics.ExtendedMetadata) Tag(org.eclipse.microprofile.metrics.Tag) OptionalDouble(java.util.OptionalDouble) OptionalDouble(java.util.OptionalDouble)

Example 35 with Metadata

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

the class MicroProfileMetricsCounterResource method hello.

@GET
@Path("/hello")
public Response hello() {
    Metadata counterMetadata = Metadata.builder().withName("helloCounter").withType(MetricType.COUNTER).build();
    registry.counter(counterMetadata).inc();
    registry.counter("customCounter").inc();
    return Response.ok("Hello World!").build();
}
Also used : Metadata(org.eclipse.microprofile.metrics.Metadata) Path(javax.ws.rs.Path) GET(javax.ws.rs.GET)

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