cyla

Jester

Mar 12th, 2009
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 1.75 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.     while read -a line
  12.     do
  13.         if [[ "${line[2]}" =~ "^[hs]d[a-z][0-9]*\$" ]]
  14.         then
  15.             echo "${line[2]}"
  16.         fi
  17.     done < /proc/diskstats
  18.     exit 0
  19. fi
  20.  
  21. device=$(basename $0)
  22. device=${device#diskutil_}
  23. if [ "$1" = "config" ]; then
  24.         echo 'graph_category disk'
  25.         echo "graph_title Disk utilization for /dev/${device}"
  26.         echo 'graph_args -l 0 -u 100'
  27.         echo 'graph_vlabel %'
  28.         echo 'util.label utilization'
  29.         echo 'util.info utilization %'
  30.         echo 'util.type GAUGE'
  31.         echo 'util.draw AREA'
  32.         exit 0
  33. fi
  34.  
  35. statefiledir=/var/lib/munin/plugin-state/
  36. statefile="${statefiledir}diskutil-${device}.state"
  37.  
  38. ncpu=0
  39. while read -a line
  40. do
  41.     case "${line[0]}" in
  42.         cpu)
  43.             newticks=$((line[1] + line[2] + line[3] + line[4] + line[5] + line[6] + line[7] + line[8] + line[9]))
  44.             ;;
  45.         cpu*)
  46.             ncpu=$((ncpu + 1))
  47.             ;;
  48.         *)
  49.             break 2
  50.             ;;
  51.     esac
  52. done < /proc/stat
  53.  
  54. while read -a line
  55. do
  56.     if [[ "${line[2]}" = "$device" ]]
  57.     then
  58.         newioticks=${line[12]}
  59.     fi
  60. done < /proc/diskstats
  61.  
  62. if [ -s $statefile ] ; then
  63.         read oldticks oldioticks <$statefile
  64. else
  65.         oldticks=$newticks
  66.         oldioticks=$newioticks
  67. fi
  68. echo "${newticks} ${newioticks}" > $statefile
  69.  
  70. deltaticks=$(($newticks-$oldticks))
  71. deltaioticks=$(($newioticks-$oldioticks))
  72.  
  73. printf "util.value %d.%d\n" $(($deltaioticks*$ncpu*10/$deltaticks)) $(($deltaioticks*$ncpu*10*10000/$deltaticks-$deltaioticks*$ncpu*10/$deltaticks*10000))
  74.  
Add Comment
Please, Sign In to add comment