Advertisement
cyla

diskutil_

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