use of org.eclipse.microprofile.metrics.Metadata in project Payara by payara.
the class MetricCDIExtension method registerCustomMetrics.
private void registerCustomMetrics(@Observes AfterDeploymentValidation adv, BeanManager manager) {
MetricsService metricsService = Globals.getDefaultBaseServiceLocator().getService(MetricsService.class);
MetricRegistry registry = metricsService.getOrAddRegistry(metricsService.getApplicationName());
MetricsHelper helper = getReference(manager, MetricsHelper.class);
for (Map.Entry<Producer<?>, AnnotatedMember<?>> entry : metrics.entrySet()) {
AnnotatedMember<?> annotatedMember = entry.getValue();
Producer<?> prod = entry.getKey();
if (hasInjectionPoints(annotatedMember)) {
continue;
}
Metadata metadata = helper.metadataOf(annotatedMember);
registry.register(metadata.getName(), (Metric) prod.produce(manager.createCreationalContext(null)), metadata);
}
metrics.clear();
}
use of org.eclipse.microprofile.metrics.Metadata in project Payara by payara.
the class MBeanMetadataHelper method resolveDynamicMetadata.
/**
* Resolve dynamic metadata by replacing specifier <b>%s</b> with the mbean value.
*
* @param metadataList list of MBean Metadata
*/
public void resolveDynamicMetadata(List<MBeanMetadata> metadataList) {
List<MBeanMetadata> resolvedMetadataList = new ArrayList<>();
List<Metadata> removedMetadataList = new ArrayList<>(metadataList.size());
for (MBeanMetadata metadata : metadataList) {
if (metadata.getName().contains(SPECIFIER)) {
MBeanExpression mBeanExpression;
try {
mBeanExpression = new MBeanExpression(metadata.getMBean().replace(SPECIFIER, "*"));
String dynamicKey = mBeanExpression.findDynamicKey();
for (ObjectName objName : mBeanExpression.queryNames(null)) {
String dynamicValue = objName.getKeyPropertyList().get(dynamicKey);
resolvedMetadataList.add(new MBeanMetadata(objName.getCanonicalName() + "/" + mBeanExpression.getAttributeName(), metadata.getName().replace(SPECIFIER, dynamicValue), metadata.getDisplayName().replace(SPECIFIER, dynamicValue), metadata.getDescription().replace(SPECIFIER, dynamicValue), metadata.getTypeRaw(), metadata.getUnit()));
}
} catch (IllegalArgumentException ex) {
LOGGER.log(Level.SEVERE, ex, () -> metadata.getMBean() + " is invalid");
} finally {
removedMetadataList.add(metadata);
}
}
}
metadataList.removeAll(removedMetadataList);
metadataList.addAll(resolvedMetadataList);
}
use of org.eclipse.microprofile.metrics.Metadata in project Payara by payara.
the class PrometheusWriter method writeMetricMap.
private void writeMetricMap(StringBuilder builder, String registryName, Map<String, Metric> metricMap, Map<String, Metadata> metricMetadataMap) {
for (Entry<String, Metric> entry : metricMap.entrySet()) {
String metricName = entry.getKey();
// Scope and name are separated by colon (:)
if (!BASE.getName().equals(registryName) && !VENDOR.getName().equals(registryName)) {
registryName = APPLICATION.getName();
}
String name = registryName + ":" + metricName;
Metric metric = entry.getValue();
Metadata metricMetadata = metricMetadataMap.get(metricName);
String description = metricMetadata.getDescription() == null || metricMetadata.getDescription().trim().isEmpty() ? EMPTY_STRING : metricMetadata.getDescription();
String tags = metricMetadata.getTagsAsString();
String unit = metricMetadata.getUnit();
PrometheusExporter exporter = new PrometheusExporter(builder);
if (Counter.class.isInstance(metric)) {
exporter.exportCounter((Counter) metric, name, description, tags);
} else if (Gauge.class.isInstance(metric)) {
exporter.exportGauge((Gauge) metric, name, description, tags, unit);
} else if (Histogram.class.isInstance(metric)) {
exporter.exportHistogram((Histogram) metric, name, description, tags, unit);
} else if (Meter.class.isInstance(metric)) {
exporter.exportMeter((Meter) metric, name, description, tags);
} else if (Timer.class.isInstance(metric)) {
exporter.exportTimer((Timer) metric, name, description, tags, unit);
} else {
LOGGER.log(Level.WARNING, "Metric type {0} for {1} is invalid", new Object[] { metric.getClass(), metricName });
}
}
}
Aggregations