Monitoring Java Application Servers with check_jmx in Nagios XI

Picture of Tucker Falen
Tucker Falen
IT Specialist
Java logo on a navy and orange background.

JMX (Java Management Extensions) is a technology in Java that allows developers to monitor and manage applications, system objects, devices, and services. It provides a standard way to access runtime data and control Java applications.

JMX is commonly used for:

  • Monitoring memory usage, CPU load, thread count, and garbage collection.
  • Managing application settings dynamically.
  • Exposing application metrics for external monitoring tools like Nagios, Prometheus, and Grafana.

Prerequisites

Before proceeding, ensure you have the following:

  • A remote server running JMX.
  • A Nagios XI server with network connectivity to the JMX server.
  • The NRPE agent installed on the remote server.

Editing Files

Throughout this guide, you will need to edit configuration files. This guide uses the vi text editor:

  • Press i to enter insert mode.
  • Press Esc to exit insert mode.
  • Save and exit by typing :wq and pressing Enter.

check_jmx Plugin Overview

The check_jmx plugin, available at GitHub, provides monitoring for:

  • Standard Java JMX parameters (memory, threads, OS, garbage collection)
  • Tomcat metrics (requests, processing time, threads)
  • Spring framework Java beans
  • JBoss objects and beans

Installing the Plugin

To install check_jmx, execute the following commands on your JMX server:

cd /usr/local/nagios/libexec/
wget -O check_jmx "https://raw.githubusercontent.com/WillPlatnick/jmxquery/master/plugin/check_jmx"
wget -O jmxquery.jar "https://github.com/WillPlatnick/jmxquery/raw/master/plugin/jmxquery.jar"
chmod +x *jmx*
chown nagios:nagios *jmx*

Testing the Plugin

Run the following command to test check_jmx:

./check_jmx -U service:jmx:rmi:///jndi/rmi://localhost:<port>/jmxrmi -O java.lang:type=Memory -A HeapMemoryUsage -K used -I HeapMemoryUsage -J used -vvvv -w 4248302272 -c 5498760192

Expected output:

JMX OK - HeapMemoryUsage.used=79112000 | HeapMemoryUsage.used=79112000,committed=954204160;init=964689920;max=954204160;used=79112000

Replace <port> with the correct JMX application port (e.g., 7199 in future steps).

Configuring NRPE

To allow Nagios XI to execute check_jmx, define the command in nrpe.cfg on the JMX server:

vi /usr/local/nagios/etc/nrpe.cfg

Add the following line:

command[check_jmx]=/usr/local/nagios/libexec/check_jmx $ARG1$

Restart the NRPE service:

service xinetd restart

Testing from Nagios XI Server

Execute the following command from the Nagios XI server, replacing <jmx_server_ip>:

/usr/local/nagios/libexec/check_nrpe -H <jmx_server_ip> -c check_jmx -a '-U service:jmx:rmi:///jndi/rmi://127.0.0.1:7199/jmxrmi -O java.lang:type=Memory -A HeapMemoryUsage -K used -I HeapMemoryUsage -J used -vvvv -w 4248302272 -c 5498760192'

Expected output:

JMX OK - HeapMemoryUsage.used=94443776 | HeapMemoryUsage.used=94443776,committed=954204160;init=964689920;max=954204160;used=94443776

Creating Nagios Monitoring Objects

Use the NRPE Configuration Wizard to create monitoring objects:

  1. Navigate to Run a Wizard.
  2. Select NRPE wizard.
Screenshot 2025 03 07 112428
  1. Enter the JMX server’s IP and select CentOS as the OS.
  2. Click Next and configure the monitoring parameters.
  3. Define the command for check_jmx in the Command Args field:
'-U service:jmx:rmi:///jndi/rmi://127.0.0.1:7199/jmxrmi -O java.lang:type=Memory -A HeapMemoryUsage -K used -I HeapMemoryUsage -J used -vvvv -w 4248302272 -c 5498760192'
  1. Click Next and complete the wizard steps.
  2. Click Finish to create and apply the monitoring configuration.
  3. Click View status details to verify monitoring.

Using check_jmx With Authentication

For authenticated JMX servers, include -username and -password arguments:

/usr/local/nagios/libexec/check_nrpe -H <jmx_server_ip> -c check_jmx -a '-U service:jmx:rmi:///jndi/rmi://127.0.0.1:7199/jmxrmi -O java.lang:type=Memory -A HeapMemoryUsage -K used -I HeapMemoryUsage -J used -vvvv -w 4248302272 -c 5498760192 -username admin -password welcome123'

Additional check_jmx Configurations

  • Garbage Collection:
-U service:jmx:rmi:///jndi/rmi://127.0.0.1:7199/jmxrmi -O java.lang:type=GarbageCollector,name=ConcurrentMarkSweep -A LastGcInfo -K duration -u ms -vvvv -w xxx -c yyy
  • Thread Count:
-U service:jmx:rmi:///jndi/rmi://127.0.0.1:7199/jmxrmi -O java.lang:type=Threading -A ThreadCount -w xxx -c yyy
  • System Load:
A:type=OperatingSystem -A SystemLoadAverage -w xxx -c yyy

Adding Additional Services

You can add additional checks by:

  • Running the NRPE Wizard again.
  • Copying an existing service:
    1. Navigate to Configure > Core Configuration Manager > Monitoring > Services.
    2. Click Copy on an existing service.
    3. Click Modify on the copied service.
    4. Change the Description to reflect the new check (e.g., “Thread Count”).
    5. Update the $ARG2$ field:
-a '-U service:jmx:rmi:///jndi/rmi://127.0.0.1:7199/jmxrmi -O java.lang:type=Threading -A ThreadCount -w 250 -c 500'
  1. Ensure the Active checkbox is checked.
  2. Click Save and Apply Configuration.

Once applied, the new service will be monitored in Nagios XI.

Share: