gala-gopher/fix-modify-unit-of-some-metrics-to-second.patch
xietangxin 71cf797faf sync bugfix patch from openeuler/gala-gopher
(cherry picked from commit 4ea8a981b29acd853dd2d279d658055e0e6e79a1)
2023-04-10 10:53:07 +08:00

103 lines
4.3 KiB
Diff

From 9ad26e3d4abfb78e99b8d75da384e36badbde75a Mon Sep 17 00:00:00 2001
From: dowzyx <zhaoyuxing2@huawei.com>
Date: Thu, 16 Mar 2023 16:09:07 +0800
Subject: [PATCH 23/30] fix: modify unit of some metrics to second
---
.../extends/java.probe/jvm.probe/jvm_probe.meta | 14 +++++++-------
.../jvm.probe/src/agent/JvmProbeAgent.java | 13 +++++++------
2 files changed, 14 insertions(+), 13 deletions(-)
diff --git a/src/probes/extends/java.probe/jvm.probe/jvm_probe.meta b/src/probes/extends/java.probe/jvm.probe/jvm_probe.meta
index bb9d01a..d80341a 100755
--- a/src/probes/extends/java.probe/jvm.probe/jvm_probe.meta
+++ b/src/probes/extends/java.probe/jvm.probe/jvm_probe.meta
@@ -18,12 +18,12 @@ measurements:
name: "runtime",
},
{
- description: "....",
+ description: "JVM implementation vender.",
type: "label",
name: "vendor",
},
{
- description: "....",
+ description: "the JVM implementation version.",
type: "label",
name: "version",
},
@@ -163,7 +163,7 @@ measurements:
name: "tgid",
},
{
- description: "....",
+ description: "name representing a memory pool.",
type: "key",
name: "pool",
},
@@ -210,8 +210,8 @@ measurements:
name: "tgid",
},
{
- description: "....",
- type: "label",
+ description: "name representing a buffer pool.",
+ type: "key",
name: "pool",
},
{
@@ -242,8 +242,8 @@ measurements:
name: "tgid",
},
{
- description: "....",
- type: "label",
+ description: "name representing a GC.",
+ type: "key",
name: "gc",
},
{
diff --git a/src/probes/extends/java.probe/jvm.probe/src/agent/JvmProbeAgent.java b/src/probes/extends/java.probe/jvm.probe/src/agent/JvmProbeAgent.java
index 488c73c..d7f635d 100644
--- a/src/probes/extends/java.probe/jvm.probe/src/agent/JvmProbeAgent.java
+++ b/src/probes/extends/java.probe/jvm.probe/src/agent/JvmProbeAgent.java
@@ -22,7 +22,7 @@ import java.lang.reflect.InvocationTargetException;
public class JvmProbeAgent {
private static final int MSEC_PER_SEC = 1000;
- private static final int NSEC_PER_SEC = 1000000;
+ private static final int NSEC_PER_SEC = 1000000000;
private static final String METRIC_FILE_NAME = "jvm-metrics.txt";
private static String pid;
private static String nspid;
@@ -79,10 +79,11 @@ public class JvmProbeAgent {
}
private static void processCollector(RuntimeMXBean runtimeBean, OperatingSystemMXBean osBean) {
- long processStartTime = runtimeBean.getStartTime(); // ms
+ long processStartTime = runtimeBean.getStartTime(); // ms
try {
- Long processCpuTime = callLongGetter(osBean.getClass().getMethod("getProcessCpuTime"), osBean); // ns
- writeMetricRecords(String.format("|jvm_process|%s|%d|%d|\n", pid, processStartTime, processCpuTime));
+ Long processCpuTime = callLongGetter(osBean.getClass().getMethod("getProcessCpuTime"), osBean); // ns
+ writeMetricRecords(String.format("|jvm_process|%s|%f|%f|\n",
+ pid, ((double)processStartTime / MSEC_PER_SEC), ((double)processCpuTime / NSEC_PER_SEC)));
} catch (Exception e) {
//System.out.println("error");
}
@@ -169,8 +170,8 @@ public class JvmProbeAgent {
// gc
private static void gcCollector(List<GarbageCollectorMXBean> garbageCollectors) {
for (GarbageCollectorMXBean gc : garbageCollectors) {
- writeMetricRecords(String.format("|jvm_gc|%s|%s|%d|%d|\n",
- pid, gc.getName(), gc.getCollectionCount(), gc.getCollectionTime())); // ms
+ writeMetricRecords(String.format("|jvm_gc|%s|%s|%d|%f|\n",
+ pid, gc.getName(), gc.getCollectionCount(), ((double)gc.getCollectionTime() / MSEC_PER_SEC)));
}
}
--
2.33.0