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));
}