Page 1 of 1

Monitoring JMX With Nagios XI - NRPE: Unable to read output

Posted: Fri Jun 15, 2018 10:36 am
by ntobars
HI Team,

I'm trying to monitor tomcat using the check_jmx plugin from the following URL:

https://library.nagios.com/library/prod ... nagios-xi/

I follow each step correctly and I currently have problems when I run the command from the NagiosXI server

Error
[root@nagiosXI linux]# /usr/local/nagios/libexec/check_nrpe -H 192.168.1.2 -c check_jmx -a '-U service:jmx:rmi:///jndi/rmi://127.0.0.1:9696/jmxrmi -O java.lang:type=Memory -A HeapMemoryUsage -K used -I HeapMemoryUsage -J used -vvvv -w 4248302272 -c 5498760192'
NRPE: Unable to read output

NRPE Test
[root@nagiosXI linux]# /usr/local/nagios/libexec/check_nrpe -H 192.168.1.2
NRPE v3.2.1

Client configuration

[root@tomcat libexec]# grep check_jmx /usr/local/nagios/etc/nrpe.cfg
command[check_jmx]=/usr/local/nagios/libexec/check_jmx $ARG1$

root user
[root@tomcat libexec]# ./check_jmx -U service:jmx:rmi:///jndi/rmi://localhost:9696/jmxrmi -O java.lang:type=Memory -A HeapMemoryUsage -K used -I HeapMemoryUsage -J used -vvvv -w 4248302272 -c 5498760192
JMX OK - HeapMemoryUsage.used=2131803240 | HeapMemoryUsage.used=2131803240,committed=3617685504;init=1073741824;max=12850036736;used=2131803240

nagios user
[nagios@tomcat libexec]$ echo $JAVA_HOME
/app/jdk1.7.0_67
[nagios@tomcat libexec]$ ./check_jmx -U service:jmx:rmi:///jndi/rmi://localhost:9696/jmxrmi -O java.lang:type=Memory -A HeapMemoryUsage -K used -I HeapMemoryUsage -J used -vvvv -w 4248302272 -c 5498760192
JMX OK - HeapMemoryUsage.used=2016888832 | HeapMemoryUsage.used=2016888832,committed=3617685504;init=1073741824;max=12850036736;used=2016888832

Re: Monitoring JMX With Nagios XI - NRPE: Unable to read out

Posted: Fri Jun 15, 2018 10:58 am
by mcapra
Give the fix mentioned in the second half of this post a try (hard-coding the Java path):
https://support.nagios.com/forum/viewto ... 68#p247768

If JAVA_HOME is being resolved by Bash, NRPE likely isn't picking it up. Hard-coding the Java path in check_jmx can fix that.

Re: Monitoring JMX With Nagios XI - NRPE: Unable to read out

Posted: Fri Jun 15, 2018 2:05 pm
by cdienger
Thank you for the assist, @mcapra!

Re: Monitoring JMX With Nagios XI - NRPE: Unable to read out

Posted: Mon Jun 18, 2018 10:10 am
by ntobars
hello, thank you very much for the help.
I did the following:

[root @ ecs-monitoring linux] # which java
/ bin / java

[root @ ecs-monitoring linux] # / bin / java -version
java version "1.8.0_171"
Java (TM) SE Runtime Environment (build 1.8.0_171-b11)
Java HotSpot (TM) 64-Bit Server VM (build 25.171-b11, mixed mode)

[root @ ecs-monitoring linux] # vi /home/nagios/.bashrc
RDIR = "/ usr / local / nagios / libexec"
/ bin / java -jar $ RDIR / jmxquery.jar "$ @"

[root @ ecs-monitoring linux] # su - nagios
Last login: Mon Jun 18 11:08:19 CLT 2018 on pts / 0
JMX UNKNOWN Required options not specified Usage: check_jmx -help

[root @ ecs-monitoring libexec] # / usr / local / nagios / libexec / check_nrpe -H 172.21.0.100 -c check_jmx -a '-U service: jmx: rmi: /// jndi / rmi: //127.0.0.1 : 6969 / jmxrmi -O java.lang: type = Memory -A HeapMemoryUsage -K used -I HeapMemoryUsage -J used -vvvv -w 4248302272 -c 5498760192
NRPE: Unable to read output

Re: Monitoring JMX With Nagios XI - NRPE: Unable to read out

Posted: Mon Jun 18, 2018 10:57 am
by mcapra
Is 172.21.0.100 the address of the remote machine hosting the Java process you wish to monitor?

I assume ecs-monitoring is the machine hosting your Nagios XI instance? If so, the Java version/environment on this server is irrelevant as you are executing check_jmx remotely via check_nrpe.

I'd like to quote the specific part of the post that I believe is important:
mcapra wrote:It's worth mentioning that, if you're relying on Bash to resolve the java command on behalf of the nagios user, this won't necessarily work when NRPE executes a given command since NRPE doesn't do so through Bash. You could modify check_jmx to include the full path to the java binary to rule out potential environmental issues. Something like this:

Code: Select all

#!/bin/sh
#
# Nagios plugin to monitor Java JMX (http://java.sun.com/jmx)attributes.
#
RDIR=`dirname $0`
/path/to/jdk/bin/java  -jar $RDIR/jmxquery.jar "$@"
I would again like to stress that it is likely not good enough to change the Bash profile by itself for reasons states above.

I would suggest altering the check_jmx script's contents on the 172.21.0.100 machine as demonstrated above. If that doesn't work, can you share the contents of the remote machine's nrpe.cfg file as well as the output of the check_jmx script executed from the CLI of the 172.21.0.100 machine?

Re: Monitoring JMX With Nagios XI - NRPE: Unable to read out

Posted: Mon Jun 18, 2018 4:38 pm
by cdienger
Hopefully Mr. @mcapra's post has helped you, @ntobars. Let us know once you've had a chance to test his suggestion.

Re: Monitoring JMX With Nagios XI - NRPE: Unable to read out

Posted: Wed Jun 20, 2018 9:33 am
by ntobars
Hi and thanks

IP 172.21.0.100 is the server with JAVA.

the ecs monitoring machine is the one that has nagios and I understand what you tell me in the second point, then I will eliminate what I modified.

After understanding what I should do, file the following in the check_jmx file of server 172.21.0.100:

RDIR = `dirname $ 0`
/app/jdk1.7.0_67/bin/java -jar $ RDIR / jmxquery.jar "$ @"

After the change, when I execute the check on the local machine, it throws the following:

[[email protected] libexec] # ./check_jmx -U service: jmx: rmi: /// jndi / rmi: // localhost: 9696 / jmxrmi -O java.lang: type = Memory -A HeapMemoryUsage -K used - I HeapMemoryUsage -J used -vvvv -w 4248302272 -c 549876019
JMX CRITICAL - HeapMemoryUsage.used = 2012329632 | HeapMemoryUsage.used = 2012329632, role = 3698393088; init = 1073741824; max = 12850036736; used = 2012329632
[root @ qehcosapp1 libexec] #


Now, when I run the command from the nagios server, it throws the following message:

[root @ ecs-monitoring linux] # / usr / local / nagios / libexec / check_nrpe -H 172.21.0.100 -c check_jmx -a '-U service: jmx: rmi: /// jndi / rmi: // localhost: 9696 / jmxrmi -O java.lang: type = Memory -A HeapMemoryUsage -K used -I HeapMemoryUsage -J used -vvvv -w 4248302272 -c 549876019
JMX CRITICAL - HeapMemoryUsage.used = 2056654760 | HeapMemoryUsage.used = 2056654760, committed = 3698393088; init = 1073741824; max = 12850036736; used = 2056654760

Now it works correctly, I think initially I misunderstood the solution.

Thank you very much for the help.

:)

Re: Monitoring JMX With Nagios XI - NRPE: Unable to read out

Posted: Wed Jun 20, 2018 12:56 pm
by scottwilkerson
ntobars wrote:Now it works correctly, I think initially I misunderstood the solution.

Thank you very much for the help.
Glad to hear the problem is resolved

Locking