Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- ######################################################################
- # #
- # check_jmx_heap.sh #
- # Executes a check_jmx memory check on a host and formats #
- # results to pass back to nagios as perf data. #
- # #
- # MW 11/09/2013 #
- # #
- ######################################################################
- FILE=${@: -1} #gets last arg
- HELP="Usage: check_jmx_heap.sh -H -p -w -c
- -H target hostname
- -p port on which host's JMX process is listening
- -w warning threshold value
- -c critical threshold value
- -? prints this message"
- #Check args
- if [ $# = 0 ]
- then
- echo "$HELP"
- exit
- else
- while getopts ":H:p:w:c:\?" opt; do
- case $opt in
- H)
- HOST=$OPTARG
- ;;
- p)
- PORT=$OPTARG
- ;;
- w)
- WARN=$OPTARG
- ;;
- c)
- CRIT=$OPTARG
- ;;
- :)
- echo "Option -$OPTARG requires an argument." >&2
- exit
- ;;
- \?)
- echo "$HELP"
- exit 1
- ;;
- esac
- done
- fi
- OUTPUT=$(/usr/local/nagios/libexec/check_jmx -U "service:jmx:rmi:///jndi/rmi://$HOST:$PORT/jmxrmi" -O java.lang:type=Memory -A HeapMemoryUsage -K used -I HeapMemoryUsage -J used -vvvv -w $WARN -c $CRIT)
- EXIT_STATUS=$?
- RAWSIZE=`echo $OUTPUT | sed "s/[^0-9]*\([0-9]\+\).*/\1/"`
- STATUS=`echo $OUTPUT | sed -E 's/(([^ ]+ ){2}).*/\2/'`
- MEMSIZE=`echo $RAWSIZE | awk '{ sum=$1 ; hum[1024**3]="GB";hum[1024**2]="MB";hum[1024]="KB"; for (x=1024**3; x>=1024; x/=1024){ if (sum>=x) { printf "%.2f %s\n",sum/x,hum[x];break } }}'`
- VALUE=$(echo $OUTPUT | sed 's/.*{\(.*\)}.*/\1;/' | sed 's/;/; /g')
- #echo "JVM Heap $STATUS | $VALUE"
- echo "JVM Heap $STATUS- $MEMSIZE | $VALUE"
- exit $EXIT_STATUS
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement