use of org.eclipse.microprofile.metrics.Metadata in project wildfly-swarm by wildfly-swarm.
the class JsonExporter method getMetricsForAScope.
private void getMetricsForAScope(StringBuilder sb, MetricRegistry.Type scope) {
MetricRegistry registry = MetricRegistryFactory.get(scope);
Map<String, Metric> metricMap = registry.getMetrics();
Map<String, Metadata> metadataMap = registry.getMetadata();
sb.append("{\n");
writeMetricsForMap(sb, metricMap, metadataMap);
sb.append("}");
}
use of org.eclipse.microprofile.metrics.Metadata 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);
}
}
}
use of org.eclipse.microprofile.metrics.Metadata in project wildfly-swarm by wildfly-swarm.
the class AMetricRegistryFactory method getMetadata.
private Metadata getMetadata(InjectionPoint ip, MetricType type) {
Metadata metadata = new Metadata(metricName.of(ip), type);
Metric metric = ip.getAnnotated().getAnnotation(Metric.class);
if (metric != null) {
if (!metric.unit().isEmpty()) {
metadata.setUnit(metric.unit());
}
if (!metric.description().isEmpty()) {
metadata.setDescription(metric.description());
}
if (!metric.displayName().isEmpty()) {
metadata.setDisplayName(metric.displayName());
}
if (metric.tags().length > 0) {
for (String tag : metric.tags()) {
metadata.addTags(tag);
}
}
}
return metadata;
}
use of org.eclipse.microprofile.metrics.Metadata in project wildfly-swarm by wildfly-swarm.
the class MetricsInterceptor method registerMetrics.
private <E extends Member & AnnotatedElement> void registerMetrics(Class<?> bean, E element) {
MetricResolver.Of<Counted> counted = resolver.counted(bean, element);
if (counted.isPresent()) {
Counted t = counted.metricAnnotation();
Metadata metadata = getMetadata(counted.metricName(), t.unit(), t.description(), t.displayName(), MetricType.COUNTER, t.tags());
registry.counter(metadata);
}
MetricResolver.Of<Metered> metered = resolver.metered(bean, element);
if (metered.isPresent()) {
Metered t = metered.metricAnnotation();
Metadata metadata = getMetadata(metered.metricName(), t.unit(), t.description(), t.displayName(), MetricType.METERED, t.tags());
registry.meter(metadata);
}
MetricResolver.Of<Timed> timed = resolver.timed(bean, element);
if (timed.isPresent()) {
Timed t = timed.metricAnnotation();
Metadata metadata = getMetadata(timed.metricName(), t.unit(), t.description(), t.displayName(), MetricType.TIMER, t.tags());
registry.timer(metadata);
}
}
use of org.eclipse.microprofile.metrics.Metadata in project wildfly-swarm by wildfly-swarm.
the class JmxWorker method expandMultiValueEntries.
/**
* We need to expand entries that are marked with the <b>multi</b> flag
* into the actual MBeans. This is done by replacing a placeholder of <b>%s</b>
* in the name and MBean name with the real Mbean key-value.
*
* @param entries List of entries
*/
void expandMultiValueEntries(List<ExtendedMetadata> entries) {
List<ExtendedMetadata> result = new ArrayList<>();
List<Metadata> toBeRemoved = new ArrayList<>(entries.size());
MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();
for (ExtendedMetadata entry : entries) {
if (entry.isMulti()) {
String name = entry.getMbean().replace(PLACEHOLDER, "*");
String attName;
String queryableName;
int slashIndex = name.indexOf('/');
// MBeanName is invalid, lets skip this altogether
if (slashIndex < 0) {
toBeRemoved.add(entry);
continue;
}
queryableName = name.substring(0, slashIndex);
attName = name.substring(slashIndex + 1);
try {
ObjectName objectName = new ObjectName(queryableName);
String keyHolder = findKeyForValueToBeReplaced(objectName);
Set<ObjectName> objNames = mbs.queryNames(objectName, null);
for (ObjectName oName : objNames) {
String keyValue = oName.getKeyPropertyList().get(keyHolder);
String newName = entry.getName();
if (!newName.contains(PLACEHOLDER)) {
LOG.warn("Name [" + newName + "] did not contain a %s, no replacement will be done, check" + " the configuration");
}
newName = newName.replace(PLACEHOLDER, keyValue);
String newDisplayName = entry.getDisplayName().replace(PLACEHOLDER, keyValue);
String newDescription = entry.getDescription().replace(PLACEHOLDER, keyValue);
ExtendedMetadata newEntry = new ExtendedMetadata(newName, newDisplayName, newDescription, entry.getTypeRaw(), entry.getUnit());
String newObjectName = oName.getCanonicalName() + "/" + attName;
newEntry.setMbean(newObjectName);
result.add(newEntry);
}
toBeRemoved.add(entry);
} catch (MalformedObjectNameException e) {
// TODO: Customise this generated block
e.printStackTrace();
}
}
}
entries.removeAll(toBeRemoved);
entries.addAll(result);
LOG.info("Converted [" + toBeRemoved.size() + "] config entries and added [" + result.size() + "] replacements");
}
Aggregations