Java JMX 对象和属性列表?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/6610905/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-16 08:15:27  来源:igfitidea点击:

List of JMX objects and attributes?

javajmx

提问by Matthew

I am trying to implement a nagios plugin, and doing so requires that I know specifically what object and attribute I want to monitor. The thing is, I haven't been able to find a listing anywhere of the standard system jmx objects and attributes. Can anyone point me in the right direction? I need to monitor things like memory pools, heap size, etc.

我正在尝试实现一个 nagios 插件,这样做需要我特别知道我想要监视的对象和属性。问题是,我无法在标准系统 jmx 对象和属性的任何地方找到列表。任何人都可以指出我正确的方向吗?我需要监控内存池、堆大小等内容。

采纳答案by Roland Hu?

You can always use mBeanServer.queryNames(null, null);for getting to all MBeans registered at a certain MBeanServer (where mBeanServeris the MBeanServerConnectionwhich you obtained either locally or remotely).

您始终可以使用mBeanServer.queryNames(null, null); 用于获取以一定的MBeanServer注册的所有Mbean(其中mBeanServerMBeanServerConnection你获得本地或远程)。

However, before implementing your own Nagios Plugins, why not using an already exisiting one ? E.g. jmx4perl's check_jmx4perlwhich comes with tools for exploring the JMX namespace (like jmx4perl <url> listfor listing all JMX MBeans with their attributes and operations or j4psha readline based JMX shell with context sensitive command line completion).

然而,在实现你自己的 Nagios 插件之前,为什么不使用一个已经存在的插件呢?例如jmx4perlcheck_jmx4perl附带游览JMX命名空间(如工具jmx4perl <url> list用于列出所有JMX MBean的与他们的属性和操作或j4psh基于JMX外壳采用上下文敏感的命令行完成一个readline的)。

回答by Joel

Are you looking for the JVM platform MBean docs?

您在寻找JVM 平台 MBean 文档吗?

There are examples there on to get the MBeans and interrogate them e.g.

那里有一些示例可以获取 MBeans 并询问它们,例如

The ThreadMXBeanplatform MBean provides support for monitoring thread contention and thread CPU time.

ThreadMXBean的平台MBean提供有关监控线程争夺和线程的CPU时间的支持。

回答by helios

Check out MC4Jor JConcole- it's trivial to get going with both of 'em.

查看MC4JJConcole- 开始使用它们很简单。

回答by Chux Uzoeto

From a sysadmin point of view, I fully understand the bases for the question. The standard JMX documentation, or the objects one can encounter while trying to browse JMX object trees, can be overwhelming and confusing.

从系统管理员的角度来看,我完全理解这个问题的基础。标准的 JMX 文档,或者在尝试浏览 JMX 对象树时可能遇到的对象,可能会让人不知所措且令人困惑。

I have found this Op5 KB articlequite useful in providing a decent overview of JMX objects of interest for JBoss.

我发现这篇Op5 KB 文章在提供 JBoss 感兴趣的 JMX 对象的体面概述方面非常有用。

Obviously, one needs to adjust to fit with the monitoring system they are actually using, but there is enough in the examples for whatever nagios-based monitoring system is being used.

显然,需要进行调整以适应他们实际使用的监控系统,但示例中的内容足以满足正在使用的任何基于 nagios 的监控系统的需求。

回答by Gilad

You can use

您可以使用

Set mbeans = mBeanServer.queryNames(null, null);
for (Object mbean : mbeans)
{
    WriteAttributes(mBeanServer, (ObjectName)mbean);
}

private void WriteAttributes(final MBeanServer mBeanServer, final ObjectName http)
        throws InstanceNotFoundException, IntrospectionException, ReflectionException
{
    MBeanInfo info = mBeanServer.getMBeanInfo(http);
    MBeanAttributeInfo[] attrInfo = info.getAttributes();

    System.out.println("Attributes for object: " + http +":\n");
    for (MBeanAttributeInfo attr : attrInfo)
    {
        System.out.println("  " + attr.getName() + "\n");
    }
}

This will write all the object names and their attributes...

这将写入所有对象名称及其属性...