Search in sources :

Example 1 with Sampling

use of com.codahale.metrics.Sampling in project spring-boot by spring-projects.

the class MetricRegistryMetricReader method findOne.

@Override
public Metric<?> findOne(String metricName) {
    String name = this.names.get(metricName);
    if (name == null) {
        return null;
    }
    com.codahale.metrics.Metric metric = this.registry.getMetrics().get(name);
    if (metric == null) {
        return null;
    }
    if (metric instanceof Counter) {
        Counter counter = (Counter) metric;
        return new Metric<Number>(metricName, counter.getCount());
    }
    if (metric instanceof Gauge) {
        Object value = ((Gauge<?>) metric).getValue();
        if (value instanceof Number) {
            return new Metric<>(metricName, (Number) value);
        }
        if (logger.isDebugEnabled()) {
            logger.debug("Ignoring gauge '" + name + "' (" + metric + ") as its value is not a Number");
        }
        return null;
    }
    if (metric instanceof Sampling) {
        if (metricName.contains(".snapshot.")) {
            Number value = getMetric(((Sampling) metric).getSnapshot(), metricName);
            if (metric instanceof Timer) {
                // convert back to MILLISEC
                value = TimeUnit.MILLISECONDS.convert(value.longValue(), TimeUnit.NANOSECONDS);
            }
            return new Metric<>(metricName, value);
        }
    }
    return new Metric<>(metricName, getMetric(metric, metricName));
}
Also used : Counter(com.codahale.metrics.Counter) Timer(com.codahale.metrics.Timer) Metric(org.springframework.boot.actuate.metrics.Metric) Sampling(com.codahale.metrics.Sampling) Gauge(com.codahale.metrics.Gauge)

Aggregations

Counter (com.codahale.metrics.Counter)1 Gauge (com.codahale.metrics.Gauge)1 Sampling (com.codahale.metrics.Sampling)1 Timer (com.codahale.metrics.Timer)1 Metric (org.springframework.boot.actuate.metrics.Metric)1