This is an automated email from the ASF dual-hosted git repository.
ashingau pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/doris.git
The following commit(s) were added to refs/heads/master by this push:
new 57b2c2abc54 [opt](metric) add jvm jsonMetric (#25774)
57b2c2abc54 is described below
commit 57b2c2abc54f65ea8e35ac132fa3919a1749bbc4
Author: ranxiang327 <[email protected]>
AuthorDate: Tue Oct 24 15:25:13 2023 +0800
[opt](metric) add jvm jsonMetric (#25774)
The "http://fe_host:http_port/metrics?type=json" interface is missing the
JVM metric.
---
.../org/apache/doris/metric/JsonMetricVisitor.java | 76 +++++++++++++++++++++-
1 file changed, 75 insertions(+), 1 deletion(-)
diff --git
a/fe/fe-core/src/main/java/org/apache/doris/metric/JsonMetricVisitor.java
b/fe/fe-core/src/main/java/org/apache/doris/metric/JsonMetricVisitor.java
index d32db92ff58..ffdaea30f4b 100644
--- a/fe/fe-core/src/main/java/org/apache/doris/metric/JsonMetricVisitor.java
+++ b/fe/fe-core/src/main/java/org/apache/doris/metric/JsonMetricVisitor.java
@@ -18,15 +18,28 @@
package org.apache.doris.metric;
import org.apache.doris.monitor.jvm.JvmStats;
+import org.apache.doris.monitor.jvm.JvmStats.GarbageCollector;
+import org.apache.doris.monitor.jvm.JvmStats.MemoryPool;
+import org.apache.doris.monitor.jvm.JvmStats.Threads;
import com.codahale.metrics.Histogram;
+import java.util.Iterator;
import java.util.List;
public class JsonMetricVisitor extends MetricVisitor {
private int ordinal = 0;
private boolean closed = false;
+ // jvm
+ private static final String JVM_HEAP_SIZE_BYTES = "jvm_heap_size_bytes";
+ private static final String JVM_NON_HEAP_SIZE_BYTES =
"jvm_non_heap_size_bytes";
+ private static final String JVM_YOUNG_SIZE_BYTES = "jvm_young_size_bytes";
+ private static final String JVM_OLD_SIZE_BYTES = "jvm_old_size_bytes";
+ private static final String JVM_YOUNG_GC = "jvm_young_gc";
+ private static final String JVM_OLD_GC = "jvm_old_gc";
+ private static final String JVM_THREAD = "jvm_thread";
+
public JsonMetricVisitor() {
super();
sb.append("[\n");
@@ -34,7 +47,68 @@ public class JsonMetricVisitor extends MetricVisitor {
@Override
public void visitJvm(JvmStats jvmStats) {
- return;
+ // heap
+ setJvmJsonMetric(sb, JVM_HEAP_SIZE_BYTES, "max", "bytes",
jvmStats.getMem().getHeapMax().getBytes());
+ setJvmJsonMetric(sb, JVM_HEAP_SIZE_BYTES, "committed", "bytes",
+ jvmStats.getMem().getHeapCommitted().getBytes());
+ setJvmJsonMetric(sb, JVM_HEAP_SIZE_BYTES, "used", "bytes",
jvmStats.getMem().getHeapUsed().getBytes());
+
+ // non heap
+ setJvmJsonMetric(sb, JVM_NON_HEAP_SIZE_BYTES, "committed", "bytes",
+ jvmStats.getMem().getNonHeapCommitted().getBytes());
+ setJvmJsonMetric(sb, JVM_NON_HEAP_SIZE_BYTES, "used", "bytes",
jvmStats.getMem().getNonHeapUsed().getBytes());
+
+ // mem pool
+ Iterator<MemoryPool> memIter = jvmStats.getMem().iterator();
+ while (memIter.hasNext()) {
+ MemoryPool memPool = memIter.next();
+ if (memPool.getName().equalsIgnoreCase("young")) {
+ setJvmJsonMetric(sb, JVM_YOUNG_SIZE_BYTES, "used", "bytes",
memPool.getUsed().getBytes());
+ setJvmJsonMetric(sb, JVM_YOUNG_SIZE_BYTES, "peak_used",
"bytes", memPool.getPeakUsed().getBytes());
+ setJvmJsonMetric(sb, JVM_YOUNG_SIZE_BYTES, "max", "bytes",
memPool.getMax().getBytes());
+ } else if (memPool.getName().equalsIgnoreCase("old")) {
+ setJvmJsonMetric(sb, JVM_OLD_SIZE_BYTES, "used", "bytes",
memPool.getUsed().getBytes());
+ setJvmJsonMetric(sb, JVM_OLD_SIZE_BYTES, "peak_used", "bytes",
memPool.getPeakUsed().getBytes());
+ setJvmJsonMetric(sb, JVM_OLD_SIZE_BYTES, "max", "bytes",
memPool.getMax().getBytes());
+ }
+ }
+
+ // gc
+ Iterator<GarbageCollector> gcIter = jvmStats.getGc().iterator();
+ while (gcIter.hasNext()) {
+ GarbageCollector gc = gcIter.next();
+ if (gc.getName().equalsIgnoreCase("young")) {
+ setJvmJsonMetric(sb, JVM_YOUNG_GC, "count", "nounit",
gc.getCollectionCount());
+ setJvmJsonMetric(sb, JVM_YOUNG_GC, "time", "milliseconds",
gc.getCollectionTime().getMillis());
+ } else if (gc.getName().equalsIgnoreCase("old")) {
+ setJvmJsonMetric(sb, JVM_OLD_GC, "count", "nounit",
gc.getCollectionCount());
+ setJvmJsonMetric(sb, JVM_OLD_GC, "time", "milliseconds",
gc.getCollectionTime().getMillis());
+ }
+ }
+
+ // threads
+ Threads threads = jvmStats.getThreads();
+ setJvmJsonMetric(sb, JVM_THREAD, "count", "nounit",
threads.getCount());
+ setJvmJsonMetric(sb, JVM_THREAD, "peak_count", "nounit",
threads.getPeakCount());
+ setJvmJsonMetric(sb, JVM_THREAD, "new_count", "nounit",
threads.getThreadsNewCount());
+ setJvmJsonMetric(sb, JVM_THREAD, "runnable_count", "nounit",
threads.getThreadsRunnableCount());
+ setJvmJsonMetric(sb, JVM_THREAD, "blocked_count", "nounit",
threads.getThreadsBlockedCount());
+ setJvmJsonMetric(sb, JVM_THREAD, "waiting_count", "nounit",
threads.getThreadsWaitingCount());
+ setJvmJsonMetric(sb, JVM_THREAD, "timed_waiting_count", "nounit",
threads.getThreadsTimedWaitingCount());
+ setJvmJsonMetric(sb, JVM_THREAD, "terminated_count", "nounit",
threads.getThreadsTerminatedCount());
+ }
+
+ private void setJvmJsonMetric(StringBuilder sb, String metric, String
type, String unit, long value) {
+ sb.append("{\n\t\"tags\":\n\t{\n");
+ sb.append("\t\t\"metric\":\"").append(metric).append("\"");
+ if (type != null) {
+ sb.append(",\n");
+ sb.append("\t\t\"type\":\"").append(type).append("\"\n");
+ }
+ sb.append("\n\t},\n");
+ sb.append("\t\"unit\":\"").append(unit).append("\",\n");
+ sb.append("\t\"value\":").append(value).append("\n}");
+ sb.append(",\n");
}
@Override
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]