On Mar 21, 2007, at 5:13 AM, Tobias Brox wrote:
I have my postgres munin monitoring script at
.txt to make the local apache happy).
I would like to see what others have done as well.
I use cacti (
http://cacti.net) which does the same thing that munin does but in php instead. Here's what I use to db stats to it (again, php):
You basically call the script with the database name and the stat you want. I have the active_queries stat set up as a gauge in cacti and the others as counters:
if(!isset($argv[1])) { echo "DB name argument required!\n"; exit();
}
$stats = array('xact_commit', 'xact_rollback', 'blks_read', 'blks_hit', 'active_queries');
if(!isset($argv[2]) || !in_array($argv[2], $stats)) { echo "Invalid stat arg!: {$argv[2]}";
exit();
}
require_once('DB.php');
$db_name = $argv[1];
if(DB::isError($db = DB::connect("pgsql://user@host:5432/$db_name"))) {
exit();
}
if($argv[2] == 'active_queries') {
$actives_sql = "SELECT COUNT(*)
FROM pg_stat_activity
WHERE current_query NOT ILIKE '<idle>'
AND now() - query_start > '1 second';";
if(DB::isError($db_stat = $db->getOne($actives_sql))) {
exit();
}
echo "$db_stat\n";
exit();
}
$db_stat_sql = "SELECT {$argv[2]}
FROM pg_stat_database
WHERE datname='$db_name';";
if(DB::isError($db_stat = $db->getOne($db_stat_sql))) {
exit();
}
echo "$db_stat\n";
software developer
615-296-0838
emma(r)