Skip to content

Instantly share code, notes, and snippets.

@kyle-johnson
Created October 8, 2012 21:22
Show Gist options
  • Save kyle-johnson/3855064 to your computer and use it in GitHub Desktop.
Save kyle-johnson/3855064 to your computer and use it in GitHub Desktop.
Munin PostgreSQL connections (Bash + psql)
#!/bin/bash
dbserver='localhost'
dbuser='postgres'
psql='/usr/local/pgsql/bin/psql'
if [ "$1" = "config" ]; then
echo 'graph_args --base 1000 --lower-limit 0'
echo 'graph_category Postgresql'
echo 'graph_info Shows active Postgresql connections'
echo 'graph_title PostgreSQL active connections'
echo 'graph_vlabel Connections'
${psql} -h ${dbserver} -U ${dbuser} -tc "SELECT datname FROM pg_database ORDER BY 1;" | while read name
do
test -z "${name}" && continue
echo ${name}'.label '${name}' active connections'
echo ${name}'.info '${name}' active connections'
echo ${name}'.type GAUGE'
echo ${name}'.draw AREASTACK'
done
exit 0
fi
echo -e $(${psql} -U ${dbuser} -Atc "select '\n'||pg_database.datname||'.value '||count(pg_stat_activity.datname) from pg_database left outer join pg_stat_activity on pg_database.datname = pg_stat_activity.datname group by pg_database.datname;")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment