cyla

cyla

Mar 12th, 2009
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 1.25 KB | None | 0 0
  1. #!/bin/bash
  2. #%# family=auto
  3. #%# capabilities=autoconf suggest
  4.  
  5. if [ "$1" = "autoconf" ]; then
  6.     echo yes
  7.     exit 0
  8. fi
  9.  
  10. if [ "$1" = "suggest" ]; then
  11.     awk '/ [hs]d[a-z][0-9]* / { print $3 }' /proc/diskstats
  12.     exit 0
  13. fi
  14.  
  15. device=$(basename $0 | sed 's/^diskutil_//g')
  16. ncpu=$(egrep -c '^cpu[0-9]+ ' /proc/stat)
  17.  
  18. if [ "$1" = "config" ]; then
  19.     echo 'graph_category disk'
  20.     echo "graph_title Disk utilization for /dev/${device}"
  21.     echo 'graph_args -l 0 -u 100'
  22.     echo 'graph_vlabel %'
  23.     echo 'util.label utilization'
  24.     echo 'util.info utilization %'
  25.     echo 'util.type GAUGE'
  26.     echo 'util.draw AREA'
  27.     exit 0
  28. fi
  29.  
  30. statefiledir=/var/lib/munin/plugin-state/
  31. statefile="${statefiledir}diskutil-${device}.state"
  32.  
  33. newticks=$(awk '/^cpu / { print $2+$3+$4+$5+$6+$7+$8+$9+$10 }' /proc/stat)
  34. newioticks=$(awk "/ $device / { print \$13 }" /proc/diskstats)
  35. if [ -s $statefile ] ; then
  36.     read oldticks oldioticks <$statefile
  37. else
  38.     oldticks=$newticks
  39.     oldioticks=$newioticks
  40. fi
  41. echo "${newticks} ${newioticks}" > $statefile
  42.  
  43. deltaticks=$(($newticks-$oldticks))
  44. deltaioticks=$(($newioticks-$oldioticks))
  45.  
  46. printf "util.value %d.%d\n" $(($deltaioticks*$ncpu*10/$deltaticks)) $(($deltaioticks*$ncpu*10*10000/$deltaticks-$deltaioticks*$ncpu*10/$deltaticks*10000))
  47.  
Add Comment
Please, Sign In to add comment