nagios -- number of postgres connections

Started by Whit Armstrongalmost 17 years ago7 messagesgeneral
Jump to latest
#1Whit Armstrong
armstrong.whit@gmail.com

anyone know a way to get nagios to monitor the number of postgres connections?

Thanks,
Whit

#2John R Pierce
pierce@hogranch.com
In reply to: Whit Armstrong (#1)
Re: nagios -- number of postgres connections

Whit Armstrong wrote:

anyone know a way to get nagios to monitor the number of postgres connections?

a script that counts how many lines of postgres processes there are and
subtracts a few....

$ ps -C postmaster uww
USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND
postgres 2878 0.0 0.1 152036 1500 ? S Apr05 22:48
/usr/bin/postmaster -p 5432 -D /var/lib/pgsql/data
postgres 3941 0.0 0.0 13056 460 ? Ss Apr05 0:11
postgres: logger process
postgres 3944 0.0 8.4 152192 87196 ? Ss Apr05 1:35
postgres: writer process
postgres 3945 0.0 0.0 152192 684 ? Ss Apr05 0:10
postgres: wal writer process
postgres 3946 0.0 0.1 152980 1380 ? Ss Apr05 29:13
postgres: autovacuum launcher process
postgres 3947 0.1 0.0 13916 1020 ? Ss Apr05 118:23
postgres: stats collector process

so there's one connection there, and the others are the fixed processes.

#3Jeff Frost
jeff@frostconsultingllc.com
In reply to: John R Pierce (#2)
Re: nagios -- number of postgres connections

John R Pierce wrote:

Whit Armstrong wrote:

anyone know a way to get nagios to monitor the number of postgres
connections?

Check out the check_postgres nagios plugin:
http://bucardo.org/check_postgres/

Specifically you want the backends check:
http://bucardo.org/check_postgres/check_postgres.pl.html#backends

--
Jeff Frost, Owner <jeff@frostconsultingllc.com>
Frost Consulting, LLC http://www.frostconsultingllc.com/
Phone: 916-647-6411 FAX: 916-405-4032

#4Scott Mead
scott.mead@enterprisedb.com
In reply to: John R Pierce (#2)
Re: nagios -- number of postgres connections

On Tue, Jun 16, 2009 at 11:32 PM, John R Pierce <pierce@hogranch.com> wrote:

Whit Armstrong wrote:

anyone know a way to get nagios to monitor the number of postgres
connections?

You could also login to the database and run:

select count(1) from pg_stat_activity;

--Scott

#5Scott Mead
scott.lists@enterprisedb.com
In reply to: John R Pierce (#2)
Re: nagios -- number of postgres connections

On Tue, Jun 16, 2009 at 11:32 PM, John R Pierce <pierce@hogranch.com> wrote:

Whit Armstrong wrote:

anyone know a way to get nagios to monitor the number of postgres
connections?

You could also login to the database and run:

select count(1) from pg_stat_activity;

--Scott

#6Rafael Martinez
r.m.guerrero@usit.uio.no
In reply to: Whit Armstrong (#1)
Re: nagios -- number of postgres connections

Whit Armstrong wrote:

anyone know a way to get nagios to monitor the number of postgres connections?

Thanks,
Whit

Hello

We use this plugin. Save it under /etc/munin/plugins/pg_connections and
update the file /etc/munin/plugin-conf.d/postgres with:

-------------------
[pg_connection]
user postgres
-------------------

-------------------------------------------------
#!/bin/sh
#
# Plugin to monitor PostgreSQL connections.
#
# Parameters:
#
# config (required)
# autoconf (optional - only used by munin-config)
#
# Magic markers (optional - used by munin-config and some installation
# scripts):
#%# family=auto
#%# capabilities=autoconf

PID_FILE="/var/lib/pgsql/data/postmaster.pid"

if [ "$1" = "autoconf" ]; then
if [ -f $PID_FILE ]; then
echo yes
exit 0
else
echo "no (Service not running)"
exit 1
fi
else
if [ "$1" = "suggest" ]; then
ls -1 /tmp/
exit 0
fi
fi

if [ "$1" = "config" ]; then

echo "graph_title Number of connections to the database"
echo 'graph_args -l 0 '
echo 'graph_vlabel Number of PostgreSQL connections'
echo 'graph_category PostgreSQL'
echo 'graph_period second'
echo 'graph_info The number of opened connections to PostgreSQL.'
echo 'established.label established'
echo 'established.type GAUGE'
echo 'established.max 500'
echo 'established.info The number of currently open connections.'
exit 0
fi

printf 'established.value '
/usr/bin/psql template1 -At -c "SELECT count(*) FROM pg_stat_activity"
-------------------------------------------------

PS.- You have to update the PATHS with the values in your system, and
the user postgres needs access to your database, for this plugin to work.

regards,
--
Rafael Martinez, <r.m.guerrero@usit.uio.no>
Center for Information Technology Services
University of Oslo, Norway

PGP Public Key: http://folk.uio.no/rafael/

#7Rafael Martinez
r.m.guerrero@usit.uio.no
In reply to: Rafael Martinez (#6)
Re: nagios -- number of postgres connections

Rafael Martinez wrote:

Whit Armstrong wrote:

anyone know a way to get nagios to monitor the number of postgres connections?

Thanks,
Whit

Hello

We use this plugin. Save it under /etc/munin/plugins/pg_connections and
update the file /etc/munin/plugin-conf.d/postgres with:

And of course this is for munin and not nagios. Sorry.

--
Rafael Martinez, <r.m.guerrero@usit.uio.no>
Center for Information Technology Services
University of Oslo, Norway

PGP Public Key: http://folk.uio.no/rafael/