cyla

Jester

Mar 12th, 2009
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 1.72 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.     if [[ "${line[0]}" == "cpu" ]]
  42.     then
  43.         newticks=$(( line[1] + line[2] + line[3] + line[4] + line[5] + line[6] + line[7] + line[8] + line[9] ))
  44.     elif [[ "${line[0]}" =~ "cpu" ]]
  45.     then
  46.         ncpu=$((ncpu + 1))
  47.     else
  48.         break
  49.     fi
  50. done < /proc/stat
  51.  
  52. while read -a line
  53. do
  54.     if [[ "${line[2]}" = "$device" ]]
  55.     then
  56.         newioticks=${line[12]}
  57.     fi
  58. done < /proc/diskstats
  59.  
  60. if [ -s $statefile ] ; then
  61.         read oldticks oldioticks <$statefile
  62. else
  63.         oldticks=$newticks
  64.         oldioticks=$newioticks
  65. fi
  66. echo "${newticks} ${newioticks}" > $statefile
  67.  
  68. deltaticks=$(($newticks-$oldticks))
  69. deltaioticks=$(($newioticks-$oldioticks))
  70.  
  71. printf "util.value %d.%d\n" $(($deltaioticks*$ncpu*10/$deltaticks)) $(($deltaioticks*$ncpu*10*10000/$deltaticks-$deltaioticks*$ncpu*10/$deltaticks*10000))
Add Comment
Please, Sign In to add comment