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