Created
October 8, 2012 21:22
-
-
Save kyle-johnson/3855064 to your computer and use it in GitHub Desktop.
Munin PostgreSQL connections (Bash + psql)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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