Search in sources :

Example 1 with ExtendedMetadata

use of io.smallrye.metrics.ExtendedMetadata 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)

Aggregations

ExtendedMetadata (io.smallrye.metrics.ExtendedMetadata)1 OptionalDouble (java.util.OptionalDouble)1 Counter (org.eclipse.microprofile.metrics.Counter)1 Metadata (org.eclipse.microprofile.metrics.Metadata)1 Metric (org.eclipse.microprofile.metrics.Metric)1 Tag (org.eclipse.microprofile.metrics.Tag)1 MetricMetadata (org.wildfly.extension.metrics.MetricMetadata)1 WildFlyMetricMetadata (org.wildfly.extension.metrics.WildFlyMetricMetadata)1