Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- #%# family=auto
- #%# capabilities=autoconf suggest
- if [ "$1" = "autoconf" ]; then
- echo yes
- exit 0
- fi
- if [ "$1" = "suggest" ]; then
- while read -a line
- do
- if [[ "${line[2]}" =~ "^[hs]d[a-z][0-9]*\$" ]]
- then
- echo "${line[2]}"
- fi
- done < /proc/diskstats
- exit 0
- fi
- device=$(basename $0)
- device=${device#diskutil_}
- if [ "$1" = "config" ]; then
- echo 'graph_category disk'
- echo "graph_title Disk utilization for /dev/${device}"
- echo 'graph_args -l 0 -u 100'
- echo 'graph_vlabel %'
- echo 'util.label utilization'
- echo 'util.info utilization %'
- echo 'util.type GAUGE'
- echo 'util.draw AREA'
- exit 0
- fi
- statefiledir=/var/lib/munin/plugin-state/
- statefile="${statefiledir}diskutil-${device}.state"
- ncpu=0
- while read -a line
- do
- case "${line[0]}" in
- cpu)
- newticks=$((line[1] + line[2] + line[3] + line[4] + line[5] + line[6] + line[7] + line[8] + line[9]))
- ;;
- cpu*)
- ncpu=$((ncpu + 1))
- ;;
- *)
- break 2
- ;;
- esac
- done < /proc/stat
- while read -a line
- do
- if [[ "${line[2]}" = "$device" ]]
- then
- newioticks=${line[12]}
- fi
- done < /proc/diskstats
- if [ -s $statefile ] ; then
- read oldticks oldioticks <$statefile
- else
- oldticks=$newticks
- oldioticks=$newioticks
- fi
- echo "${newticks} ${newioticks}" > $statefile
- deltaticks=$(($newticks-$oldticks))
- deltaioticks=$(($newioticks-$oldioticks))
- 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