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();
}
}
Aggregations