Skip to content

Commit

Permalink
parse iostat for disk busy average
Browse files Browse the repository at this point in the history
  • Loading branch information
bahamas10 committed Oct 29, 2013
1 parent 24a80a4 commit 403d6c3
Showing 1 changed file with 26 additions and 25 deletions.
51 changes: 26 additions & 25 deletions check_disk_busy
Expand Up @@ -6,20 +6,31 @@
# Date: 11/16/12
# License: MIT

sample_time=1 # seconds to sample

# Extract the values from kstat
getvals() {
kstat -p ::"$disk":{rtime,wtime,snaptime}
}

# populate the kstat keys into variables
populate() {
local i=$1
while read name val; do
IFS=: read _ _ _ key <<< "$name"
read "$key$i" <<< "$val"
done < <(getvals)
function busy() {
iostat -xr 1 2 |\
awk -F, '
BEGIN {
max = -1;
}
/^sd[0-9]/ {
d = $1;
sub(/^sd/,"",d);
if (d > max) {
max = d;
next;
}
if ($2||$3||$4||$5||$6||$7||$8||$9) {
i++;
busy+=$10;
}
}
END {
if (i) {
printf("%d\n", (busy / i) + .5);
} else {
print "0"
}
}'
}

warning=90
Expand All @@ -34,21 +45,11 @@ while getopts 'nw:c:' option; do
done
shift $((OPTIND - 1))

disk=${1:-sd1}

# grab the values, sleep for $sample_time seconds, grab more values
populate 1
sleep "$sample_time"
populate 2

# calculate the percentage of time spent doing work during $sample_time seconds
busy=$(bc <<< "((100 * $rtime2 + $wtime2) - (100 * $rtime1 + $wtime1)) / ($snaptime2 - $snaptime1)")
busy=$(busy)

# alert
if [[ -z "$busy" ]]; then
echo 'unknown: error retrieving data'
echo '- possible disks -' >&2
kstat -lc disk :::class | awk -F: '{print $3}' >&2
exit 3
elif (( busy >= critical )); then
echo -n 'critical: '
Expand Down

0 comments on commit 403d6c3

Please sign in to comment.