List of JMX objects and attributes?

Matthew picture Matthew · Jul 7, 2011 · Viewed 36.6k times · Source

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.

Answer

Gilad picture Gilad · Oct 5, 2014

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...