Open GoogleCodeExporter opened 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
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
Original issue reported on code.google.com by
bre...@limbocat.com
on 27 Nov 2012 at 9:07