Search in sources :

Example 1 with Counting

use of org.eclipse.microprofile.metrics.Counting in project Payara by payara.

the class MetricsServiceImpl method collectRegistry.

private static void collectRegistry(String contextName, MetricRegistry registry, MonitoringDataCollector collector) {
    // OBS: this way of iterating the metrics in the registry is optimal because of its internal data organisation
    for (String name : registry.getNames()) {
        for (Entry<MetricID, Metric> entry : ((MetricRegistryImpl) registry).getMetrics(name).entrySet()) {
            MetricID metricID = entry.getKey();
            Metric metric = entry.getValue();
            try {
                MonitoringDataCollector metricCollector = tagCollector(contextName, metricID, collector);
                if (metric instanceof Counting) {
                    metricCollector.collect(toName(metricID, "Count"), ((Counting) metric).getCount());
                }
                if (metric instanceof SimpleTimer) {
                    metricCollector.collect(toName(metricID, "Duration"), ((SimpleTimer) metric).getElapsedTime().toMillis());
                }
                if (metric instanceof Timer) {
                    metricCollector.collect(toName(metricID, "MaxDuration"), ((Timer) metric).getSnapshot().getMax());
                }
                if (metric instanceof Gauge) {
                    Object value = ((Gauge<?>) metric).getValue();
                    if (value instanceof Number) {
                        metricCollector.collect(toName(metricID, getMetricUnitSuffix(registry.getMetadata(name).unit())), ((Number) value));
                    }
                }
            } catch (Exception ex) {
                LOGGER.log(Level.SEVERE, "Failed to retrieve metric: " + metricID);
                ;
            }
        }
    }
}
Also used : MonitoringDataCollector(fish.payara.monitoring.collect.MonitoringDataCollector) MetricID(org.eclipse.microprofile.metrics.MetricID) SimpleTimer(org.eclipse.microprofile.metrics.SimpleTimer) Timer(org.eclipse.microprofile.metrics.Timer) SimpleTimer(org.eclipse.microprofile.metrics.SimpleTimer) Metric(org.eclipse.microprofile.metrics.Metric) Counting(org.eclipse.microprofile.metrics.Counting) FileNotFoundException(java.io.FileNotFoundException) NoSuchRegistryException(fish.payara.microprofile.metrics.exception.NoSuchRegistryException) Gauge(org.eclipse.microprofile.metrics.Gauge)

Aggregations

NoSuchRegistryException (fish.payara.microprofile.metrics.exception.NoSuchRegistryException)1 MonitoringDataCollector (fish.payara.monitoring.collect.MonitoringDataCollector)1 FileNotFoundException (java.io.FileNotFoundException)1 Counting (org.eclipse.microprofile.metrics.Counting)1 Gauge (org.eclipse.microprofile.metrics.Gauge)1 Metric (org.eclipse.microprofile.metrics.Metric)1 MetricID (org.eclipse.microprofile.metrics.MetricID)1 SimpleTimer (org.eclipse.microprofile.metrics.SimpleTimer)1 Timer (org.eclipse.microprofile.metrics.Timer)1