Java Management Extensions API (JMX)

The Java™ Management Extensions API (JMX) is used for resource monitoring and management.

JMX is a Java framework and API that provides a way of exposing application information by using a widely accepted implementation. Various tools, such as JConsole can then be configured to read that information. The information is exposed by using managed beans (MBeans) - non-static Java classes with public constructors. Get and set methods of the bean are exposed as attributes , while all other methods are exposed as operations.

You can connect to JMX in a Liberty JVM server to view the attributes and operations of MBeans, both locally and from a remote machine. A local connection requires adding the localConnector-1.0 feature to your server.xml and allows you to connect from within the same JVM server. Adding the restConnector-1.0 feature to your server.xml allows you to connect by way of a RESTful interface, which provides remote access to JMX.

Using WebSphere MBeans to monitor your applications

  1. To begin, you must acquire a reference to your MBeanServer. This example looks for the JvmStats MBean and uses the findMBeanServer method to check which server the MBean is registered to. Then, referring to the correct MBeanServer object, you can obtain reference to your MBean and get data back from the attributes that it exposes. This example looks for the UpTime attribute of the JvmStats MBean.
    // Create an ObjectName object for the MBean that we're looking for.
    ObjectName beanObjName = null;
    beanObjName = new ObjectName("WebSphere:type=JvmStats");
    
    // Obtain the full list of MBeanServers.
    java.util.List servers = MBeanServerFactory.findMBeanServer(null);
    MBeanServer mbs = null;
    
    // Iterate through our list of MBeanServers and attempt to find the one we want.
    for (int i = 0; i < servers.size(); i++)
    {
        // Check if the MBean domain matches what we're looking for.
        mbs = (MBeanServer)servers.get(i);
    
        if (mbs.isRegistered(beanObjName))
        {
            Object attributeObj = mbs.getAttribute(beanObjName, "UpTime");
            System.out.println("UpTime of JVM is: " + attributeObj + ".");
        }
    }

Remote connectivity to JMX in Liberty

Remote connectivity to JMX in a Liberty JVM server requires use of an SSL connection and Java Platform, Enterprise Edition (JEE) role authorization. The client code then obtains a reference to the remote MBean using a JMXServiceURL.

  1. All the JMX MBeans accessed through the REST connector are protected by a single JEE role named administrator. To provide access to this role edit the server.xml and add the authenticated user to the administrator role.
    <administrator-role>
    <user>myuserid</user>
    <group>group1</group>
    </administrator-role>
    For more information on using JEE roles, see Authorization using SAF role mapping.
  2. A remote RESTful JMX client must access the Liberty JVM server by using SSL. To configure SSL support for a Liberty JVM server, refer to topic Configuring SSL (TLS) for a Liberty JVM server using RACF. In addition, the JMX client requires access to the restConnector client-side JAR file and an SSL client keystore containing the server's signing certificate. The restConnector.jar comes as part of the CICS® WLP installation, which is available at &USSHOME;/wlp/clients.
  3. In the client-side code, you need to create a JMXServiceURL object. This allows you to obtain a reference to the remote MBeanServerConnection object. See example where <host> and <httpsPort> match those of your server:
    JMXServiceURL url = new JMXServiceURL("service:jmx:rest://<host>:<httpsPort>/IBMJMXConnectorREST");
    JMXConnector jmxConnector = JMXConnectorFactory.connect(url, environment);
    MBeanServerConnection mbsc = jmxConnector.getMBeanServerConnection();
  4. When you successfully obtain the connection, the MBeanServerConnection object provides the same capability and set of methods as a local connection from the MBeanServer object.

For more information about the MBeans that are provided by WebSphere®, see Liberty profile: List of provided MBeans.