From eca6451832aa66da130a21f86b1a990b3c39f1e6 Mon Sep 17 00:00:00 2001 From: Amnon Heiman Date: Tue, 17 May 2016 11:08:05 +0300 Subject: [PATCH] APIHistogram: Support APITimer With the move to APITimer, in many occasion a histogram will not update itself, instead it will be updated by the APITimer. This breaks the update values functionality so that a histogram that is included in an APITimer will not try to update it self. Signed-off-by: Amnon Heiman --- .../com/yammer/metrics/core/APIHistogram.java | 30 ++++++++++++++----- 1 file changed, 22 insertions(+), 8 deletions(-) diff --git a/src/main/java/com/yammer/metrics/core/APIHistogram.java b/src/main/java/com/yammer/metrics/core/APIHistogram.java index 985950a..ca9e27d 100644 --- a/src/main/java/com/yammer/metrics/core/APIHistogram.java +++ b/src/main/java/com/yammer/metrics/core/APIHistogram.java @@ -10,6 +10,8 @@ import java.lang.reflect.Field; import java.util.concurrent.atomic.AtomicLong; import java.util.concurrent.atomic.AtomicReference; +import javax.json.JsonObject; + import com.scylladb.jmx.api.APIClient; import com.yammer.metrics.stats.Sample; import com.yammer.metrics.stats.Snapshot; @@ -101,14 +103,7 @@ public class APIHistogram extends Histogram { this(url, type, UPDATE_INTERVAL); } - public void update() { - long now = System.currentTimeMillis(); - if (now - last_update < UPDATE_INTERVAL) { - return; - } - last_update = now; - clear(); - HistogramValues vals = c.getHistogramValue(url); + public void updateValue(HistogramValues vals) { try { if (vals.sample != null) { for (long v : vals.sample) { @@ -128,6 +123,25 @@ public class APIHistogram extends Histogram { } } + public void update() { + if (url == null) { + return; + } + long now = System.currentTimeMillis(); + if (now - last_update < UPDATE_INTERVAL) { + return; + } + last_update = now; + clear(); + JsonObject obj = c.getJsonObj(url, null); + if (obj.containsKey("hist")) { + updateValue(APIClient.json2histogram(obj.getJsonObject("hist"))); + } else { + updateValue(APIClient.json2histogram(obj)); + } + + } + /** * Returns the number of values recorded. *