Enabling JMX Support for JRE

In older versions of Java (i.e., JDK/JRE 1.1, 1.2, and 1.3), very little instrumentation was built in, and custom-developed byte-code instrumentation had to be used to perform monitoring. From JRE/JDK 1.5 and above however, support for Java Management Extensions (JMX) were pre-built into JRE/JDK. JMX enables external programs like the eG agent to connect to the JRE of an application and pull out metrics in real-time.

By default, JMX requires no authentication or security (SSL). In this case therefore, to use JMX for pulling out metrics from a target application, the following needs to be done:

  1. Login to the application host.
  2. The <CASSANDRA_HOME>\conf folder used by the target Cassandra Database node will typically contain the following file:

    • cassandra-env.sh if the target Cassandra Database node is installed on a Windows host or cassandra-env.ps1 if the target Cassandra Database node is installed on a Unix host
  3. If the Cassandra Database node is installed on a Windows host, edit the cassandra-env.ps1 file, and append the following lines to it:

    $env:JVM_OPTS="$env:JVM_OPTS -Djava.rmi.server.hostname=<IP_ADDRESS>"

    $JMX_PORT="<Port No>"

    For instance, if the JMX listens on port 7199, then the second line of the above specification would be:

    $JMX_PORT="7199"

    If the Cassandra Database node is installed on a Unix host, edit the cassandra-env.sh file, and append the following lines to it:

    JVM_OPTS="$JVM_OPTS -Djava.rmi.server.hostname=<IP_ADDRESS>"

    JMX_PORT="<Port No>"

    For instance, if the JMX listens on port 7199, then the second line of the above specification would be:

    JMX_PORT="7199"

  4. Then, save the file.
  5. In the first line, set the <IP Address> to the IP address using which the Cassandra Database node has been managed in the eG Enterprise system. Alternatively, you can add the following line to the startup script:

    -Djava.rmi.server.hostname=localhost

  6. Save this script file too.
  7. Next, during test configuration, do the following:

    • Set the port that you defined in step 3 above (in the cassandra-env.ps1 file or cassandra-env.sh) as the JMX Remote Port;
    • Set the user and password parameters to none.
    • Update the test configuration.

On the other hand, if JMX requires only authentication (and no security), then the following steps will apply:

  1. Login to the application host. If the target Cassandra Database node is installed on a Windows host, then, login to the host as a local/domain administrator.
  2. The <JAVA_HOME>\jre\lib\management folder used by the target Cassandra Database node will typically contain the following files:

    • management.properties
    • jmxremote.access
    • jmxremote.password.template
  3. First, copy the jmxremote.password.template file to any other location on the host, rename it as jmxremote.password, and then, copy it back to the <JAVA_HOME>\jre\lib\management folder. Ensure that the jmxremote.password and the jmxremote.access files are copied to the <CASSANDRA_HOME>folder.
  4. Next, edit the jmxremote.password file and the jmxremote.access file copied to the <CASSANDRA_HOME> to create a user with read-write access to the JMX. To know how to create such a user, refer to Enabling JMX Support for JRE.
  5. Then, proceed to make the jmxremote.password file secure by granting a single user “full access” to that file. For monitoring applications executing on Windows in particular, only the Owner of the jmxremote.password file should have full control of that file. To know how to grant this privilege to the Owner of the file, refer to Enabling JMX Support for JRE.
  6. In case of applications executing on Linux hosts on the other hand, any user can be granted full access to the jmxremote.password file, by following the steps below:

    • Login to the host as the user who is to be granted full control of the jmxremote.password file.
    • Issue the following command:

      chmod 600 jmxremote.password

    • This will automatically grant the login user full access to the jmxremote.password file.
  7. The <CASSANDRA_HOME>\conf folder used by the target Cassandra Database node will typically contain the following file:

    • cassandra-env.sh if the target Cassandra Database node is installed on a Windows host or cassandra-env.ps1 if the target Cassandra Database node is installed on a Unix host
  8. If the Cassandra Database node is installed on a Windows host, edit the cassandra-env.ps1 file, and append the following lines to it:

    $env:JVM_OPTS="$env:JVM_OPTS -Djava.rmi.server.hostname=<IP_ADDRESS>"

    $JMX_PORT="<Port No>"

    For instance, if the JMX listens on port 7199, then the second line of the above specification would be:

    $JMX_PORT="7199"

    If the Cassandra Database node is installed on a Unix host, edit the cassandra-env.sh file, and append the following lines to it:

    JVM_OPTS="$JVM_OPTS -Djava.rmi.server.hostname=<IP_ADDRESS>"

    JMX_PORT="<Port No>"

    For instance, if the JMX listens on port 7199, then the second line of the above specification would be:

    JMX_PORT="7199"

  9. In the first line of the script mentioned in step 8, set the <IP Address> to the IP address using which the Cassandra Database node has been managed in the eG Enterprise system. Alternatively, you can add the following line to the startup script of the target Cassandra Database node:

    -Djava.rmi.server.hostname=localhost

  10. Next, edit the cassandra-env.ps1 file, and append the following lines to it:

    $env:JVM_OPTS="$env:JVM_OPTS -Dcom.sun.management.jmxremote.authenticate=true"

    $env:JVM_OPTS="$env:JVM_OPTS -Dcom.sun.management.jmxremote.password.file=<Path of jmxremote.access>"

    $env:JVM_OPTS="$env:JVM_OPTS -Dcom.sun.management.jmxremote.access.file=<Path of jmxremote.password>"

    For instance, assume that the the jmxremote.access and jmxremote.password files exist in the following directory on a Windows host:  <CASSANDRA_HOME>. The specification above will then read as follows:

    $env:JVM_OPTS="$env:JVM_OPTS -Dcom.sun.management.jmxremote.authenticate=true"

    $env:JVM_OPTS="$env:JVM_OPTS -Dcom.sun.management.jmxremote.password.file=<CASSANDRA_HOME>\jmxremote.password"

    $env:JVM_OPTS="$env:JVM_OPTS -Dcom.sun.management.jmxremote.access.file=<CASSANDRA_HOME>\jmxremote.access"

  11. If the application in question is executing on a Unix/Linux host, and the jmxremote.access and jmxremote.password files reside in the <CASSANDRA_HOME> folder of the host, then the specification will be:

    JVM_OPTS="$JVM_OPTS -Dcom.sun.management.jmxremote.authenticate=true"

    JVM_OPTS="$JVM_OPTS -Dcom.sun.management.jmxremote.password.file=<CASSANDRA_HOME>\jmxremote.password"

    JVM_OPTS="$JVM_OPTS -Dcom.sun.management.jmxremote.access.file=<CASSANDRA_HOME>\jmxremote.access"

  12. Finally, save the file.
  13. Next, during test configuration, do the following:

    • Ensure that the port number configured at step 8 above is set as the JMX Remote Port;
    • Make sure that the user and password parameters of the test are that of a user with readwrite rights to JMX. To know how to create a new user and assign the required rights to him/her, refer to Configuring the eG Agent to Support JMX Authentication.