Created
February 17, 2021 05:54
-
-
Save chethanbandi/902bb6772c5ea7d25818e8f4baef4c56 to your computer and use it in GitHub Desktop.
List JMX Beans
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.io.IOException; | |
import java.util.Arrays; | |
import java.util.Set; | |
import javax.management.InstanceNotFoundException; | |
import javax.management.IntrospectionException; | |
import javax.management.MBeanAttributeInfo; | |
import javax.management.MBeanInfo; | |
import javax.management.MBeanServerConnection; | |
import javax.management.ObjectName; | |
import javax.management.ReflectionException; | |
import javax.management.remote.JMXConnectorFactory; | |
import javax.management.remote.JMXServiceURL; | |
class ListJMXBeans { | |
public static void main(String[] args) | |
throws IOException, ReflectionException, InstanceNotFoundException, IntrospectionException { | |
JMXServiceURL jmxUrl = new JMXServiceURL("service:jmx:rmi:///jndi/rmi://:11099/jmxrmi"); | |
MBeanServerConnection connection = JMXConnectorFactory | |
.connect(jmxUrl) | |
.getMBeanServerConnection(); | |
Set<ObjectName> objectNameSet = connection.queryNames(null, null); | |
ObjectName[] objectNames = objectNameSet.toArray(new ObjectName[]{}); | |
Arrays.sort(objectNames); | |
for(ObjectName objectName : objectNames) { | |
System.out.println(); | |
System.out.println(objectName); | |
MBeanInfo mBeanInfo = connection.getMBeanInfo(objectName); | |
MBeanAttributeInfo[] attributeInfos = mBeanInfo.getAttributes(); | |
if(attributeInfos == null) { | |
System.out.println("\tAttributeInfo is null"); | |
continue; | |
} | |
for(MBeanAttributeInfo attributeInfo : attributeInfos) { | |
System.out.println("\t" + attributeInfo); | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment