-
Notifications
You must be signed in to change notification settings - Fork 1
/
check_iostat
executable file
·55 lines (47 loc) · 1.16 KB
/
check_iostat
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
53
54
55
#!/bin/sh
basename=`basename $0`
print_help(){
printf "$basename -d device\n \n"
printf " -d\t Device to check (e.g. /dev/sda) \n"
printf "\n"
exit 0
}
args=`getopt --long -o "i:d:h" "$@"`
eval set -- "$args"
while true; do
case "$1" in
-d)
DEVICE=$2
shift 2
;;
-h)
print_help
;;
*)
break
;;
esac
done
if [ -z "$DEVICE" ]; then
echo "You need to specify at least the device"
exit 3
fi
OUTPUT=`iostat -x -d $DEVICE | tail -n2 | head -n1`
RS=`echo $OUTPUT | awk '{print $4}'`
WS=`echo $OUTPUT | awk '{print $5}'`
IOREAD=`echo $OUTPUT | awk '{print $6}'`
IOWRITE=`echo $OUTPUT | awk '{print $7}'`
IOWAIT=`echo $OUTPUT | awk '{print $10}'`
UTILISATION=`echo $OUTPUT | awk '{print $14}'`
if [ -z "$IOWRITE" ] || [ -z "$IOREAD" ]; then
echo "Failed to get a value for $DEVICE"
exit 3
fi
echo "IO for $DEVICE -- Read: $IOREAD kB/s // Write: $IOWRITE kB/s // Wait: $IOWAIT ms // Reads/s $RS // Writes/s $WS // Utilisation $UTILISATION % | \
kbs_read=${IOREAD}KB \
kbs_write=${IOWRITE} \
ms_wait=${IOWAIT}ms \
utilisation=${UTILISATION}% \
rs=${RS} \
ws=${WS}"
exit 0