DuMONChIK

nagois-glugin-check_xen_lvm

Oct 31st, 2013
211
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 2.16 KB | None | 0 0
  1. #!/bin/bash
  2.  
  3. #pastebin-url: http://pastebin.com/t1tcLX6n
  4.  
  5. IFS=$'\n'
  6.  
  7. DEBUG=0
  8.  
  9. #units 1000 or 1024
  10. UNITS="GB"
  11. KB=1024
  12. MB=$[KB*KB]
  13. GB=$[MB*KB]
  14.  
  15. bc=$(which bc)
  16.  
  17. usage()
  18. {
  19.  echo "Usage:"
  20.  echo " "`basename $0`" [ -w <warn> ] [ -c <crit> ] [ -l <storage-label> | -u <storage-uuid> ]"
  21.  echo
  22. }
  23.  
  24. crit=10
  25. warn=20
  26. storage="Local storage"
  27. by_uuid=0
  28.  
  29. while [ "$1" != "" ]; do
  30.     case $1 in
  31.         -c) shift
  32.             crit=$1
  33.             ;;
  34.         -w) shift
  35.             warn=$1
  36.             ;;
  37.         -l) shift
  38.             storage="$1"
  39.             by_uuid=0
  40.             ;;
  41.         -u) shift
  42.             storage="$1"
  43.             by_uuid=1
  44.             ;;
  45.         -d) DEBUG=1
  46.             ;;
  47.         * ) usage
  48.             exit 1
  49.     esac
  50.     shift
  51. done
  52.  
  53. if [ $by_uuid -gt 0 ]; then
  54.  VG_SIZE=$(xe sr-list uuid=$storage params=physical-size | awk '{print($NF)}' | head -n1)
  55.  VG_USED=$(xe sr-list uuid=$storage params=physical-utilisation | awk '{print($NF)}' | head -n1)
  56. else
  57.  VG_SIZE=$(xe sr-list name-label=$storage params=physical-size | awk '{print($NF)}' | head -n1)
  58.  VG_USED=$(xe sr-list name-label=$storage params=physical-utilisation | awk '{print($NF)}' | head -n1)
  59. fi
  60.  
  61. #need more accuracy in calculations
  62. FREE_PERCENT=$(echo "\$v=(($VG_SIZE-$VG_USED)/$VG_SIZE)*100; printf \"%0.2f\",\$v;" | perl)
  63.  
  64. if [ $DEBUG -gt 0 ]; then
  65.  echo "VG_SIZE=$VG_SIZE"
  66.  echo "VG_USED=$VG_USED"
  67.  echo "FREE_PERCENT=$FREE_PERCENT"
  68. fi
  69.  
  70. crit_value=$(echo "$crit>$FREE_PERCENT" | $bc)
  71. warn_value=$(echo "$warn>$FREE_PERCENT" | $bc)
  72.  
  73. MSG="OK"
  74. if [ $warn_value -gt 0 ]; then
  75.  MSG="WARNING"
  76. fi
  77. if [ $crit_value -gt 0 ]; then
  78.  MSG="CRITICAL"
  79. fi
  80.  
  81. SIZE_GB=$(echo "scale=2; $VG_SIZE/$GB" | $bc)
  82. FREE_GB=$(echo "scale=2; ($VG_SIZE-$VG_USED)/$GB" | $bc)
  83.  
  84. echo "DISK $MSG - free space: $FREE_GB / $SIZE_GB $UNITS ($FREE_PERCENT% free)"
Advertisement
Add Comment
Please, Sign In to add comment