-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcheck_io
executable file
·52 lines (41 loc) · 1.27 KB
/
check_io
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#!/bin/bash
. $(dirname $0)/lib.sh
# Simple function to calculate and round with bc
function calcr() {
bc -l <<< "
result = $1
if (length(result) > 23) {
scale = 0
} else {
scale = 23 - length(result)
}
result / 1"
}
if [ -z "$1" -o "$2" ]; then
echo "Usage: $0 <device>"
exit $STATE_UNKNOWN
fi
DEV=$1
STATE=/var/lib/nagioschecks/check_io_$DEV
if [ ! -f $STATE ]; then
cat /sys/block/$DEV/stat > $STATE || exit 1
echo "OK - State initialized on first call, now call again"
exit $STATE_OK
fi
LAST=($(mtime_cat $STATE))
cat /sys/block/$DEV/stat > $STATE
CURRENT=($(mtime_cat $STATE))
TIME=$((${CURRENT[0]} - ${LAST[0]}))
READ_BYTES=$(((${CURRENT[3]} - ${LAST[3]}) * 512 / TIME))
WRTN_BYTES=$(((${CURRENT[7]} - ${LAST[7]}) * 512 / TIME))
READ_IOPS=$(calcr "(${CURRENT[1]} - ${LAST[1]}) / $TIME")
WRTN_IOPS=$(calcr "(${CURRENT[5]} - ${LAST[5]}) / $TIME")
TOTAL_IOPS=$(calcr "(${CURRENT[1]} - ${LAST[1]} + \
${CURRENT[5]} - ${LAST[5]}) / $TIME")
echo "$TOTAL_IOPS IOPS - \
read $(bytes_to_human $READ_BYTES)/s, $READ_IOPS IOPS - \
written $(bytes_to_human $WRTN_BYTES)/s, $WRTN_IOPS IOPS - \
averaged over $((TIME / 60)):$(printf %02d $((TIME % 60))) minutes|\
read=${READ_BYTES}B wrtn=${WRTN_BYTES}B readop=$READ_IOPS wrtnop=$WRTN_IOPS \
iops=$TOTAL_IOPS"
exit $STATE_OK