Advertisement
cyla

cyla

Mar 10th, 2009
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 1.24 KB | None | 0 0
  1. #!/bin/sh
  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 '^cpu[0-9]+ ' /proc/stat | wc -l)
  17.  
  18. if [ "$1" = "config" ]; then
  19.     echo 'graph_category disk'
  20.     echo "graph_title Disk Utilization ${device}"
  21.     echo 'graph_args --base 1000 -l 0'
  22.     echo 'graph_vlabel %'
  23.     echo 'util.label utilization'
  24.     echo 'util.info utilization %'
  25.     echo 'util.type GAUGE'
  26.     echo 'util.draw LINE2'
  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=`cat /proc/diskstats | grep " $device " | awk '{ print $13 }'`
  35. if [ -s $statefile ] ; then
  36.     oldticks=`awk '{print $1}' $statefile`
  37.     oldioticks=`awk '{print $2}' $statefile`
  38. else
  39.     oldticks=$newticks
  40.     oldioticks=$newioticks
  41. fi
  42. echo "${newticks} ${newioticks}" > $statefile
  43.  
  44. deltaticks=$(($newticks-$oldticks))
  45. deltaioticks=$(($newioticks-$oldioticks))
  46.  
  47. echo "${deltaioticks} ${deltaticks} ${ncpu}" | awk '{ printf "util.value %f\n", $1/$2*$3*10 }'
  48.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement