Advertisement
Guest User

check_jmx_heap.sh

a guest
Aug 27th, 2014
254
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 2.34 KB | None | 0 0
  1. #!/bin/bash
  2. ######################################################################
  3. #                                                                    #
  4. #       check_jmx_heap.sh                                            #
  5. #       Executes a check_jmx memory check on a host and formats      #
  6. #       results to pass back to nagios as perf data.                 #
  7. #                                                                    #
  8. #       MW 11/09/2013                                                #
  9. #                                                                    #
  10. ######################################################################
  11.  
  12. FILE=${@: -1} #gets last arg
  13.  
  14. HELP="Usage: check_jmx_heap.sh -H -p  -w  -c
  15.     -H target hostname
  16.     -p port on which host's JMX process is listening
  17.     -w warning threshold value
  18.     -c critical threshold value
  19.     -? prints this message"
  20.  
  21. #Check args
  22. if [ $# = 0 ]
  23. then
  24.         echo "$HELP"
  25.         exit
  26. else
  27.         while getopts ":H:p:w:c:\?" opt; do
  28.         case $opt in
  29.                 H)
  30.                         HOST=$OPTARG
  31.                         ;;
  32.                 p)
  33.                         PORT=$OPTARG
  34.                         ;;
  35.                 w)
  36.                         WARN=$OPTARG
  37.                         ;;
  38.                 c)
  39.                         CRIT=$OPTARG
  40.                         ;;
  41.                 :)
  42.                         echo "Option -$OPTARG requires an argument." >&2
  43.                         exit
  44.                         ;;
  45.                 \?)
  46.                         echo "$HELP"
  47.                         exit 1
  48.                         ;;
  49.         esac
  50.         done
  51. fi
  52.  
  53. 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)
  54. EXIT_STATUS=$?
  55. RAWSIZE=`echo $OUTPUT | sed "s/[^0-9]*\([0-9]\+\).*/\1/"`
  56. STATUS=`echo $OUTPUT | sed -E 's/(([^ ]+ ){2}).*/\2/'`
  57. 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 } }}'`
  58. VALUE=$(echo $OUTPUT | sed 's/.*{\(.*\)}.*/\1;/' | sed 's/;/; /g')
  59. #echo "JVM Heap $STATUS | $VALUE"
  60. echo "JVM Heap $STATUS- $MEMSIZE | $VALUE"
  61. exit $EXIT_STATUS
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement