java - jvm 线程 block 计数的 SNMP OID 是多少

标签 java multithreading jvm snmp

我需要使用 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/

相关文章:

java - AlertDialog.Builder finish() 导致 NPE

从 Visual Studio 启动时,C# ReleaseMutex() 不会在控制台应用程序的多个实例中释放互斥量

垃圾回收 : static variables not lasting through the applications lifetime

java - JVM 无法正确加载类

java - SQL 语法中的连接变量

java - 如何在 Play Framework 上模拟curl --data 'some_content=xyz'?

java - 多点触控代码不起作用

c# - 使用c#进行多线程搜索

c++ - 二维数组的 concurrent_vector

Tomcat 6 : JVM fatal error