Getting the JVM heap consumption using JMX code in JBoss EAP 7

Solution Verified - Updated -

Issue

  • Not able to read heap consumption on application server using a custom JMX code. I am trying to make JMX code read and print current heap memory usage on our application servers. But I can not see which property in the MBeans has this. I am able to read the heap memory stats from Domain controller though. The following code works for Domain controller but not for querying application servers.

     JMXConnector jmxConnector = JMXConnectorFactory.connect(serviceURL, map);
     MBeanServerConnection connection = jmxConnector.getMBeanServerConnection();
     ObjectName objectName = ObjectName.getInstance("jboss.as:host=master,core-service=platform-mbean,type=memory");
     String attributeName = "heapMemoryUsage";
     Object result = connection.getAttribute(objectName, attributeName);
     System.out.println(attributeName +"="+ result);
    
  • Similarly what option should I use to query "heap consumption of each JVM", based on my example to check the server state:

     ObjectName objectName = ObjectName.getInstance("jboss.as:management-root=server");
     String attributeName = "serverState";
     Object result = connection.getAttribute(objectName, attributeName);
     System.out.println(result);
    

Environment

  • Red Hat JBoss Enterprise Application Platform (EAP)
    • 7.x

Subscriber exclusive content

A Red Hat subscription provides unlimited access to our knowledgebase, tools, and much more.

Current Customers and Partners

Log in for full access

Log In

New to Red Hat?

Learn more about Red Hat subscriptions

Using a Red Hat product through a public cloud?

How to access this content