]> git.evergreen-ils.org Git - contrib/equinox.git/blob - monitoring/nagios/check_backends2
errant line sending a copy of the row
[contrib/equinox.git] / monitoring / nagios / check_backends2
1 #!/bin/bash\r
2 # Copyright (C) 2008-2010  Equinox Software, Inc.\r
3 #\r
4 # This program is free software; you can redistribute it and/or\r
5 # modify it under the terms of the GNU General Public License\r
6 # as published by the Free Software Foundation; either version 2\r
7 # of the License, or (at your option) any later version.\r
8 #\r
9 # This program is distributed in the hope that it will be useful,\r
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of\r
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
12 # GNU General Public License for more details.\r
13 #\r
14 # postgres Backend Count\r
15 # Written by: Equinox Software, September 22, 2010 - Lee Dickens\r
16 # Modified by: Equinox Software, March 13, 2014 - Michael Tate\r
17 USAGE="check_backends2 <max_connnections (default 800 if empty)> <pool|pg (default pg if empty)>"\r
18 if [[ $1 == *help* ]]; then\r
19   echo "Usage: $USAGE"\r
20   exit 0\r
21 fi\r
22 \r
23 ## GET/SET Variables ##\r
24 # Use "max_connections" from postgresql.conf\r
25 if [ -n "$1" ]; then\r
26   MAXCX=$1\r
27 else\r
28   MAXCX="800"\r
29 #  MAXCX=`grep max_connections $(find /etc/postgresql/ -name postgresql.conf|tail -n1)` | grep -v "^#"|tr -cd '[[:digit:]]{}'`\r
30 fi\r
31 \r
32 # Platform: plain postgres or pgpool\r
33 if [ -n "$2" ]; then\r
34   PLATCX=$2\r
35 else\r
36   PLATCX="pg"\r
37 fi\r
38 \r
39 if [[ $PLATCX == "pg" ]]; then\r
40  PGCX=$MAXCX\r
41  # PG warn and crit, high and low\r
42  PGCXWL=$(($PGCX/10))           # PostgreSQL number of connections WARN level, low (10% of max)\r
43  PGCXCL=$(($PGCXWL/2))          # PostgreSQL number of connections CRIT level, low (5% of max)\r
44  PGCXC=$(($PGCX-$PGCXWL))    # PostgreSQL number of connections CRIT level, high (90% of max)\r
45  PGCXW=$(($PGCXC-$PGCXWL))       # PostgreSQL number of connections WARN level, high (80% of max)\r
46  PGACT=`ps ax|grep -v grep | grep -c postgres`\r
47 \r
48  if [ $PGACT -lt $PGCXCL ]; then\r
49    EXITSTATUS="CRIT: postgresql backends = $PGACT/$PGCX"\r
50    EXITCODE=2\r
51  elif [ $PGACT -lt $PGCXWL ]; then\r
52    EXITSTATUS="WARN: postgresql backends = $PGACT/$PGCX"\r
53    EXITCODE=1\r
54  elif [ $PGACT -gt $PGCXW ]; then\r
55    EXITSTATUS="WARN: postgresql backends = $PGACT/$PGCX"\r
56    EXITCODE=1\r
57  elif [ $PGACT -gt $PGCXW ]; then\r
58    EXITSTATUS="CRIT: postgresql backends = $PGACT/$PGCX"\r
59    EXITCODE=2\r
60  else\r
61    EXITSTATUS="OK: postgresql backends = $PGACT/$PGCX"\r
62    EXITCODE=0\r
63  fi\r
64 \r
65 elif [[ $PLATCX == "pool" ]]; then\r
66  POOLCX=$MAXCX\r
67  # PGPOOL warn and crit, high and low\r
68  POOLCXWL=$(($PGCX/10))           # PostgreSQL number of connections WARN level, low (10% of max)\r
69  POOLCXCL=$(($PGCXWL/2))          # PostgreSQL number of connections CRIT level, low (5% of max)\r
70  POOLCXC=$(($PGCX-$PGCXWL))    # PostgreSQL number of connections CRIT level, high (90% of max)\r
71  POOLCXW=$(($PGCXC-$PGCXWL))       # PostgreSQL number of connections WARN level, high (80% of max)\r
72  POOLACT=`ps ax|grep -v "wait\|grep" | grep -c pgpool`\r
73 \r
74  if [ $POOLACT -lt $POOLACTCXCL ]; then\r
75    EXITSTATUS="CRIT: postgresql backends = $PGACT/$PGCX and pgpool backends = $POOLACT/$POOLACTCX"\r
76    EXITCODE=2\r
77  elif [ $POOLACT -lt $POOLACTCXWL ]; then\r
78    EXITSTATUS="WARN: postgresql backends = $PGACT/$PGCX and pgpool backends = $POOLACT/$POOLACTCX"\r
79    EXITCODE=1\r
80  elif [ $POOLACT -gt $POOLACTCXC ]; then\r
81    EXITSTATUS="CRIT: postgresql backends = $PGACT/$PGCX and pgpool backends = $POOLACT/$POOLACTCX"\r
82    EXITCODE=2\r
83  elif [ $POOLACT -gt $POOLACTCXW ]; then\r
84    EXITSTATUS="WARN: postgresql backends = $PGACT/$PGCX and pgpool backends = $POOLACT/$POOLACTCX"\r
85    EXITCODE=1\r
86  else\r
87    EXITSTATUS="OK: pgpool backends = $POOLACT/$POOLACTCX"\r
88    EXITCODE=0\r
89  fi\r
90 \r
91 else\r
92   echo "Usage: $USAGE"\r
93   exit 0\r
94 fi\r
95 \r
96 \r
97 echo "$EXITSTATUS"\r
98 exit $EXITCODE\r
99 \r