Benjamin Renard commited on 2011-01-04 13:54:18
Showing 1 changed files, with 72 additions and 0 deletions.
... | ... |
@@ -0,0 +1,72 @@ |
1 |
+#!/bin/bash |
|
2 |
+ |
|
3 |
+ |
|
4 |
+SWAP=1 |
|
5 |
+ |
|
6 |
+function usage() { |
|
7 |
+ echo "Usage : $0 -w WARN_MEM,WARN_SWAP -c CRIT_MEM,CRIT_SWAP" |
|
8 |
+ echo "Seuil exprime en %" |
|
9 |
+ exit 1 |
|
10 |
+} |
|
11 |
+ |
|
12 |
+[ $# -lt 4 -o "$1" == "-h" ] && usage |
|
13 |
+[ "$1" != "-w" -o "$3" != "-c" ] && usage |
|
14 |
+ |
|
15 |
+DEBUG=0 |
|
16 |
+[ "$5" == "-d" ] && DEBUG=1 |
|
17 |
+ |
|
18 |
+WM=`echo $2|cut -d',' -f1` |
|
19 |
+WS=`echo $2|cut -d',' -f2` |
|
20 |
+CM=`echo $4|cut -d',' -f1` |
|
21 |
+CS=`echo $4|cut -d',' -f2` |
|
22 |
+ |
|
23 |
+[ "$WM" == "" -o "$WS" == "" -o "$CM" == "" -o "$CS" == "" ] && usage |
|
24 |
+ |
|
25 |
+RET=0 |
|
26 |
+MSG="" |
|
27 |
+ |
|
28 |
+MT=`free|grep Mem|awk '{print $2}'` |
|
29 |
+MU=`free|grep Mem|awk '{print $3-$7}'` |
|
30 |
+if [ "$MT" == "0" -o "$MT" == "" ] |
|
31 |
+then |
|
32 |
+ echo "CRITICAL - Can't read memory informations" |
|
33 |
+ exit 2 |
|
34 |
+fi |
|
35 |
+let MR=MU*100/MT |
|
36 |
+ |
|
37 |
+if [ $MR -gt $CM ] |
|
38 |
+then |
|
39 |
+ RET=2 |
|
40 |
+elif [ $MR -gt $WM ] |
|
41 |
+then |
|
42 |
+ RET=1 |
|
43 |
+fi |
|
44 |
+MSG="Mem : $MR% used" |
|
45 |
+[ $DEBUG -eq 1 ] && echo "Mem : $MU / $MT => $MR%" |
|
46 |
+ |
|
47 |
+if [ $SWAP -eq 1 ] |
|
48 |
+then |
|
49 |
+ ST=`free|grep Swap|awk '{print $2}'` |
|
50 |
+ SU=`free|grep Swap|awk '{print $3}'` |
|
51 |
+ if [ "$ST" == "0" -o "$ST" == "" ] |
|
52 |
+ then |
|
53 |
+ echo "CRITICAL - Can't read memory informations" |
|
54 |
+ exit 2 |
|
55 |
+ fi |
|
56 |
+ let SR=SU*100/ST |
|
57 |
+ |
|
58 |
+ if [ $SR -gt $CS ] |
|
59 |
+ then |
|
60 |
+ RET=2 |
|
61 |
+ elif [ $SR -gt $WS ] |
|
62 |
+ then |
|
63 |
+ [ $RET -eq 0 ] && RET=1 |
|
64 |
+ fi |
|
65 |
+ MSG="$MSG - Swap : $SR% used" |
|
66 |
+ [ $DEBUG -eq 1 ] && echo "Swap : $SU / $ST => $SR%" |
|
67 |
+fi |
|
68 |
+ |
|
69 |
+[ $RET -eq 2 ] && echo "CRITICAL - $MSG" && exit 2 |
|
70 |
+[ $RET -eq 1 ] && echo "WARNING - $MSG" && exit 1 |
|
71 |
+echo "OK - $MSG" |
|
72 |
+exit 0 |
|
0 | 73 |