pgBadger is a Perl script created as a successor to pgFouine. It reads PostgreSQL logfiles and creates a dashboard of basic metrics and log messages that can be useful in analyzing past server performance. The latency of the information is determined by the frequency you run pgBadger across your logs.
I use a simple setup to parse logs with PdBadger and expose them via lighttpd, with directory browsing to view history. Any web server you have laying about would also do - its simple static content.
A cron job calling the following script every 15 minutes generates the current date's page. Specifying a date as an argument creates a page from a past date (I rotate logs daily):
#!/bin/bash
if [ $# -eq 0 ]; then
dt=$(date +%Y-%m-%d)
else
dt=$1
fi
fd=$(date -d "$dt" +%Y%m%d)
pgbadger -T '<a href="/logs">pgBadger</a>' -o /var/www/pglogs/pgsql_${fd}.html /var/lib/pgsql/data/pg_log/postgresql-${dt}_*.log
index="<meta HTTP-EQUIV='REFRESH' content='0; url=logs/pgsql_${fd}.html'>"
echo $index > /var/www/pglogs/index.html
The root of the site displays the current days log information, and the -T parameter creates a link in the page header to the browsable directory of old logs. Lighttpd is in part configured for local directory browsing as:
server.document-root = "/var/www/pglogs"
$HTTP["url"] =~ "^/logs($|/)" {
dir-listing.activate = "enable"
dir-listing.hide-dotfiles = "enable"
dir-listing.exclude = ( "\.sh$", "\.conf$" )
}
index-file.names = ( "index.html" )
Although just a static view on a set of logfiles, the ease of implementation makes this a great way to keep tabs on a database server. Add tail_n_mail, or tie check_postgres into your Ops monitoring platform and you can get notifications when to look at your pgBadger dashboard.