-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathcheck_linux_net_usage
More file actions
89 lines (77 loc) · 2.42 KB
/
check_linux_net_usage
File metadata and controls
89 lines (77 loc) · 2.42 KB
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
#!/bin/bash
Syntax()
{
echo " "
echo " Command Syntax: check_linux_net_usage [-H host] [-c val] [-w val]"
echo " "
exit 3;
}
if [[ $# -ne 6 ]]
then
Syntax
fi
valw=0
valc=0
host=""
while [[ $# > 0 ]]
do
par=$1
case $par in
-c) shift
valc=$1;;
-w) shift
valw=$1;;
-H) shift
host=$1;;
-h) shift
Syntax
exit;;
*) shift;;
esac
done
bashSnippet='
rxBytes1=0;\
for bytes in `cat /sys/class/net/*/statistics/rx_bytes`; do\
rxBytes1=$((rxBytes1 + bytes));\
done;\
txBytes1=0;\
for bytes in `cat /sys/class/net/*/statistics/tx_bytes`; do\
txBytes1=$((txBytes1 + bytes));\
done;\
sleep 5s;\
rxBytes2=0;\
for bytes in `cat /sys/class/net/*/statistics/rx_bytes`; do\
rxBytes2=$((rxBytes2 + bytes));\
done;\
txBytes2=0;\
for bytes in `cat /sys/class/net/*/statistics/tx_bytes`; do\
txBytes2=$((txBytes2 + bytes));\
done;\
rxPerSecond=$(( (rxBytes2 - rxBytes1) / 5 ));\
txPerSecond=$(( (txBytes2 - txBytes1) / 5 ));\
echo "$rxPerSecond $txPerSecond";'
rxAndtxOutput=$(ssh nagios@$host "$bashSnippet")
if [[ -z $rxAndtxOutput ]]; then
echo "SSH Error | ExitCode=3"
exit 3
fi
rxInBytes=$(echo "$rxAndtxOutput" | awk '{ print $1 }')
rxInKiloBits=$(echo "(($rxInBytes * 8 ) / 1024)" | bc -l )
rxInMegaBits=$(echo "(($rxInKiloBits) / 1024)" | bc -l | awk '{printf "%.2f", $0}')
txInBytes=$(echo "$rxAndtxOutput" | awk '{ print $2 }')
txInKiloBits=$(echo "(($txInBytes * 8 ) / 1024)" | bc -l )
txInMegaBits=$(echo "(($txInKiloBits) / 1024)" | bc -l | awk '{printf "%.2f", $0}')
exitCode=0
status="OK"
#if (( $(echo "$rxInMegaBits > $valw" | bc -l) )) || (( $(echo "$txInMegaBits > $valw" | bc -l) ))
if [ $(echo "$rxInMegaBits > $valw" | bc) -eq 1 ] || [ $(echo "$txInMegaBits > $valw" | bc) -eq 1 ]; then
exitCode=1
status="WARNING"
fi
#if (( $(echo "$rxInMegaBits > $valc" | bc -l) )) || (( $(echo "$txInMegaBits > $valc" | bc -l) ))
if [ $(echo "$rxInMegaBits > $valc" | bc -l) -eq 1 ] || [ $(echo "$txInMegaBits > $valc" | bc -l) -eq 1 ]; then
exitCode=2
status="CRITICAL"
fi
echo "NetUsage $status :: RX = $rxInMegaBits Mbits/s / TX = $txInMegaBits Mbits/s | RX=$rxInMegaBits;TX=$txInMegaBits;$valw;$valc"
exit $exitCode