-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathcheck_top_process.sh
executable file
·65 lines (57 loc) · 1.05 KB
/
check_top_process.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
#!/bin/bash
#
# Bill Beavis
#
# todo: better checking for commandline arguments
CLIMIT=80
WLIMIT=50
STATE_OK=0
STATE_CRITICAL=2
STATE_WARNING=1
print_help() {
echo ""
echo "Usage: check_top_process -w <warning> -c <critical>"
echo ""
echo "This plugin checks the top running process."
echo ""
exit 0
}
case "$1" in
-w)
WLIMIT=$2
CLIMIT=$4
;;
-c)
CLIMIT=$2
WLIMIT=$4
;;
--help)
print_help
exit $STATE_OK
;;
-h)
print_help
exit $STATE_OK
;;
*)
esac
if [ `echo $WLIMIT $CLIMIT |awk '{print ($1 > $2) ? "true" : "false" }'` = "true" ]
then
echo "Error: WARNING value must be below CRITICAL value"
print_help
exit $STATE_OK
fi
x=`UNIX95= ps -eo pcpu,comm,user,pid,time |sort -rnk1 | head -1`
y=`echo $x |awk '{print $1 "% command=" $2 " user=" $3 " pid=" $4 " cputime=" $5}'`
if [ `echo $x $CLIMIT |awk '{print ($1 > $6) ? "true" : "false" }'` = "true" ]
then
echo $y
exit $STATE_CRITICAL
fi
if [ `echo $x $WLIMIT |awk '{print ($1 > $6) ? "true" : "false" }'` = "true" ]
then
echo $y
exit $STATE_WARNING
fi
echo $y
exit $STATE_OK