diff --git a/hugegraph-store/hg-store-node/src/main/java/org/apache/hugegraph/store/node/metrics/JRaftMetrics.java b/hugegraph-store/hg-store-node/src/main/java/org/apache/hugegraph/store/node/metrics/JRaftMetrics.java index 098372bee6..d5ca11b3f5 100644 --- a/hugegraph-store/hg-store-node/src/main/java/org/apache/hugegraph/store/node/metrics/JRaftMetrics.java +++ b/hugegraph-store/hg-store-node/src/main/java/org/apache/hugegraph/store/node/metrics/JRaftMetrics.java @@ -127,10 +127,6 @@ private static void registerNodeMetrics() { } - private static HistogramWrapper toWrapper(com.codahale.metrics.Histogram histogram) { - return new HistogramWrapper(histogram); - } - private static String refineMetrics(String name, List tags) { if (name == null || name.isEmpty()) { return name; @@ -172,35 +168,33 @@ private static void registerHistogram(String group, String name, String baseName = PREFIX + "." + name.toLowerCase(); - HistogramWrapper wrapper = toWrapper(histogram); - - Gauge.builder(baseName + ".median", wrapper, (d) -> d.getSnapshot().getMedian()) + Gauge.builder(baseName + ".median", histogram, h -> h.getSnapshot().getMedian()) .tags(tags).register(registry); - Gauge.builder(baseName + ".min", wrapper, (d) -> d.getSnapshot().getMin()) + Gauge.builder(baseName + ".min", histogram, h -> h.getSnapshot().getMin()) .tags(tags).register(registry); - Gauge.builder(baseName + ".max", wrapper, (d) -> d.getSnapshot().getMax()) + Gauge.builder(baseName + ".max", histogram, h -> h.getSnapshot().getMax()) .tags(tags).register(registry); - Gauge.builder(baseName + ".mean", wrapper, (d) -> d.getSnapshot().getMean()) + Gauge.builder(baseName + ".mean", histogram, h -> h.getSnapshot().getMean()) .tags(tags).register(registry); baseName = baseName + ".summary"; - Gauge.builder(baseName, wrapper, (d) -> d.getSnapshot().getMedian()) + Gauge.builder(baseName, histogram, h -> h.getSnapshot().getMedian()) .tags(tags).tag(LABELS, LABEL_50).register(registry); - Gauge.builder(baseName, wrapper, (d) -> d.getSnapshot().get75thPercentile()) + Gauge.builder(baseName, histogram, h -> h.getSnapshot().get75thPercentile()) .tags(tags).tag(LABELS, LABEL_75).register(registry); - Gauge.builder(baseName, wrapper, (d) -> d.getSnapshot().get95thPercentile()) + Gauge.builder(baseName, histogram, h -> h.getSnapshot().get95thPercentile()) .tags(tags).tag(LABELS, LABEL_95).register(registry); - Gauge.builder(baseName, wrapper, (d) -> d.getSnapshot().get98thPercentile()) + Gauge.builder(baseName, histogram, h -> h.getSnapshot().get98thPercentile()) .tags(tags).tag(LABELS, LABEL_98).register(registry); - Gauge.builder(baseName, wrapper, (d) -> d.getSnapshot().get99thPercentile()) + Gauge.builder(baseName, histogram, h -> h.getSnapshot().get99thPercentile()) .tags(tags).tag(LABELS, LABEL_99).register(registry); - Gauge.builder(baseName, wrapper, (d) -> d.getSnapshot().get999thPercentile()) + Gauge.builder(baseName, histogram, h -> h.getSnapshot().get999thPercentile()) .tags(tags).tag(LABELS, LABEL_999).register(registry); - Gauge.builder(baseName + ".sum", wrapper, - (d) -> Arrays.stream(d.getSnapshot().getValues()).sum()) + Gauge.builder(baseName + ".sum", histogram, + h -> Arrays.stream(h.getSnapshot().getValues()).sum()) .tags(tags).register(registry); - Gauge.builder(baseName + ".count", wrapper, (d) -> d.getSnapshot().size()) + Gauge.builder(baseName + ".count", histogram, h -> h.getSnapshot().size()) .tags(tags).register(registry); } @@ -214,7 +208,7 @@ private static void registerTimer(String group, String name, com.codahale.metric String baseName = PREFIX + "." + name.toLowerCase(); - Gauge.builder(baseName + ".count", timer, t->t.getCount()) + Gauge.builder(baseName + ".count", timer, t -> t.getCount()) .tags(tags).register(registry); Gauge.builder(baseName + ".min", timer, t -> t.getSnapshot().getMin()) .tags(tags).register(registry); @@ -309,26 +303,4 @@ private static void registerGauge(String group, String name, } } - - private static class HistogramWrapper { - - private final com.codahale.metrics.Histogram histogram; - - private Snapshot snapshot; - private long ts = System.currentTimeMillis(); - - HistogramWrapper(com.codahale.metrics.Histogram histogram) { - this.histogram = histogram; - this.snapshot = this.histogram.getSnapshot(); - } - - Snapshot getSnapshot() { - if (System.currentTimeMillis() - this.ts > 30_000) { - this.snapshot = this.histogram.getSnapshot(); - this.ts = System.currentTimeMillis(); - } - return this.snapshot; - } - } - }