This repository has been archived by the owner on Nov 24, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
check_io_bandwidth.sh
executable file
·71 lines (61 loc) · 1.78 KB
/
check_io_bandwidth.sh
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
#!/bin/bash
#------------------------------------------------------------------------------
# [Ivan Alejandro Marugan]
# Check I/O Bandwidth
# Only print I/O Bandwidth
#
# Dependences: ifstat [apt-get install ifstat]
#
#------------------------------------------------------------------------------
VERSION=1.1
# Exit codes
STATE_OK=0
STATE_WARNING=1
STATE_CRITICAL=2
STATE_UNKNOWN=3
# Print help
_usage() {
echo "Usage: check_io_bw.sh [-h help] -i <interface>
-h Print this help message
-i Interface (eth0, eth1...)
Exit status:
0 if OK
1 if minor problems (e.g., cannot create a temp file)
2 if serious trouble (e.g., cannot access command-line argument)
3 unknown
"
exit $STATE_OK;
}
# Arguemtns
while getopts ":i:h" opt; do
case $opt in
h) _usage; $STATE_OK;;
i) INTERFACE=$OPTARG;;
\?) echo "Invalid option: -$OPTARG" >&2; _usage; exit $STATE_CRITICAL;;
:) echo "Requiere an argument: -$OPTARG" >&2; _usage; exit $STATE_CRITICAL;;
esac
done
# Check arguments
if [[ -z "$INTERFACE" ]]; then
echo "Empty obligatory arguments."
exit $STATE_CRITICAL
fi
# Check dependences
if [[ ! $(which ifstat) ]]; then
echo "ifstat isn't installed. Please install it."
exit $STATE_CRITICAL;
fi
# Vars
INPUT=$(ifstat -nqwz -i $INTERFACE 1 1 | tail -1 | awk '{ print $1 }')
OUTPUT=$(ifstat -nqwz -i $INTERFACE 1 1 | tail -1 | awk '{ print $2 }')
PERF_DATA="| in=${INPUT}KB/s;${INPUT};${INPUT};0 out=${OUTPUT}KB/s;${OUTPUT};${OUTPUT};0"
# Main #####################################################
if [[ "$OUTPUT" == 'n/a' || "$INPUT" == 'n/a' ]]; then
# STATE_CRITICAL
echo "INTERFACE DON'T WORK"
exit $STATE_CRITICAL
else
# STATE_OK
echo "I/O BANDWIDTH OK - input = ${INPUT}KB/s output = ${OUTPUT}KB/s $PERF_DATA"
exit $STATE_OK
fi