From 092e769dd84d2f3b051d35b4b64b8fd4f00ac788 Mon Sep 17 00:00:00 2001 From: Gian Merlino Date: Thu, 17 Nov 2022 23:03:16 -0800 Subject: [PATCH] JvmMonitor: Report jvm/gc/cpu in nanos. (#13383) Our documentation says we report this in nanos, and we actually did prior to #12481. This patch restores the prior behavior. --- .../org/apache/druid/java/util/metrics/JvmMonitor.java | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/core/src/main/java/org/apache/druid/java/util/metrics/JvmMonitor.java b/core/src/main/java/org/apache/druid/java/util/metrics/JvmMonitor.java index 7c9f6be99df..524a8dc87f0 100644 --- a/core/src/main/java/org/apache/druid/java/util/metrics/JvmMonitor.java +++ b/core/src/main/java/org/apache/druid/java/util/metrics/JvmMonitor.java @@ -187,7 +187,7 @@ public class JvmMonitor extends FeedDefiningMonitor private final GarbageCollectorMXBean gcBean; private long lastInvocations = 0; - private long lastCpuNanos = 0; + private long lastCpuMillis = 0; private static final String GC_YOUNG_GENERATION_NAME = "young"; private static final String GC_OLD_GENERATION_NAME = "old"; @@ -268,10 +268,10 @@ public class JvmMonitor extends FeedDefiningMonitor emitter.emit(builder.build("jvm/gc/count", newInvocations - lastInvocations)); lastInvocations = newInvocations; - long newCpuNanos = gcBean.getCollectionTime(); - emitter.emit(builder.build("jvm/gc/cpu", newCpuNanos - lastCpuNanos)); - lastCpuNanos = newCpuNanos; - + // getCollectionTime is in milliseconds; we report jvm/gc/cpu in nanoseconds. + long newCpuMillis = gcBean.getCollectionTime(); + emitter.emit(builder.build("jvm/gc/cpu", (newCpuMillis - lastCpuMillis) * 1_000_000L)); + lastCpuMillis = newCpuMillis; } }