From 3cee0a1ba3a7731ed417dac67e9edd69ecf96a3a Mon Sep 17 00:00:00 2001 From: RuscalWorld Date: Tue, 7 Sep 2021 22:21:56 +0300 Subject: [PATCH] Fix changing MSPT gauge value without label (#1) --- .../fabricexporter/metrics/MillisPerTick.java | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/src/main/java/ru/ruscalworld/fabricexporter/metrics/MillisPerTick.java b/src/main/java/ru/ruscalworld/fabricexporter/metrics/MillisPerTick.java index 252877f..67bd397 100644 --- a/src/main/java/ru/ruscalworld/fabricexporter/metrics/MillisPerTick.java +++ b/src/main/java/ru/ruscalworld/fabricexporter/metrics/MillisPerTick.java @@ -13,11 +13,17 @@ public class MillisPerTick extends SparkMetric { @Override public void update(FabricExporter exporter) { GenericStatistic mspt = this.getSpark().mspt(); - if (mspt == null) this.getGauge().set(0); - else { - this.getGauge().labels("min").set(mspt.poll(StatisticWindow.MillisPerTick.MINUTES_1).min()); - this.getGauge().labels("mean").set(mspt.poll(StatisticWindow.MillisPerTick.MINUTES_1).mean()); - this.getGauge().labels("max").set(mspt.poll(StatisticWindow.MillisPerTick.MINUTES_1).max()); - } + if (mspt == null) this.setValue(0, 0, 0); + else this.setValue( + mspt.poll(StatisticWindow.MillisPerTick.MINUTES_1).min(), + mspt.poll(StatisticWindow.MillisPerTick.MINUTES_1).mean(), + mspt.poll(StatisticWindow.MillisPerTick.MINUTES_1).max() + ); + } + + private void setValue(double min, double mean, double max) { + this.getGauge().labels("min").set(min); + this.getGauge().labels("mean").set(mean); + this.getGauge().labels("max").set(max); } }