Skip to content

Commit

Permalink
[BugFix] Fix bug metric not using bytes unit (backport #36221) (#37025)
Browse files Browse the repository at this point in the history
Signed-off-by: Astralidea <[email protected]>
  • Loading branch information
Astralidea authored Dec 14, 2023
1 parent 8a79cff commit fcc0c6b
Show file tree
Hide file tree
Showing 5 changed files with 105 additions and 55 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -62,23 +62,23 @@ public ProcResult fetchResult() throws AnalysisException {
result.addRow(genRow("classes total loaded", jvmStats.getClasses().getTotalLoadedClassCount()));
result.addRow(genRow("classes unloaded", jvmStats.getClasses().getUnloadedClassCount()));

result.addRow(genRow("mem heap committed", jvmStats.getMem().getHeapCommitted().getBytes()));
result.addRow(genRow("mem heap used", jvmStats.getMem().getHeapUsed().getBytes()));
result.addRow(genRow("mem non heap committed", jvmStats.getMem().getNonHeapCommitted().getBytes()));
result.addRow(genRow("mem non heap used", jvmStats.getMem().getNonHeapUsed().getBytes()));
result.addRow(genRow("mem heap committed", jvmStats.getMem().getHeapCommitted()));
result.addRow(genRow("mem heap used", jvmStats.getMem().getHeapUsed()));
result.addRow(genRow("mem non heap committed", jvmStats.getMem().getNonHeapCommitted()));
result.addRow(genRow("mem non heap used", jvmStats.getMem().getNonHeapUsed()));

for (MemoryPool memPool : jvmStats.getMem()) {
result.addRow(genRow("mem pool " + memPool.getName() + " committed", memPool.getCommitted().getBytes()));
result.addRow(genRow("mem pool " + memPool.getName() + " used", memPool.getUsed().getBytes()));
result.addRow(genRow("mem pool " + memPool.getName() + " max", memPool.getMax().getBytes()));
result.addRow(genRow("mem pool " + memPool.getName() + " peak used", memPool.getPeakUsed().getBytes()));
result.addRow(genRow("mem pool " + memPool.getName() + " peak max", memPool.getPeakMax().getBytes()));
result.addRow(genRow("mem pool " + memPool.getName() + " committed", memPool.getCommitted()));
result.addRow(genRow("mem pool " + memPool.getName() + " used", memPool.getUsed()));
result.addRow(genRow("mem pool " + memPool.getName() + " max", memPool.getMax()));
result.addRow(genRow("mem pool " + memPool.getName() + " peak used", memPool.getPeakUsed()));
result.addRow(genRow("mem pool " + memPool.getName() + " peak max", memPool.getPeakMax()));
}

for (BufferPool bp : jvmStats.getBufferPools()) {
result.addRow(genRow("buffer pool " + bp.getName() + " count", bp.getCount()));
result.addRow(genRow("buffer pool " + bp.getName() + " used", bp.getUsed().getBytes()));
result.addRow(genRow("buffer pool " + bp.getName() + " capacity", bp.getTotalCapacity().getBytes()));
result.addRow(genRow("buffer pool " + bp.getName() + " used", bp.getUsed()));
result.addRow(genRow("buffer pool " + bp.getName() + " capacity", bp.getTotalCapacity()));
}

for (GarbageCollector gc : jvmStats.getGc()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,15 +89,15 @@ public void visitJvm(JvmStats jvmStats) {
for (JvmStats.MemoryPool memPool : jvmStats.getMem()) {
if (memPool.getName().equalsIgnoreCase(GcNames.PERM)) {
double percent = 0.0;
if (memPool.getCommitted().getBytes() > 0) {
percent = 100 * ((double) memPool.getUsed().getBytes() / memPool.getCommitted().getBytes());
if (memPool.getCommitted() > 0) {
percent = 100 * ((double) memPool.getUsed() / memPool.getCommitted());
}
buildMetric("jvm_size_percent", "percent", String.valueOf(percent),
Collections.singletonList(new MetricLabel("type", GcNames.PERM)));
} else if (memPool.getName().equalsIgnoreCase(GcNames.OLD)) {
double percent = 0.0;
if (memPool.getCommitted().getBytes() > 0) {
percent = 100 * ((double) memPool.getUsed().getBytes() / memPool.getCommitted().getBytes());
if (memPool.getCommitted() > 0) {
percent = 100 * ((double) memPool.getUsed() / memPool.getCommitted());
}
// **NOTICE**: We shouldn't use 'jvm_size_percent' as a metric name, it should be a type,
// but for compatibility reason, we won't remove it.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,19 +82,19 @@ public void visitJvm(JvmStats jvmStats) {
// heap
sb.append(Joiner.on(" ").join(HELP, JVM_HEAP_SIZE_BYTES, "jvm heap stat\n"));
sb.append(Joiner.on(" ").join(TYPE, JVM_HEAP_SIZE_BYTES, "gauge\n"));
sb.append(JVM_HEAP_SIZE_BYTES).append("{type=\"max\"} ").append(jvmStats.getMem().getHeapMax().getBytes())
sb.append(JVM_HEAP_SIZE_BYTES).append("{type=\"max\"} ").append(jvmStats.getMem().getHeapMax())
.append("\n");
sb.append(JVM_HEAP_SIZE_BYTES).append("{type=\"committed\"} ")
.append(jvmStats.getMem().getHeapCommitted().getBytes()).append("\n");
sb.append(JVM_HEAP_SIZE_BYTES).append("{type=\"used\"} ").append(jvmStats.getMem().getHeapUsed().getBytes())
.append(jvmStats.getMem().getHeapCommitted()).append("\n");
sb.append(JVM_HEAP_SIZE_BYTES).append("{type=\"used\"} ").append(jvmStats.getMem().getHeapUsed())
.append("\n");
// non heap
sb.append(Joiner.on(" ").join(HELP, JVM_NON_HEAP_SIZE_BYTES, "jvm non heap stat\n"));
sb.append(Joiner.on(" ").join(TYPE, JVM_NON_HEAP_SIZE_BYTES, "gauge\n"));
sb.append(JVM_NON_HEAP_SIZE_BYTES).append("{type=\"committed\"} ")
.append(jvmStats.getMem().getNonHeapCommitted().getBytes()).append("\n");
.append(jvmStats.getMem().getNonHeapCommitted()).append("\n");
sb.append(JVM_NON_HEAP_SIZE_BYTES).append("{type=\"used\"} ")
.append(jvmStats.getMem().getNonHeapUsed().getBytes()).append("\n");
.append(jvmStats.getMem().getNonHeapUsed()).append("\n");

// mem pool
for (MemoryPool memPool : jvmStats.getMem()) {
Expand All @@ -114,9 +114,9 @@ public void visitJvm(JvmStats jvmStats) {
sb.append(JVM_DIRECT_BUFFER_POOL_SIZE_BYTES).append("{type=\"count\"} ").append(pool.getCount())
.append("\n");
sb.append(JVM_DIRECT_BUFFER_POOL_SIZE_BYTES).append("{type=\"used\"} ")
.append(pool.getUsed().getBytes()).append("\n");
.append(pool.getUsed()).append("\n");
sb.append(JVM_DIRECT_BUFFER_POOL_SIZE_BYTES).append("{type=\"capacity\"} ")
.append(pool.getTotalCapacity().getBytes()).append("\n");
.append(pool.getTotalCapacity()).append("\n");
}
}

Expand Down Expand Up @@ -149,13 +149,13 @@ private void addGcMetrics(GarbageCollector gc, String metricName, String desc) {
private void addMemPoolMetrics(MemoryPool memPool, String metricName, String desc) {
sb.append(Joiner.on(" ").join(HELP, metricName, desc));
sb.append(Joiner.on(" ").join(TYPE, metricName, "gauge\n"));
sb.append(metricName).append("{type=\"committed\"} ").append(memPool.getCommitted().getBytes())
sb.append(metricName).append("{type=\"committed\"} ").append(memPool.getCommitted())
.append("\n");
sb.append(metricName).append("{type=\"used\"} ").append(memPool.getUsed().getBytes())
sb.append(metricName).append("{type=\"used\"} ").append(memPool.getUsed())
.append("\n");
sb.append(metricName).append("{type=\"peak_used\"} ").append(memPool.getPeakUsed().getBytes())
sb.append(metricName).append("{type=\"peak_used\"} ").append(memPool.getPeakUsed())
.append("\n");
sb.append(metricName).append("{type=\"max\"} ").append(memPool.getMax().getBytes())
sb.append(metricName).append("{type=\"max\"} ").append(memPool.getMax())
.append("\n");
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public class SimpleCoreMetricVisitor extends MetricVisitor {
public static final String JVM_OLD_USED_PERCENT = "jvm_old_used_percent";
public static final String JVM_THREAD = "jvm_thread";

public static final String MAX_JOURMAL_ID = "max_journal_id";
public static final String MAX_JOURNAL_ID = "max_journal_id";
public static final String CONNECTION_TOTAL = "connection_total";
public static final String QUERY_LATENCY_MS = "query_latency_ms";

Expand All @@ -75,7 +75,7 @@ public class SimpleCoreMetricVisitor extends MetricVisitor {
private static final Map<String, String> CORE_METRICS = Maps.newHashMap();

static {
CORE_METRICS.put(MAX_JOURMAL_ID, TYPE_LONG);
CORE_METRICS.put(MAX_JOURNAL_ID, TYPE_LONG);
CORE_METRICS.put(CONNECTION_TOTAL, TYPE_LONG);
CORE_METRICS.put(QUERY_LATENCY_MS, TYPE_LONG);
CORE_METRICS.put(QUERY_PER_SECOND, TYPE_DOUBLE);
Expand All @@ -97,13 +97,13 @@ public void visitJvm(JvmStats jvmStats) {
while (memIter.hasNext()) {
MemoryPool memPool = memIter.next();
if (memPool.getName().equalsIgnoreCase("young")) {
long used = memPool.getUsed().getBytes();
long max = memPool.getMax().getBytes();
long used = memPool.getUsed();
long max = memPool.getMax();
String percent = String.format("%.1f", (double) used / (max + 1) * 100);
sb.append(Joiner.on(" ").join(JVM_YOUNG_USED_PERCENT, TYPE_DOUBLE, percent)).append("\n");
} else if (memPool.getName().equalsIgnoreCase("old")) {
long used = memPool.getUsed().getBytes();
long max = memPool.getMax().getBytes();
long used = memPool.getUsed();
long max = memPool.getMax();
String percent = String.format("%.1f", (double) used / (max + 1) * 100);
sb.append(Joiner.on(" ").join(JVM_OLD_USED_PERCENT, TYPE_DOUBLE, percent)).append("\n");
}
Expand Down Expand Up @@ -154,9 +154,9 @@ public void getNodeInfo() {
long brokerDeadNum =
GlobalStateMgr.getCurrentState().getBrokerMgr().getAllBrokers().stream().filter(b -> !b.isAlive)
.count();
sb.append(prefix + "_frontend_dead_num").append(" ").append(String.valueOf(feDeadNum)).append("\n");
sb.append(prefix + "_backend_dead_num").append(" ").append(String.valueOf(beDeadNum)).append("\n");
sb.append(prefix + "_broker_dead_num").append(" ").append(String.valueOf(brokerDeadNum)).append("\n");
sb.append(prefix).append("_frontend_dead_num").append(" ").append(feDeadNum).append("\n");
sb.append(prefix).append("_backend_dead_num").append(" ").append(beDeadNum).append("\n");
sb.append(prefix).append("_broker_dead_num").append(" ").append(brokerDeadNum).append("\n");
}

@Override
Expand Down
90 changes: 70 additions & 20 deletions fe/fe-core/src/main/java/com/starrocks/monitor/jvm/JvmStats.java
Original file line number Diff line number Diff line change
Expand Up @@ -328,32 +328,54 @@ public String getName() {
return this.name;
}

public ByteSizeValue getUsed() {
public long getUsed() {
return used;
}

public ByteSizeValue getByteSizeUsed() {
return new ByteSizeValue(used);
}

public ByteSizeValue getMax() {
public long getMax() {
return max;
}

public ByteSizeValue getByteSizeMax() {
return new ByteSizeValue(max);
}

public ByteSizeValue getCommitted() {

public long getCommitted() {
return committed;
}

public ByteSizeValue getByteSizeCommitted() {
return new ByteSizeValue(committed);
}

public ByteSizeValue getPeakUsed() {
public long getPeakUsed() {
return peakUsed;
}

public ByteSizeValue getByteSizePeakUsed() {
return new ByteSizeValue(peakUsed);
}

public ByteSizeValue getPeakMax() {
public long getPeakMax() {
return peakMax;
}

public ByteSizeValue getByteSizePeakMax() {
return new ByteSizeValue(peakMax);
}

@Override
public String toString() {
StringBuilder sb = new StringBuilder();
sb.append("name: ").append(name).append(", used: ").append(getUsed().toString());
sb.append(", max: ").append(getMax().toString()).append(", peak used: ").append(getPeakUsed().toString());
sb.append(", peak max: ").append(getPeakMax().toString());
sb.append("name: ").append(name).append(", used: ").append(getByteSizeUsed().toString());
sb.append(", max: ").append(getByteSizeMax().toString())
.append(", peak used: ").append(getByteSizePeakUsed().toString());
sb.append(", peak max: ").append(getByteSizePeakMax().toString());
return sb.toString();
}
}
Expand Down Expand Up @@ -383,18 +405,30 @@ public Iterator<MemoryPool> iterator() {
return pools.iterator();
}

public ByteSizeValue getHeapCommitted() {
public long getHeapCommitted() {
return heapCommitted;
}

public ByteSizeValue getByteSizeHeapCommitted() {
return new ByteSizeValue(heapCommitted);
}

public ByteSizeValue getHeapUsed() {
public long getHeapUsed() {
return heapUsed;
}

public ByteSizeValue getByteSizeHeapUsed() {
return new ByteSizeValue(heapUsed);
}

public long getHeapMax() {
return heapMax;
}

/**
* returns the maximum heap size. 0 bytes signals unknown.
*/
public ByteSizeValue getHeapMax() {
public ByteSizeValue getByteSizeHeapMax() {
return new ByteSizeValue(heapMax);
}

Expand All @@ -408,22 +442,30 @@ public short getHeapUsedPercent() {
return (short) (heapUsed * 100 / heapMax);
}

public ByteSizeValue getNonHeapCommitted() {
public long getNonHeapCommitted() {
return nonHeapCommitted;
}

public ByteSizeValue getByteSizeNonHeapCommitted() {
return new ByteSizeValue(nonHeapCommitted);
}

public ByteSizeValue getNonHeapUsed() {
public long getNonHeapUsed() {
return nonHeapUsed;
}

public ByteSizeValue getByteSizeNonHeapUsed() {
return new ByteSizeValue(nonHeapUsed);
}

@Override
public String toString() {
StringBuilder sb = new StringBuilder();
sb.append("heap committed: ").append(getHeapCommitted().toString());
sb.append(", heap used: ").append(getHeapUsed().toString());
sb.append(", heap max: ").append(getHeapMax().toString());
sb.append(", non heap committed: ").append(getNonHeapCommitted().toString());
sb.append(", non heap used: ").append(getNonHeapUsed().toString());
sb.append("heap committed: ").append(getByteSizeHeapCommitted().toString());
sb.append(", heap used: ").append(getByteSizeHeapUsed().toString());
sb.append(", heap max: ").append(getByteSizeHeapMax().toString());
sb.append(", non heap committed: ").append(getByteSizeNonHeapCommitted().toString());
sb.append(", non heap used: ").append(getByteSizeNonHeapUsed().toString());
sb.append("\nMem pools: ");
for (MemoryPool memoryPool : pools) {
sb.append(memoryPool.toString()).append("\n");
Expand Down Expand Up @@ -454,11 +496,19 @@ public long getCount() {
return this.count;
}

public ByteSizeValue getTotalCapacity() {
public long getTotalCapacity() {
return totalCapacity;
}

public ByteSizeValue getByteSizeTotalCapacity() {
return new ByteSizeValue(totalCapacity);
}

public ByteSizeValue getUsed() {
public long getUsed() {
return used;
}

public ByteSizeValue getByteSizeUsed() {
return new ByteSizeValue(used);
}

Expand Down

0 comments on commit fcc0c6b

Please sign in to comment.