Re: OT: Munin (was Re: Determining server load from client)

From: Erik Jones <erik(at)myemma(dot)com>
To: Tobias Brox <tobias(at)nordicbet(dot)com>
Cc: Richard Huxton <dev(at)archonet(dot)com>, Joe Healy <joe(at)omc-international(dot)com(dot)au>, Dan Harris <fbsd(at)drivefaster(dot)net>, PostgreSQL Performance <pgsql-performance(at)postgresql(dot)org>
Subject: Re: OT: Munin (was Re: Determining server load from client)
Date: 2007-03-21 14:31:48
Message-ID: 2B568D22-BDCC-40B7-B27D-0F47216094F2@myemma.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-performance


On Mar 21, 2007, at 5:13 AM, Tobias Brox wrote:

> I have my postgres munin monitoring script at
> http://oppetid.no/~tobixen/pg_activity.munin.txt (had to suffix it
> with
> .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(at)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";

erik jones <erik(at)myemma(dot)com>
software developer
615-296-0838
emma(r)

In response to

Responses

Browse pgsql-performance by date

  From Date Subject
Next Message Tobias Brox 2007-03-21 21:13:05 Re: OT: Munin (was Re: Determining server load from client)
Previous Message Richard Huxton 2007-03-21 10:36:05 Re: OT: Munin (was Re: Determining server load from client)