2 # Copyright (C) 2008-2010 Equinox Software, Inc.
\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
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
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
23 ## GET/SET Variables ##
\r
24 # Use "max_connections" from postgresql.conf
\r
25 if [ -n "$1" ]; then
\r
29 # MAXCX=`grep max_connections $(find /etc/postgresql/ -name postgresql.conf|tail -n1)` | grep -v "^#"|tr -cd '[[:digit:]]{}'`
\r
32 # Platform: plain postgres or pgpool
\r
33 if [ -n "$2" ]; then
\r
39 if [[ $PLATCX == "pg" ]]; then
\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
48 if [ $PGACT -lt $PGCXCL ]; then
\r
49 EXITSTATUS="CRIT: postgresql backends = $PGACT/$PGCX"
\r
51 elif [ $PGACT -lt $PGCXWL ]; then
\r
52 EXITSTATUS="WARN: postgresql backends = $PGACT/$PGCX"
\r
54 elif [ $PGACT -gt $PGCXW ]; then
\r
55 EXITSTATUS="WARN: postgresql backends = $PGACT/$PGCX"
\r
57 elif [ $PGACT -gt $PGCXW ]; then
\r
58 EXITSTATUS="CRIT: postgresql backends = $PGACT/$PGCX"
\r
61 EXITSTATUS="OK: postgresql backends = $PGACT/$PGCX"
\r
65 elif [[ $PLATCX == "pool" ]]; then
\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
74 if [ $POOLACT -lt $POOLACTCXCL ]; then
\r
75 EXITSTATUS="CRIT: postgresql backends = $PGACT/$PGCX and pgpool backends = $POOLACT/$POOLACTCX"
\r
77 elif [ $POOLACT -lt $POOLACTCXWL ]; then
\r
78 EXITSTATUS="WARN: postgresql backends = $PGACT/$PGCX and pgpool backends = $POOLACT/$POOLACTCX"
\r
80 elif [ $POOLACT -gt $POOLACTCXC ]; then
\r
81 EXITSTATUS="CRIT: postgresql backends = $PGACT/$PGCX and pgpool backends = $POOLACT/$POOLACTCX"
\r
83 elif [ $POOLACT -gt $POOLACTCXW ]; then
\r
84 EXITSTATUS="WARN: postgresql backends = $PGACT/$PGCX and pgpool backends = $POOLACT/$POOLACTCX"
\r
87 EXITSTATUS="OK: pgpool backends = $POOLACT/$POOLACTCX"
\r
92 echo "Usage: $USAGE"
\r