Advertisement
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]+|cciss/.*$ ]]
- then
- echo "${line[2]}"
- elif [[ "${line[2]}" =~ ^dm-[0-9]+$ ]]
- then
- echo -n "${line[2]} "
- index=${line[2]#dm-}
- ls -l /dev/mapper | grep "254,\s*${index} " | cut -c 47-1024
- fi
- done < /proc/diskstats
- exit 0
- fi
- device=$(basename $0)
- device=${device#diskutil_}
- devname="dev_${device}"
- tmpdevice=${!devname}
- if [ $tmpdevice ]; then
- realdevice=${!devname}
- else
- realdevice=$device
- fi
- if [ "$1" = "config" ]; then
- echo 'graph_category disk'
- echo "graph_title Disk utilization for ${device} (/dev/${realdevice})"
- 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"
- newtime=$(date -u +%s)
- 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]}" = "${realdevice}" ]] ; then
- newioticks=${line[12]}
- fi
- done < /proc/diskstats
- if [ -s $statefile ] ; then
- read oldtime oldticks oldioticks < $statefile
- else
- oldtime=$newtime
- oldticks=$newticks
- oldioticks=$newioticks
- fi
- echo "${newtime} ${newticks} ${newioticks}" > $statefile
- deltatime=$(( $newtime - $oldtime ))
- deltaticks=$(( $newticks - $oldticks ))
- deltaioticks=$(( $newioticks - $oldioticks ))
- #printf "%d, %d, %d\n" $deltatime $deltaticks $deltaioticks
- #printf "util.value %d.%d\n" $(( $deltaioticks * $ncpu * 10 / $deltaticks )) $(( $deltaioticks * $ncpu * 10 * 10000 / $deltaticks - $deltaioticks * $ncpu * 10 / $deltaticks * 10000 ))
- 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