-
Notifications
You must be signed in to change notification settings - Fork 1
/
check_load
executable file
·66 lines (52 loc) · 1.6 KB
/
check_load
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
#! /usr/bin/env bash
#The following plugin checks and reports the load average of the system. The warning and critical thresholds are accepted as percentage values.
usage() { echo "Usage: $0 -c Critical -w Warning (% values, w<c)" 1>&2; exit 1; }
while getopts ":c:w:" o; do
case "${o}" in
c)
c=${OPTARG}
;;
w)
w=${OPTARG}
;;
*)
usage
;;
esac
done
#! [[ "$w" =~ ^[0-9]+$ ]]
if [ -z "${c}" ] || [ -z "${w}" ] || [ $(echo "$w > $c" | bc) -ne 0 ]; then
usage
fi
w=${w%.*}
c=${c%.*}
cpu=$(lscpu|grep CPU\(s\)|head -1|awk -F ':' '{print $2}')
#Half of w1/w
w15=$((w*cpu))
w15=$(echo "scale=3; $w15/200" | bc -l)
w1=$((w*cpu))
w1=$(echo "scale=3; $w1/100" | bc -l)
#Mean of w1 and w15
w5=$(echo $w1 + $w15| bc)
w5=$(echo "scale=3; $w5/2" | bc -l)
c15=$w1
c1=$((c*cpu))
c1=$(echo "scale=3; $c1/100" | bc -l)
#Mean of c1 and c15
c5=$(echo $c1 + $c15| bc)
c5=$(echo "scale=3; $c5/2" | bc -l)
load=$(uptime|awk -F ':' '{print $NF}')
IFS=',' read -ra addr <<< "$load"
#Load average for last 1,5 and 15 mins respectively
d1=${addr[0]}
d5=${addr[1]}
d15=${addr[2]}
echo "Load Average: $d1,$d5,$d15 (1,5,15 mins)"
echo "Warning Limit: $w1,$w5,$w15"
echo "Critical Limit: $c1,$c5,$c15"
#Reports critical/warning if either of the values get exceed (d1,d5,d15)
if [ $(echo "$d1 > $c1" | bc) -ne 0 ] || [ $(echo "$d5 > $c5" | bc) -ne 0 ] || [ $(echo "$d15 > $c15" | bc) -ne 0 ]; then
exit 2
elif [ $(echo "$d1 > $w1" | bc) -ne 0 ] || [ $(echo "$d5 > $w5" | bc) -ne 0 ] || [ $(echo "$d15 > $w15" | bc) -ne 0 ]; then
exit 1
fi