gohopper / jmxquery

Automatically exported from code.google.com/p/jmxquery
0 stars 0 forks source link

Performance data output for HeapMemoryUsage not in proper format #22

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1. The command used and output is below.
./check_jmx -U service:jmx:rmi:///jndi/rmi://localhost:8686/jmxrmi -O 
java.lang:type=Memory -A HeapMemoryUsage -K used -I HeapMemoryUsage -J used 
-vvvv -w 731847066 -c 1045495808 -username admin -password adminadmin
JMX OK - HeapMemoryUsage.used=94996088 | 
HeapMemoryUsage.used=94996088,committed=373665792;init=16777216;max=2075918336;u
sed=94996088

What is the expected output? What do you see instead?

According to Nagios documentation, 
(http://nagiosplug.sourceforge.net/developer-guidelines.html#AEN201) it should 
be in the format below

'label'=value[UOM];[warn];[crit];[min];[max]

What version of the product are you using? On what operating system?
1.3 on Ubuntu hitting Glassfish 2.2 JVM

Please provide any additional information below.

First, it was a joy to find this project because it actually worked.  I was 
planning to build a pnp4nagios template using the performance data output, but 
I don't think the HeapMemoryUsage values are mapped properly.

Original issue reported on code.google.com by bre...@limbocat.com on 27 Nov 2012 at 9:07

GoogleCodeExporter commented 9 years ago
I've made a workaround for myself 

cat >/usr/lib/nagios/plugins/contrib/check_jmx <<EOL
#!/bin/sh
JAVA_HOME=/opt/jdk1.7.0_07
RDIR=\`dirname \$0\`
OUTPUT=\$($JAVA_HOME/bin/java -cp \$RDIR/jmxquery.jar org.nagios.JMXQuery "\$@")
EXIT_STATUS=\$?
STATUS=\`echo \$OUTPUT\`
PARAMCOUNT=\$(echo \$OUTPUT | tr -cd '=' | wc -c)
if [ \$PARAMCOUNT -gt "1" ] 
then
        VALUE=\$(echo \$OUTPUT | sed 's/.*{\(.*\)}.*/\1;/' | sed 's/;/;;;0; /g')
else
        VALUE=\$(echo \$OUTPUT | awk '{print \$NF}')
fi
echo "\$STATUS | \$VALUE"

exit \$EXIT_STATUS
EOL

Example:
"
test@xxx:~$ /usr/lib/nagios/plugins/contrib/check_jmx -U 
service:jmx:rmi:///jndi/rmi://localhost:8060/jmxrmi -O java.lang:type=Memory -A 
HeapMemoryUsage -K used -I HeapMemoryUsage -J used -vvvv -w 1048576000 -c 
1887436800
JMX OK 
HeapMemoryUsage.used=85766112{committed=202899456;init=209715200;max=405471232;u
sed=85766112} | committed=202899456;;;0; init=209715200;;;0; max=405471232;;;0; 
used=85766112;;;0; 
test@xxx:~$ 
"

Original comment by desinfor...@gmail.com on 7 Dec 2012 at 6:48

GoogleCodeExporter commented 9 years ago
Below is the workaround I'm using with version 1.3.  This has be getting graphs 
in pnp4nagios.  I want to ultimately pull down the source and attempt to 
address the performance data stuff.  

Specific changes from the workaround from "desinfor...@gmail.com":

1. I'm setting JAVA_HOME to /usr/java/default. 

2. The output has duplicate outputs due to echoing $STATUS and $VALUE, but 
$STATUS already has the data from $VALUE.  

Example output before change:
JMX OK - HeapMemoryUsage.used=4948958504 | 
HeapMemoryUsage.used=4948958504,committed=14656602112;init=15032385536;max=14656
602112;used=4948958504 | JMX OK - HeapMemoryUsage.used=4948958504 | 
HeapMemoryUsage.used=4948958504,committed=14656602112;;;0; 
init=15032385536;;;0; max=14656602112;;;0; used=4948958504

2. Regular expressions are not my thing, but the "sed 's/.*{\(.*\)}.*/\1;/'" 
didn't do anything to my output from the raw output of the original check. So, 
I stripped it out.

3. The PARAMCOUNT was including the additional number due to the 
"HeapMemoryUsage" which is being included after the "|" for Performance data.  
This should not be included per Nagios performance data documentation, so I put 
a sed command, the one using cut, to strip this out. 

BEFORE: 
JMX OK - HeapMemoryUsage.used=5806198016 | 
HeapMemoryUsage.used=5806198016,committed=14656602112;init=15032385536;max=14656
602112;used=5806198016

AFTER: 
JMX OK - HeapMemoryUsage.used=5806198016 | 
committed=14656602112;init=15032385536;max=14656602112;used=5806198016

4.  I added an additional sed to add one (blindly) to the end of the output. 

BEFORE:
JMX CRITICAL - HeapMemoryUsage.used=6126633704 | committed=14656602112;;;0; 
init=15032385536;;;0; max=14656602112;;;0; used=6126633704

AFTER:
JMX CRITICAL - HeapMemoryUsage.used=6126633704 | committed=14656602112;;;0; 
init=15032385536;;;0; max=14656602112;;;0; used=6126633704;;;0;

############################################################
# I call this "check_jmx_mod_2"
############################################################

#!/bin/sh
JAVA_HOME=/usr/java/default/
RDIR=`dirname $0`
OUTPUT=$($JAVA_HOME/bin/java -jar $RDIR/jmxquery.jar "$@")
EXIT_STATUS=$?
STATUS=`echo $OUTPUT`
PARAMCOUNT=$(echo $OUTPUT | cut -d '|' -f2 | tr -cd '=' | wc -c)

if [ $PARAMCOUNT -gt "1" ]
then
        VALUE=$(echo $OUTPUT | sed 's/[^"|]*,/ /' | sed 's/;/;;;0; /g' | sed 's/$/;;;0;/g')
else
        VALUE=$(echo $OUTPUT | awk '{print $NF}')
fi
echo "$VALUE"

exit $EXIT_STATUS

############################################################

This is a full example showing output. This is properly being graphed in my 
pnp4nagios environment. 
[mcastanien@nagios-prod jmxquery-1.3]$ 
/usr/local/nagios/libexec/jmxquery-1.3/check_jmx_mod_2 -U 
service:jmx:rmi:///jndi/rmi://prdjboss01:9585/jmxrmi -O java.lang:type=Memory 
-A HeapMemoryUsage -K used -I HeapMemoryUsage -J used -vvvv -w 1048576000 -c 
1887436800 -username monitorRole -password <password_here>
JMX CRITICAL - HeapMemoryUsage.used=7271012536 | committed=14656602112;;;0; 
init=15032385536;;;0; max=14656602112;;;0; used=7271012536;;;0;

Original comment by mcastan...@gmail.com on 19 Dec 2013 at 1:10