Java Virtual Machine (JMX)

Configuring Java Virtual Machines for JMX

The SAM Java application Server (JMX) template allows you to monitor vital statistics from Java Virtual Machines (JVM). Before assigning the template to a node with a JVM you want to monitor, you must configure the target JVM to accept remote JMX queries.

The sections that follow discuss how to configure JVM servers for JMX monitoring. Configuration instructions are given for both Linux and Microsoft Windows operating systems.

  • Explaining Java arguments.
  • Configuring a Standalone Java Virtual Machine

Java Arguments

For enabling remote JMX monitoring, the following Java arguments will be used:

-Djava.rmi.server.hostname=192.168.0.236
This line indicates the IP address the RMI server will use. Type your server IP address here.

-Dcom.sun.management.jmxremote
This line enables remote JMX monitoring.

-Dcom.sun.management.jmxremote.port=8686
This line indicates which port the JMX module will use to accept JMX connections.

-Dcom.sun.management.jmxremote.ssl=false
This line indicates whether or not SSL is used.

-Dcom.sun.management.jmxremote.authenticate=true
This line indicates whether or not authentication is used. Use of authentication is recommended. If you do not want to use authentication, you should change the value to
false.

-Dcom.sun.management.jmxremote.password.file=c:\jmxremote.password
This line indicates where the passwords file is stored. Do not add this line if you are not using authentication.

-Dcom.sun.management.jmxremote.access.file=c:\jmxremote.access
This line indicates where the access file is stored. Do not add this line if you are not using authentication.

More information can be found at the following website: http://docs.oracle.com/javase/1.5.0/docs/guide/management/agent.html.

Configuring a Standalone Java Virtual Machine

  1. Windows:

  2. 1.   Download the JDK from the Oracle website: http://www.oracle.com/technetwork/java/javase/downloads/index.html (tested on JDK 1.7.0, update version 3).
  3. 2.   Install the JDK.
  4. 3.   On the license agreement page, read and accept the license and then click Next.
  5. 4.   Click Change to change the installation directory to C:\Program Files\Java\jdk1.7.0_3, and then click OK.
  6. 5.   Click Next.
  7. 6.   Click Finish to exit from the installer.
  8. 7.   Add a variable to the system with its path pointing to the JDK installation folder.

For example:

Variable name: JAVA_HOME
Variable value:  C:\Program Files\Java\jdk1.7.0_3

Note: If you want to run Java commands from the command line, you should add the JDK installation path to the PATH variable.

      If you plan to use JMX authentication, follow steps 8-12.

8.   Navigate to the %JAVA_HOME%\jre\lib\management folder.

9.   Rename the jmxremote.password.template file to jmxremote.password. Edit jmxremote.password by replacing/adding its content with the following:

samuser somepasswd

Where samuser is the user for the JVM monitored from SAM and somepasswd – is the password.

10Edit jmxremote.access by replacing/adding its content with the following:

samuser readonly

Where samuser is user for the JVM monitored and readonly – gives this read only permissions.

11Copy jmxremote.access and jmxremote.password to a folder, for example c:\jmxremote\.

12Grant access to the jmxremote.password file only for the Administrator. To grant access only for the Administrator, refer to this topic at the following location: http://download.oracle.com/javase/6/docs/technotes/guides/management/security-windows.html

Linux:

1.   Download the JDK from the Oracle website: http://www.oracle.com/technetwork/java/javase/downloads/index.html (tested on JDK SE 6, update version 24).

2.   Unpack and run the JDK. In this case, the JDK was installed into the /usr/java/jdk1.7.0_3 folder.

3.   Move this folder to /usr/local.

4.   In the /usr/local/ directory, create a symbolic link to jdk1.7.0_3 named Java. Now the JDK is installed in /usr/local/jdk1.7.0_3 and linked to /usr/local/java.

5.   Add the /usr/local/java/bin folder to the system path. (If it is only for your account, add it in .bash_profile file in your home directory). In Slackware, it should be in the .profile file. To make it a system wide environment, add it in the /etc/profile.

6.   Edit a line in .bash_profile to be similar to: PATH=$PATH:$HOME/bin:/usr/local/java/bin. The path will be automatically set at boot time. To set the path immediately, use the command:

$ export PATH=$PATH:/usr/local/java/bin
 

7.   Add a variable to the system with the path pointing to the JDK installation folder.

8.   Add the following lines to the /etc/profile file. Syntax dependencies may be different in various Linux distributions. This example is shown for the CentOS system:
 

export JAVA_HOME=/usr/java/jdk1.7.0_3

export PATH=$PATH:/usr/java/jdk1.7.0_3
 

To set this immediately, run the export commands in your shel, or, logout then log back in to your system.

If you use JMX authentication follow the steps 9-13.

9.   Go to the $JAVA_HOME/jre/lib/management folder and rename the jmxremote.password.template file to jmxremote.password.

10.  Edit jmxremote.password by replacing/adding its content with the following:

samuser somepasswd

Where samuser is the user for the JVM monitored from SAM and somepasswd – is the password.

11. Edit jmxremote.access by replacing/adding its content with the following:

samuser readonly

Where samuser is user for the JVM monitored and readonly – gives this read only permissions.

12Copy jmxremote.access and jmxremote.password to a folder, for example /jmxremote/.

13.  Grant access to the jmxremote.password file only for the root user. Run the following commands as the root user in your shell:

# chown root.root $JAVA_HOME/jre/lib/management/jmxremote.password
# chmod 600 $JAVA_HOME/jre/lib/management/
jmxremote.password

Testing a Standalone JVM

You can test that your JVM can respond to JMX queries by adding the following to the java command line. This will enable JMX on port 8686 using authentication:

-Dcom.sun.management.jmxremote -Dcom.sun.management.jmxremote.port=8686 -Dcom.sun.management.jmxremote.ssl=false -Dcom.sun.management.jmxremote.authenticate=true -Dcom.sun.management.jmxremote.password.file="c:\jmxremote\jmxremote.password" -Dcom.sun.management.jmxremote.access.file="c:\jmxremote\jmxremote.access"

For example:

java -Dcom.sun.management.jmxremote -Dcom.sun.management.jmxremote.port=8686 -Dcom.sun.management.jmxremote.ssl=false -Dcom.sun.management.jmxremote.authenticate=true -Dcom.sun.management.jmxremote.password.file="c:\jmxremote\jmxremote.password" -Dcom.sun.management.jmxremote.access.file="c:\jmxremote\jmxremote.access" some_java_applet

In a separate window/shell, run the following command to test JMX and the JDK configurations:

%JAVA_HOME%\jdk1.7.0_3\bin\jconsole


In the jconsole window, select Remote Process, type 127.0.0.1:8686 and provide Username sam and Password somepasswd.

After a successful connection, you will be able to see different monitoring statistics.


Java Virtual Machine (JMX)

This template assesses the overall performance of any Java Virtual Machine by using JMX protocol. The following application servers are supported: Apache Tomcat, JBoss, GlassFish, IBM WebSphere and Oracle WebLogic.


Prerequisites:
Target JVM configured to allow JMX queries.

Note: This template is configured to send JMX requests on port 8686.

Credentials: Dependent on the JMX configuration.


Monitored Components

Note: All components may vary from a running environment. You can add your own threshold limits as necessary. For more information, see http://knowledgebase.solarwinds.com/kb/questions/2415.

Classes Loaded Count

This monitor returns the number of classes that are currently loaded in the Java virtual machine.


Classes Total Loaded Count

This monitor returns the total number of classes that have been loaded since the Java virtual machine has started execution.


Classes Unloaded Count

This monitor returns the total number of classes unloaded since the Java virtual machine has started execution.


Memory Pending Final Count

This monitor returns the approximate number of objects for which finalization is pending.


Memory Heap Init Size (B)

This monitor returns the initial amount of memory in bytes that the Java virtual machine allocates; or -1 if undefined.


Memory Heap Used (B)

This monitor returns the amount of used memory in bytes. The amount of used memory in the returned memory usage is the amount of memory occupied by both live objects and garbage objects that have not been collected, if any.


Memory Heap Committed (B)

This monitor returns the amount of committed memory in bytes.


Memory Heap Max Size (B)

This monitor returns the maximum amount of memory in bytes that can be used; or -1 if undefined.


Memory Non Heap Init Size (B)

This monitor returns the initial amount of memory in bytes that the Java virtual machine allocates; or -1 if undefined.


Memory Non Heap Used (B)

This monitor returns the amount of used memory in bytes.


Memory Non Heap Committed (B)

This monitor returns the amount of committed memory in bytes.


Memory Non Heap Max Size (B)

This monitor returns the maximum amount of memory in bytes that can be used; or -1 if undefined.


Memory Garbage Collections Count

This monitor returns the approximate accumulated collection elapsed time in milliseconds.

Note: You should set the correct Object Name. You can see which names are available by running the Find Processes, Services, and Performance Counters wizard. In the wizard, expand java.lang, and GarbageCollector and check which names are available. By default, this counter uses: name=Copy.


Memory Garbage Collection Time (ms)

This monitor returns the approximate accumulated collection elapsed time in milliseconds.

Note: You should set the correct Object Name. You can see which names are available by running the Find Processes, Services, and Performance Counters wizard. In the wizard, expand java.lang, and GarbageCollector and check which names are available. By default, this counter uses: name=Copy.


Memory Pool Init Size (B)

This monitor returns the initial amount of memory (in bytes) that the Java virtual machine requests from the operating system for memory management during startup. The Java virtual machine may request additional memory from the operating system and may also release memory to the system over time. The value of init may be undefined.

Note: You should set the correct Object Name. You can see which names are available by running the Find Processes, Services, and Performance Counters wizard. In the wizard, expand java.lang and MemoryPool and check which names are available. By default, this counter uses: name=Code Cache.


Memory Pool Used (B)

This monitor returns the amount of memory currently used (in bytes).

Note: You should set the correct Object Name. You can see which names are available by running the Find Processes, Services, and Performance Counters wizard. In the wizard, expand java.lang and MemoryPool and check which names are available. By default, this counter uses: name=Code Cache.


Memory Pool Committed Size (B)

This monitor returns the amount of memory (in bytes) that is guaranteed to be available for use by the Java virtual machine. The amount of committed memory may change over time (increase or decrease). The Java virtual machine may release memory to the system and committed could be less than init. committed will always be greater than or equal to used.

Note: You should set the correct Object Name. You can see which names are available by running the Find Processes, Services, and Performance Counters wizard. In the wizard, expand java.lang and MemoryPool and check which names are available. By default, this counter uses: name=Code Cache.


Memory Pool Max Size (B)

This monitor returns the maximum amount of memory (in bytes) that can be used for memory management. Its value may be undefined. The maximum amount of memory may change over time if defined. The amount of used and committed memory will always be less than or equal to max if max is defined. A memory allocation may fail if it attempts to increase the used memory such that used > committed even if used <= max would still be true (for example, when the system is low on virtual memory).

Note: You should set the correct Object Name. You can see which names are available by running the Find Processes, Services, and Performance Counters wizard. In the wizard, expand java.lang and MemoryPool and check which names are available. By default, this counter uses: name=Code Cache.


Memory Pool Peak Used (B)

This monitor returns the peak amount of memory currently used (in bytes).

Note: You should set the correct Object Name. You can see which names are available by running the Find Processes, Services, and Performance Counters wizard. In the wizard, expand java.lang and MemoryPool and check which names are available. By default, this counter uses: name=Code Cache.


Memory Pool Peak Committed (B)

This monitor returns the peak amount of memory (in bytes) that is guaranteed to be available for use by the Java virtual machine. The amount of committed memory may change over time (increase or decrease). The Java virtual machine may release memory to the system and committed could be less than init. committed will always be greater than or equal to used.

Note: You should set the correct Object Name. You can see which names are available by running the Find Processes, Services, and Performance Counters wizard. In the wizard, expand java.lang and MemoryPool and check which names are available. By default, this counter uses: name=Code Cache.


Memory Pool Peak Max Size (B)

This monitor returns the maximum peak amount of memory (in bytes) that can be used for memory management. Its value may be undefined. The maximum amount of memory may change over time if defined. The amount of used and committed memory will always be less than or equal to max if max is defined. A memory allocation may fail if it attempts to increase the used memory such that used > committed even if used <= max would still be true (for example, when the system is low on virtual memory).

Note: You should set the correct Object Name. You can see which names are available by running the Find Processes, Services, and Performance Counters wizard. In the wizard, expand java.lang and MemoryPool and check which names are available. By default, this counter uses: name=Code Cache.


Threads Total Started Count

This monitor returns the total number of threads created and also started since the Java virtual machine started.


Current Thread Count

This monitor returns the current number of live threads including both daemon and non-daemon threads.


Current Thread CPU Time

This monitor returns the total CPU time for the current thread in nanoseconds.


Current Thread User Time

This monitor returns the CPU time that the current thread has executed in user mode in nanoseconds.


Runtime Uptime (ms)

This monitor returns the uptime of the Java virtual machine in milliseconds.


Compiler Time (ms)

This monitor returns the approximate accumulated elapsed time (in milliseconds) spent in compilation.

Portions of this document were originally created by and are excerpted from the following sources:
Oracle Corporation, “Oracle System Administration Guide: Printing,” Copyright Copyright 2012 Oracle Corporation. 
All rights reserved. Available at
http://docs.oracle.com/javase/1.5.0/docs/guide/management/overview.html.