-
Notifications
You must be signed in to change notification settings - Fork 1
/
check_cpu.sh
51 lines (46 loc) · 1.44 KB
/
check_cpu.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
#!/bin/bash
function usage {
echo "$(basename $0) usage: "
echo " -w warning_level Example: 80"
echo " -c critical_level Example: 90"
echo ""
exit 1
}
while [[ $# -gt 1 ]]
do
key="$1"
case $key in
-w)
WARN="$2"
shift
;;
-c)
CRIT="$2"
shift
;;
*)
usage
shift
;;
esac
shift
done
[ ! -z ${WARN} ] && [ ! -z ${CRIT} ] || usage
CPU_USAGE="$(vmstat 1 2|tail -1)"
CPU_USER="$(echo ${CPU_USAGE} | awk '{print $13}')"
CPU_SYSTEM="$(echo ${CPU_USAGE} | awk '{print $14}')"
CPU_IDLE="$(echo ${CPU_USAGE} | awk '{print $15}')"
CPU_IOWAIT="$(echo ${CPU_USAGE} | awk '{print $16}')"
CPU_ST="$(echo ${CPU_USAGE} | awk '{print $17}')"
if [[ ${CPU_USER} -gt ${CRIT} || ${CPU_SYSTEM} -gt ${CRIT} || ${CPU_IOWAIT} -gt ${CRIT} || ${CPU_ST} -gt ${CRIT} ]]
then
echo "CRITICAL - CPU Usage |CPU_USER=${CPU_USER};;;; CPU_SYSTEM=${CPU_SYSTEM};;;; CPU_IDLE=${CPU_IDLE};;;; CPU_IOWAIT=${CPU_IOWAIT};;;; CPU_ST=${CPU_ST};;;;"
exit 2
elif [[ ${CPU_USER} -gt ${WARN} || ${CPU_SYSTEM} -gt ${WARN} || ${CPU_IOWAIT} -gt ${WARN} || ${CPU_ST} -gt ${WARN} ]]
then
echo "WARNING - CPU Usage |CPU_USER=${CPU_USER};;;; CPU_SYSTEM=${CPU_SYSTEM};;;; CPU_IDLE=${CPU_IDLE};;;; CPU_IOWAIT=${CPU_IOWAIT};;;; CPU_ST=${CPU_ST};;;;"
exit 1
else
echo "OK - CPU Usage |CPU_USER=${CPU_USER};;;; CPU_SYSTEM=${CPU_SYSTEM};;;; CPU_IDLE=${CPU_IDLE};;;; CPU_IOWAIT=${CPU_IOWAIT};;;; CPU_ST=${CPU_ST};;;;"
exit 0
fi