我需要使用 OID 获取 jvm 线程 block 计数的值,以便可以使用 cacti 绘制图表。我搜索了很多,但只发现以下OID 1.3.6.1.4.1.42.2.145.3.163.1.1.3.10.1.4。当我尝试 snmpwalk 时,它返回带有 Counter64 值的子 OID。以上OID代表
The total number of times that this thread has blocked to enter or re-enter a monitor..
当我在上面 snmpwalk 时,它返回每个线程的值及其阻塞值。但我想要在指定时间内阻塞的所有线程的计数。任何帮助将不胜感激。
最佳答案
根本就没有这样的计数器。
列出了所有可用的 JVM OID here .
您可能感兴趣的最接近的 JVM 指标是 sun.rt._sync_ContendedLockAttempts
计数器。
以下是如何从 Java 获取它:
import sun.management.ManagementFactoryHelper;
import sun.management.counter.Counter;
import java.util.NoSuchElementException;
public class Test {
public static void main(String[] args) {
System.out.println(getContendedLockAttempts());
}
private static long getContendedLockAttempts() {
for (Counter counter : ManagementFactoryHelper.getHotspotRuntimeMBean().getInternalRuntimeCounters()) {
if ("sun.rt._sync_ContendedLockAttempts".equals(counter.getName())) {
return (long) counter.getValue();
}
}
throw new NoSuchElementException();
}
}
或者从命令行:
jcmd {PID} PerfCounter.print | grep sun.rt._sync_ContendedLockAttempts
关于java - jvm 线程 block 计数的 SNMP OID 是多少,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39590386/