From 4b367372a64c039a1de0182070e689514d880eb9 Mon Sep 17 00:00:00 2001 From: Amnon Heiman Date: Wed, 15 Mar 2017 15:07:25 +0200 Subject: [PATCH] MetricsRegistry: Solving empty histograms in nodetool This patch fixes two issues with the histogram implementation: * Need to all update before trying to read values from the histogram. * The histogram values return from the API in microseconds and not nano. See Scylladb/scylla#2155 Signed-off-by: Amnon Heiman Message-Id: <20170315130725.22261-1-amnon@scylladb.com> (cherry picked from commit 0c541d73e7d7a70797b0a3f31c9c3bc69c9b4587) --- .../cassandra/metrics/MetricsRegistry.java | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/src/main/java/org/apache/cassandra/metrics/MetricsRegistry.java b/src/main/java/org/apache/cassandra/metrics/MetricsRegistry.java index f23ef66..eee2c30 100644 --- a/src/main/java/org/apache/cassandra/metrics/MetricsRegistry.java +++ b/src/main/java/org/apache/cassandra/metrics/MetricsRegistry.java @@ -196,11 +196,11 @@ public class MetricsRegistry { private static final TimeUnit RATE_UNIT = TimeUnit.SECONDS; private static final TimeUnit DURATION_UNIT = TimeUnit.MICROSECONDS; - private static final TimeUnit API_DURATION_UNIT = TimeUnit.NANOSECONDS; + private static final TimeUnit API_DURATION_UNIT = TimeUnit.MICROSECONDS; private static final double DURATION_FACTOR = 1.0 / API_DURATION_UNIT.convert(1, DURATION_UNIT); - private static double toDuration(double nanos) { - return nanos * DURATION_FACTOR; + private static double toDuration(double micro) { + return micro * DURATION_FACTOR; } private static String unitString(TimeUnit u) { @@ -650,61 +650,73 @@ public class MetricsRegistry { @Override public double getMin() { + update(); return toDuration(histogram.getMin()); } @Override public double getMax() { + update(); return toDuration(histogram.getMax()); } @Override public double getMean() { + update(); return toDuration(histogram.getMean()); } @Override public double getStdDev() { + update(); return toDuration(histogram.getStdDev()); } @Override public double get50thPercentile() { + update(); return toDuration(histogram.getValue(.5)); } @Override public double get75thPercentile() { + update(); return toDuration(histogram.getValue(.75)); } @Override public double get95thPercentile() { + update(); return toDuration(histogram.getValue(.95)); } @Override public double get98thPercentile() { + update(); return toDuration(histogram.getValue(.98)); } @Override public double get99thPercentile() { + update(); return toDuration(histogram.getValue(.99)); } @Override public double get999thPercentile() { + update(); return toDuration(histogram.getValue(.999)); } @Override public long[] values() { + update(); return histogram.getValues(); } @Override public String getDurationUnit() { + update(); return DURATION_UNIT.toString().toLowerCase(Locale.US); } }