use of org.eclipse.microprofile.metrics.MetricRegistry in project Payara by payara.
the class MetricsService method getOrAddRegistry.
/**
* Returns the Metrics registry based on respective registry name,
* if not available then add the new MetricRegistry instance
*
* @param registryName
* @return
*/
public MetricRegistry getOrAddRegistry(String registryName) {
MetricRegistry registry = REGISTRIES.get(registryName.toLowerCase());
if (registry == null) {
registry = new MetricRegistryImpl();
final MetricRegistry raced = REGISTRIES.putIfAbsent(registryName.toLowerCase(), registry);
if (raced != null) {
registry = raced;
}
}
return registry;
}
use of org.eclipse.microprofile.metrics.MetricRegistry in project Payara by payara.
the class MetricsService method getMetadataAsMap.
public Map<String, Metadata> getMetadataAsMap(String registryName, String metricName) throws NoSuchRegistryException, NoSuchMetricException {
MetricRegistry registry = getRegistry(registryName);
Map<String, Metadata> metricMetadataMap = registry.getMetadata();
if (metricMetadataMap.containsKey(metricName)) {
return singletonMap(metricName, metricMetadataMap.get(metricName));
} else {
throw new NoSuchMetricException(metricName);
}
}
use of org.eclipse.microprofile.metrics.MetricRegistry 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.MetricRegistry in project wildfly-swarm by wildfly-swarm.
the class Helper method countNonEmptyScopes.
static int countNonEmptyScopes() {
MetricRegistry.Type[] values = MetricRegistry.Type.values();
int totalNonEmptyScopes = 0;
for (MetricRegistry.Type scope : values) {
MetricRegistry registry = MetricRegistryFactory.get(scope);
if (registry.getNames().size() > 0) {
totalNonEmptyScopes++;
}
}
return totalNonEmptyScopes;
}
use of org.eclipse.microprofile.metrics.MetricRegistry 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("}");
}
Aggregations