-
Notifications
You must be signed in to change notification settings - Fork 7
/
monitor-io
executable file
·100 lines (83 loc) · 2.47 KB
/
monitor-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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
#!/bin/bash
# Copyright 2021 Red Hat, Inc.
#
# Purpose: Monitor block device performance
# Author: Vivek Goyal <[email protected]>
set -e
# Sampling interval in seconds
_INTERVAL="5"
# Default average wait thresholds in ms
_R_AWAIT_THRESHOLD=50
_W_AWAIT_THRESHOLD=50
_PRINT_FORMAT="%-24s%-16s%-16s\n"
usage() {
cat <<-FOE
Usage: $1 [OPTIONS] <block-dev-to-monitor>
Options:
-h, --help Print help message
-r, --rlat Average read latency threshold in ms (default 50ms)
-w, --wlat Average write latency threshold in ms (default 50ms)
-i Sampling Interval in seconds (default 5 second)
FOE
}
print_header() {
#echo "Read latency threshold=$_R_AWAIT_THRESHOLD Write latency threshold=$_W_AWAIT_THRESHOLD"
#printf "\n\n"
printf "$_PRINT_FORMAT" "Date/Time" "Read Lat(ms)" "Write Lat(ms)"
}
monitor_device() {
local bdev_path=$1
local bdev_base=$(basename $bdev_path)
local field_dev f_r_await f_w_await r_await w_await
local timestamp
/usr/bin/iostat -d $bdev_path -x -y $_INTERVAL | while read line;
do
# TODO: Use awk instead
field_dev=`echo $line | cut -d " " -f1`
[ "$field_dev" != "$bdev_base" ] && continue
f_r_await=`echo $line | cut -d " " -f6`
f_w_await=`echo $line | cut -d " " -f12`
timestamp=`date +"%x %T"`
printf "$_PRINT_FORMAT" "$timestamp" "$f_r_await" "$f_w_await"
r_await=${f_r_await%%.*}
w_await=${f_w_await%%.*}
if [ $r_await -gt $_R_AWAIT_THRESHOLD ];then
printf "%s Read Latency %sms is higher than threshold %sms\n" "$timestamp" "$r_await" "$_R_AWAIT_THRESHOLD"
fi
if [ $w_await -gt $_W_AWAIT_THRESHOLD ];then
printf "%s Write Latency %sms is higher than threshold %sms \n" "$timestamp" "$w_await" "$_W_AWAIT_THRESHOLD"
fi
done
}
# Main
_INPUT_STR=""$@
_OPTS=`getopt -o hr:w:i: -l help -l rlat: -l wlat: -- $_INPUT_STR`
eval set -- "$_OPTS"
while true ; do
case "$1" in
-h | --help) usage $(basename $0); exit 0;;
-r | --rlat) _R_AWAIT_THRESHOLD=$2; shift 2;;
-w | --wlat) _W_AWAIT_THRESHOLD=$2; shift 2;;
-i) _INTERVAL=$2; shift 2;;
--) shift; break;;
esac
done
if [ $# -ne 1 ];then
usage $(basename $0)
exit 1
fi
_BLOCK_DEV=$1
if [ -z $_BLOCK_DEV ]; then
usage $(basename $0)
exit 1
fi
if [ ! -b "$_BLOCK_DEV" ]; then
echo "Error: $_BLOCK_DEV is not a block device"
exit 1
fi
if [ ! -x "/usr/bin/iostat" ]; then
echo "Error: /usr/bin/iostat is not available/executable."
exit 1
fi
print_header
monitor_device "$_BLOCK_DEV"