]> git.evergreen-ils.org Git - contrib/equinox.git/blob - monitoring/nagios/check_apache_cpu
errant line sending a copy of the row
[contrib/equinox.git] / monitoring / nagios / check_apache_cpu
1 #!/bin/bash\r
2 # Copyright (C) 2008-2013  Equinox Software, Inc.\r
3 # Written by Michael Tate <mtate@esilibrary.com>\r
4 #\r
5 # This program is free software; you can redistribute it and/or\r
6 # modify it under the terms of the GNU General Public License\r
7 # as published by the Free Software Foundation; either version 2\r
8 # of the License, or (at your option) any later version.\r
9 #\r
10 # This program is distributed in the hope that it will be useful,\r
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of\r
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
13 # GNU General Public License for more details.\r
14 #\r
15 #\r
16 # Author       : Michael Tate, Sys Admin, ESI\r
17 # Purpose      : Check to see if any Apache processes are consuming 100% of CPU, and ennumerate them.\r
18 USAGE="check_apachecpu  (WARN 1, CRIT 2+)"\r
19 if [[ $1 == *help* ]]; then\r
20   echo "Usage: $USAGE"\r
21   exit 0\r
22 fi\r
23 \r
24 HIGHESTPROC=`ps -Ao pcpu,pid,args | grep -i apache | grep -v grep | sort -rn|cut -d"." -f1|head -n1`\r
25 TOPPROCLIST=`ps -Ao pcpu,pid,args | grep -i apache | grep -v grep | sort -rn|cut -d"." -f1|head -n4`\r
26 HIGPPROCS=0\r
27 \r
28 for i in `ps -Ao pcpu,pid,args | grep -i apache | grep -v grep | sort -rn|cut -d"." -f1|head -n4`; do\r
29   if [ "$i" -gt "80" ]; then\r
30     HIGPPROCS=$((HIGHPROCS++))\r
31   fi\r
32 done\r
33 \r
34 \r
35 if [ "$HIGHPROCS" -gt "1" ]; then\r
36    EXITSTATUS="CRIT:  $HIGHPROCS High CPU Apache processes; Highest: $HIGHESTPROC%"\r
37    EXITCODE="2"\r
38 elif [ "$HIGHPROCS" -gt "0" ]; then\r
39    EXITSTATUS="WARN: $HIGHPROCS High CPU Apache process; Usage: $HIGHESTPROC%"\r
40    EXITCODE="1"\r
41 else\r
42    EXITSTATUS="OK: Highest CPU usage $HIGHESTPROC%"\r
43    EXITCODE="0"\r
44 fi\r
45 \r
46 echo "$EXITSTATUS"\r
47 exit $EXITCODE\r
48 \r