Home
Reading
Searching
Subscribe
Sponsors
Statistics
Posting
Contact
Spam
Lists
Links
About
Hosting
Filtering
Features Download
Marketing
Archives
FAQ
Blog
 
Gmane

From: Munin SVN Repository Admin <ilmari-svnadmin-cDshPT+Y4Rxhl2p70BpVqQ <at> public.gmane.org>
Subject: Munin SVN commit: r2388 - in trunk/plugins: lib/Munin/Plugin node.d
Newsgroups: gmane.comp.db.rddtool.munin.scm
Date: Tuesday 1st September 2009 15:17:41 UTC (over 9 years ago)
Author: mha
Date: 2009-09-01 17:17:41 +0200 (Tue, 01 Sep 2009)
New Revision: 2388

Modified:
   trunk/plugins/lib/Munin/Plugin/Pgsql.pm
   trunk/plugins/node.d/postgres_connections_.in
   trunk/plugins/node.d/postgres_connections_db.in
   trunk/plugins/node.d/postgres_locks_.in
   trunk/plugins/node.d/postgres_querylength_.in
   trunk/plugins/node.d/postgres_size_.in
   trunk/plugins/node.d/postgres_transactions_.in
Log:
Update the PostgreSQL plugin framework to the latest version, previous
commit
was accidentally of an old version. This includes: 
 * documentation
 * typo fixes
 * support for version-specific queries
 * support for "minimum version required" plugins
 * support for some more advanced queries, like simple pivoting
 * remove some hardcoded values and bad error messages



Modified: trunk/plugins/lib/Munin/Plugin/Pgsql.pm
===================================================================
--- trunk/plugins/lib/Munin/Plugin/Pgsql.pm	2009-08-31 21:21:46 UTC (rev
2387)
+++ trunk/plugins/lib/Munin/Plugin/Pgsql.pm	2009-09-01 15:17:41 UTC (rev
2388)
@@ -18,8 +18,7 @@
 # 02110-1301 USA.
 
 # This Module is user documented inline, interspersed with code with
-# perlpod.  The documentation for the session() function is the
-# pattern.  Please maintain it in the same way.
+# perlpod.
 
 
 # $Id$
@@ -31,23 +30,49 @@
 =head1 SYNOPSIS
 
 The Munin::Plugin::Pgsql module provides base functionality for all
-PostgreSQL Munin plugins.
+PostgreSQL Munin plugins, including common configuration parameters.
 
 =head1 CONFIGURATION
 
-To Be Done
+All configuration is done through environment variables.
 
-=head1 More documentation needed
+=head1 ENVIRONMENT VARIABLES
 
-There is more documentation here that needs to be written
+All plugins based on Munin::Plugin::Pgsql accepts all the environment
+variables that libpq does. The most common ones used are:
 
+ PGHOST      hostname to connect to, or path to Unix socket
+ PGPORT      port number to connect to
+ PGUSER      username to connect as
+ PGPASSWORD  password to connect with, if a password is required
+
+The plugins will always connect to the 'template1' database.
+
+=head2 Example
+
+ [postgres_*]
+ user=postgres
+ env.PGUSER=postgres
+ env.PGPORT=5433
+
+=head1 WILDCARD MATCHING
+
+Wildcard plugins based on this module will match on whatever type of
object
+specifies for a filter, usually a database. If the object name ALL is used
+(for example, a symlink to postgres_connections_ALL), the filter will not
be
+applied, and the plugin behaves like a non-wildcard one.
+
+=head1 REQUIREMENTS
+
+The module requires DBD::Pg to work.
+
 =head1 TODO
 
-Lots.
+Support for using psql instead of DBD::Pg, to remove dependency.
 
 =head1 BUGS
 
-I'm sure there are plenty.
+No known bugs at this point.
 
 =head1 SEE ALSO
 
@@ -55,17 +80,21 @@
 
 =head1 AUTHOR
 
-Magnus Hagander
+Magnus Hagander , Redpill
Linpro AB
 
 =head1 COPYRIGHT/License.
 
-Copyright (c) 2009 Magnus Hagander.
+Copyright (c) 2009 Magnus Hagander, Redpill Linpro AB
 
 All rights reserved. This program is free software; you can
 redistribute it and/or modify it under the terms of the GNU General
 Public License as published by the Free Software Foundation; version 2
 dated June, 1991.
 
+=head1 API DOCUMENTATION
+
+The following functions are available to plugins using this module.
+
 =cut
 
 package Munin::Plugin::Pgsql;
@@ -73,8 +102,77 @@
 use strict;
 use warnings;
 
-use DBI;
+=head2 Initialization
 
+ use Munin::Plugin::Pgsql;
+ my $pg = Munin::Plugin::Pgsql->new(
+    parameter=>value,
+    parameter=>value
+ );
+
+=head3 Parameters
+
+ minversion     Minimum PostgreSQL version required, formatted like 8.2.
If the
+                database is an older version than this, the plugin will
exit
+                with an error.
+ title          The title for this plugin. Copied directly to the config
output.
+ info           The info for this plugin. Copied directly to the config
output.
+ vlabel         The vertical label for the graph. Copied directly to the
config
+                output.
+ basename       For wildcard plugins, this is the base name of the plugin,
+                including the trailing underscore.
+ basequery      SQL query run to get the plugin values. The query should
return
+                two columns, one being the name of the counter and the
second
+                being the current value for the counter.
+ pivotquery     Set to 1 to indicate that the query in basequery returns a
single
+                row, with one field for each counter. The name of the
counter is
+                taken from the returned column name, and the value from
the
+                first row in the result.
+ configquery    SQL query run to generate the configuration information
for the
+                plugin. The query should return at least two columns,
which are
+                the name of the counter and the label of the counter. If
+                a third column is present, it will be used as the info
+                parameter.
+ suggestquery   SQL query to run to generate the list of suggestions for a
+                wildcard plugin. Don't forget to include ALL if the plugin
+                supports aggregate statistics.
+ graphdraw      The draw parameter for the graph. The default is LINE1.
+ graphtype      The type parameter for the graph. The default is GAUGE.
+ graphperiod    The period for the graph. Copied directly to the config
output.
+ graphmin       The min parameter for the graph. The default is no
minimum.
+ graphmax       The max parameter for the graph. The default is no
maximum.
+ stack          If set to 1, all counters except the first one will be
written
+                with a draw type of STACK.
+ base           Used for graph_args --base. Default is 1000, set to 1024
when
+                returning sizes in Kb for example.
+ wildcardfilter The SQL to substitute for when a wildcard plugin is run
against
+                a specific entity, for example a database. All occurrances
of
+                the string %%FILTER%% will be replaced with this string,
and
+                for each occurance a parameter with the value of the
filtering
+                condition will be added to the DBI statement.
+ extraconfig    This string is copied directly into the configuration
output
+                when the plugin is run in config mode, allowing low-level
+                customization.
+
+=head3 Specifying queries
+
+Queries specified in one of the parameters above can take one of two
forms.
+The easiest one is a simple string, which will then always be executed,
+regardless of server version. The other form is an array, looking like
this:
+ [
+  "SELECT 'default',... FROM ...",
+  [
+    "8.3", "SELECT 'query for 8.3 or earlier',... FROM ...",
+    "8.1", "SELECT 'query for 8.1 or earlier',... FROM ..."
+  ]
+ ]
+This array is parsed from top to bottom, so the entires must be in order
of
+version number. The *last* value found where the version specified is
higher
+than or equal to the version of the server will be used (yes, it counts
+backwards).
+
+=cut
+
 sub new {
     my ($class) = shift;
     my (%args)  = @_;
@@ -87,6 +185,7 @@
 
     my $self = {
         debug          => 0,
+        minversion     => $args{minversion},
         basename       => $args{basename},
         basequery      => $args{basequery},
         title          => $args{title},
@@ -94,11 +193,16 @@
         vlabel         => $args{vlabel},
         graphdraw      => $args{graphdraw},
         graphtype      => $args{graphtype},
+        graphperiod    => $args{graphperiod},
+        graphmin       => $args{graphmin},
+        graphmax       => $args{graphmax},
         stack          => $args{stack},
         configquery    => $args{configquery},
         base           => $args{base},
         wildcardfilter => $args{wildcardfilter},
         suggestquery   => $args{suggestquery},
+        pivotquery     => $args{pivotquery},
+        extraconfig    => $args{extraconfig},
     };
 
     foreach my $k (keys %defaults) {
@@ -111,22 +215,22 @@
 
 sub Config {
     my ($self) = @_;
+
+    $self->ensure_version();
+
     print "graph_title $self->{title}\n";
     print "graph_vlabel $self->{vlabel}\n";
     print "graph_category PostgreSQL\n";
     print "graph_info $self->{info}\n";
-    print "graph_args --base $self->{base}\n";
+    print "graph_args --base $self->{base}";
+    print " -l $self->{graphmin}" if (defined $self->{graphmin});
+    print "\n";
+    print "graph_period $self->{graphperiod}\n" if ($self->{graphperiod});
+    print "$self->{extraconfig}\n"              if ($self->{extraconfig});
 
-    my %rowinfo = ();
-    if ($self->{configquery}) {
-        my $r = $self->runquery($self->{configquery});
-        foreach my $row (@$r) {
-            $rowinfo{$row->[0]} = 1;
-        }
-    }
-
     my $firstrow = 1;
-    foreach my $row (@{$self->runquery($self->{configquery})}) {
+    foreach my $row (
+       
@{$self->runquery($self->get_versioned_query($self->{configquery}))}) {
         my $l = $row->[0];
         print "$l.label $row->[1]\n";
         print "$l.info $row->[2]\n" if (defined $row->[2]);
@@ -137,6 +241,8 @@
         else {
             print "$l.draw $self->{graphdraw}\n";
         }
+        print "$l.min $self->{graphmin}\n" if (defined $self->{graphmin});
+        print "$l.max $self->{graphmax}\n" if (defined $self->{graphmax});
         $firstrow = 0;
     }
 }
@@ -149,6 +255,16 @@
         return 1;
     }
 
+    # Check minimum version, if it applies
+    if ($self->{minversion}) {
+        $self->get_version();
+        if ($self->{detected_version} < $self->{minversion}) {
+            print
+                "no (version $self->{detected_version} is less than the
required $self->{minversion})\n";
+            return 1;
+        }
+    }
+
     # More magic needed?
     print "yes\n";
     return 0;
@@ -157,6 +273,7 @@
 sub Suggest {
     my ($self) = @_;
 
+    $self->ensure_version();
     if ($self->{suggestquery}) {
         my $r = $self->runquery($self->{suggestquery});
         foreach my $row (@$r) {
@@ -169,8 +286,9 @@
 
 sub GetData {
     my ($self) = @_;
+    $self->ensure_version();
     if ($self->{basequery}) {
-        my $q = $self->{basequery};
+        my $q = $self->get_versioned_query($self->{basequery});
         my $w = $self->wildcard_parameter();
         my @p = ();
         if ($w) {
@@ -183,7 +301,7 @@
             # Not called as a wildcard, or called with "all" - remove
filter spec
             $q =~ s/%%FILTER%%//g;
         }
-        my $r = $self->runquery($q, @p);
+        my $r = $self->runquery($q, \@p, $self->{pivotquery});
         foreach my $row (@$r) {
             my $l = $row->[0];
             print $row->[0] . ".value " . $row->[1] . "\n";
@@ -193,6 +311,14 @@
     die "No query configured!";
 }
 
+=head2 Processing
+
+ $pg->Process();
+
+ This command executes the plugin. It will automatically parse the ARGV
array
+ for commands given by Munin.
+
+=cut
 sub Process {
     my ($self) = @_;
 
@@ -234,10 +360,13 @@
 
     return 1 if ($self->{dbh});
 
-    if (eval "require DBD::Pg;") {
+    if (eval "require DBI; require DBD::Pg;") {
 
-        #FIXME: Don't hardcode
-        $self->{dbh} = DBI->connect('DBI:Pg:dbname=postgres;host=/tmp');
+        # Always connect to database template1, because it exists on both
old
+        # and new versions of PostgreSQL.
+        # All other connection parameters are controlled by the libpq
environment
+        # variables.
+        $self->{dbh} = DBI->connect('DBI:Pg:dbname=template1');
         unless ($self->{dbh}) {
             $self->{connecterror} = "$DBI::errstr";
             return 0;
@@ -253,30 +382,96 @@
 }
 
 sub runquery {
-    my ($self, $query, @params) = @_;
+    my ($self, $query, $params, $pivot) = @_;
     $self->connect();
     if ($self->{dbh}) {
 
         # Run query on DBI
         my $s = $self->{dbh}->prepare($query);
-        my $r = $s->execute(@params);
+        my $r = $s->execute(@$params);
         unless ($r) {
             print "Query failed!\n";
             exit(1);
         }
-        return $s->fetchall_arrayref();
+        if ($pivot) {
+
+            # Query returning a single row with one column for each
counter
+            # Turn this into a regular resultset
+            my $r     = [];
+            my @dbrow = $s->fetchrow_array();
+            for (my $i = 0; $i < scalar(@dbrow); $i++) {
+                push @$r, [$s->{NAME}->[$i], $dbrow[$i]];
+            }
+            return $r;
+        }
+        else {
+            return $s->fetchall_arrayref();
+        }
     }
-    print "AIIEH\n";
-    exit(1);
+    die "Don't know how to run without DBI yet!\n";
 }
 
+sub get_version {
+    my ($self) = @_;
+
+    return if (defined $self->{detected_version});
+
+    my $r = $self->runquery("SELECT version()");
+    my $v = $r->[0]->[0];
+    die "Unable to detect PostgreSQL version\n"
+        unless ($v =~ /^PostgreSQL (\d+)\.(\d+)\.(\d+) on/);
+    $self->{detected_version} = "$1.$2";
+}
+
+sub get_versioned_query {
+    my ($self, $query) = @_;
+    $self->get_version();
+    if (ref($query) eq "ARRAY") {
+        my $rq = undef;
+        foreach my $entry (@$query) {
+            if (!defined($rq)) {
+
+                # First row must always be a scalar
+                die "First available query must be unconditional"
+                    unless (ref($entry) eq "");
+                $rq = $entry;
+                next;
+            }
+            die "Non-first available queries must be version conditional!"
+                unless (ref($entry) eq "ARRAY");
+            if ($self->{detected_version} <= @$entry[0]) {
+
+                # We are running against a server that's this version or
older, so change
+                # to using this query.
+                $rq = @$entry[1];
+            }
+        }
+        return $rq;
+    }
+    else {
+        return $query;
+    }
+}
+
+sub ensure_version {
+    my ($self) = @_;
+
+    if ($self->{minversion}) {
+        $self->get_version();
+        if ($self->{detected_version} < $self->{minversion}) {
+            die
+                "This plugin requires PostgreSQL $self->{minversion} or
newer!\n";
+        }
+    }
+}
+
 sub wildcard_parameter {
     my ($self) = @_;
 
     return undef unless (defined $self->{basename});
 
     if ($0 =~ /$self->{basename}(.*)$/) {
-        return undef if ($1 eq "all");
+        return undef if ($1 eq "ALL");
         return $1;
     }
     die "Wildcard base not found in called filename!\n";

Modified: trunk/plugins/node.d/postgres_connections_.in
===================================================================
--- trunk/plugins/node.d/postgres_connections_.in	2009-08-31 21:21:46 UTC
(rev 2387)
+++ trunk/plugins/node.d/postgres_connections_.in	2009-09-01 15:17:41 UTC
(rev 2388)
@@ -1,51 +1,100 @@
 #[email protected]@[email protected]@
-# -*- perl -*-
+# -*- cperl -*-
+#
+# Copyright (C) 2009 Magnus Hagander, Redpill Linpro AB
+#
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License
+# as published by the Free Software Foundation; version 2 dated June,
+# 1991.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+# 02110-1301 USA.
 
 =head1 NAME
 
-postgres_connections - Plugin to monitor number of PostgreSQL database
-connections.
+postgres_connections_ - Plugin to monitor PostgreSQL connections.
 
 =head1 CONFIGURATION
 
-For configuration information, see Munin::Plugins::PgSQL
+Configuration is done through libpq environment variables, for example
+PGUSER, PGDATABASE, etc. For more information, see
L.
 
+To monitor a specific database, link to
postgres_connections_.
+To monitor all databases, link to postgres_connections_ALL.
+
+=head1 SEE ALSO
+
+L
+
 =head1 AUTHOR
 
-Magnus Hagander
+Magnus Hagander , Redpill
Linpro AB
 
-=head1 LICENSE
+=head1 COPYRIGHT/License.
 
-GPL, put more text here :-)
+Copyright (c) 2009 Magnus Hagander, Redpill Linpro AB
 
+All rights reserved. This program is free software; you can
+redistribute it and/or modify it under the terms of the GNU General
+Public License as published by the Free Software Foundation; version 2
+dated June, 1991.
+
 =cut
 
 use strict;
 use warnings;
-use DBI;
 
 use Munin::Plugin::Pgsql;
 
 my $pg = Munin::Plugin::Pgsql->new(
-	basename=>'postgres_connections_',
-        title=>'PostgreSQL connections',
-        info=>'Number of connections',
-        vlabel=>'Connections',
-	basequery=>"SELECT tmp.state,COALESCE(count,0) FROM
-                 (VALUES
('active'),('waiting'),('idle'),('idletransaction')) AS tmp(state)
+    basename  => 'postgres_connections_',
+    title     => 'PostgreSQL connections',
+    info      => 'Number of connections',
+    vlabel    => 'Connections',
+    basequery => [
+        "SELECT tmp.state,COALESCE(count,0) FROM
+                 (VALUES
('active'),('waiting'),('idle'),('idletransaction'),('unknown')) AS
tmp(state)
 	        LEFT JOIN
-                 (SELECT CASE WHEN waiting THEN 'waiting' WHEN
current_query='' THEN 'idle' WHEN current_query=' in
transaction' THEN 'idletransaction' ELSE 'active' END AS state,
+                 (SELECT CASE WHEN waiting THEN 'waiting' WHEN
current_query='' THEN 'idle' WHEN current_query=' in
transaction' THEN 'idletransaction' WHEN current_query='' THEN 'unknown' ELSE 'active' END AS state,
                  count(*) AS count
                  FROM pg_stat_activity WHERE procpid != pg_backend_pid()
%%FILTER%%
-                 GROUP BY CASE WHEN waiting THEN 'waiting' WHEN
current_query='' THEN 'idle' WHEN current_query=' in
transaction' THEN 'idletransaction' ELSE 'active' END
+                 GROUP BY CASE WHEN waiting THEN 'waiting' WHEN
current_query='' THEN 'idle' WHEN current_query=' in
transaction' THEN 'idletransaction' WHEN current_query='' THEN 'unknown' ELSE 'active' END
                  ) AS tmp2
                 ON tmp.state=tmp2.state
                 ORDER BY 1
-		",
-	wildcardfilter=>" AND datname=?",
-	configquery=>"VALUES ('active','Active'),('waiting','Waiting for
lock'),('idle','Idle'),('idletransaction','Idle in transaction')",
-	suggestquery=>"SELECT datname FROM pg_database WHERE datallowconn UNION
ALL SELECT 'all' ORDER BY 1",
-	stack=>1
+		", [
+            8.1, "SELECT tmp.state,COALESCE(count,0) FROM
+                 (SELECT 'active' UNION ALL SELECT 'idle' UNION ALL SELECT
'idletransaction' UNION ALL SELECT 'unknown') AS tmp(state)
+	        LEFT JOIN
+                 (SELECT CASE WHEN current_query='' THEN 'idle' WHEN
current_query=' in transaction' THEN 'idletransaction' WHEN
current_query='' THEN 'unknown' ELSE 'active' END
AS state,
+                 count(*) AS count
+                 FROM pg_stat_activity WHERE procpid != pg_backend_pid()
%%FILTER%%
+                 GROUP BY CASE WHEN current_query='' THEN 'idle'
WHEN current_query=' in transaction' THEN 'idletransaction' WHEN
current_query='' THEN 'unknown' ELSE 'active' END
+                 ) AS tmp2
+                ON tmp.state=tmp2.state
+                ORDER BY 1"
+        ]
+    ],
+    wildcardfilter => " AND datname=?",
+    configquery    => [
+        "VALUES ('active','Active'),('waiting','Waiting for
lock'),('idle','Idle'),('idletransaction','Idle in
transaction'),('unknown','Unknown')",
+        [
+            8.1,
+            "SELECT 'active','Active' UNION ALL SELECT 'idle','Idle' UNION
ALL SELECT 'idletransaction','Idle in transaction' UNION ALL SELECT
'unknown','Unknown'"
+        ]
+    ],
+    suggestquery =>
+        "SELECT datname FROM pg_database WHERE datallowconn AND NOT
datistemplate AND NOT datname='postgres' UNION ALL SELECT 'ALL' ORDER BY 1
LIMIT 10",
+    graphdraw => 'AREA',
+    stack => 1
 );
 
 $pg->Process();

Modified: trunk/plugins/node.d/postgres_connections_db.in
===================================================================
--- trunk/plugins/node.d/postgres_connections_db.in	2009-08-31 21:21:46 UTC
(rev 2387)
+++ trunk/plugins/node.d/postgres_connections_db.in	2009-09-01 15:17:41 UTC
(rev 2388)
@@ -1,37 +1,65 @@
 #[email protected]@[email protected]@
-# -*- perl -*-
+# -*- cperl -*-
+#
+# Copyright (C) 2009 Magnus Hagander, Redpill Linpro AB
+#
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License
+# as published by the Free Software Foundation; version 2 dated June,
+# 1991.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+# 02110-1301 USA.
 
 =head1 NAME
 
-postgres_connections_db - Plugin to monitor number of PostgreSQL database
-connections per database.
+postgres_connections_db - Plugin to monitor PostgreSQL connections per
+database.
 
 =head1 CONFIGURATION
 
-For configuration information, see Munin::Plugins::PgSQL
+Configuration is done through libpq environment variables, for example
+PGUSER, PGDATABASE, etc. For more information, see
L.
 
+=head1 SEE ALSO
+
+L
+
 =head1 AUTHOR
 
-Magnus Hagander
+Magnus Hagander , Redpill
Linpro AB
 
-=head1 LICENSE
+=head1 COPYRIGHT/License.
 
-GPL, put more text here :-)
+Copyright (c) 2009 Magnus Hagander, Redpill Linpro AB
 
+All rights reserved. This program is free software; you can
+redistribute it and/or modify it under the terms of the GNU General
+Public License as published by the Free Software Foundation; version 2
+dated June, 1991.
+
 =cut
 
 use strict;
 use warnings;
-use DBI;
 
 use Munin::Plugin::Pgsql;
 
 my $pg = Munin::Plugin::Pgsql->new(
-        title=>'PostgreSQL connections per database',
-        info=>'Number of connections per database',
-        vlabel=>'Connections',
-        basequery=>"SELECT pg_database.datname,COALESCE(count,0) AS count
FROM pg_database LEFT JOIN (SELECT datname,count(*) FROM pg_stat_activity
WHERE procpid != pg_backend_pid() GROUP BY datname) AS tmp ON
pg_database.datname=tmp.datname ORDER BY 1",
-        configquery=>"SELECT datname,datname FROM pg_database WHERE
datallowconn ORDER BY 1",
+    title  => 'PostgreSQL connections per database',
+    info   => 'Number of connections per database',
+    vlabel => 'Connections',
+    basequery =>
+        "SELECT pg_database.datname,COALESCE(count,0) AS count FROM
pg_database LEFT JOIN (SELECT datname,count(*) FROM pg_stat_activity WHERE
procpid != pg_backend_pid() GROUP BY datname) AS tmp ON
pg_database.datname=tmp.datname WHERE datallowconn ORDER BY 1",
+    configquery =>
+        "SELECT datname,datname FROM pg_database WHERE datallowconn ORDER
BY 1",
 );
 
 $pg->Process();

Modified: trunk/plugins/node.d/postgres_locks_.in
===================================================================
--- trunk/plugins/node.d/postgres_locks_.in	2009-08-31 21:21:46 UTC (rev
2387)
+++ trunk/plugins/node.d/postgres_locks_.in	2009-09-01 15:17:41 UTC (rev
2388)
@@ -1,38 +1,70 @@
 #[email protected]@[email protected]@
-# -*- perl -*-
+# -*- cperl -*-
+#
+# Copyright (C) 2009 Magnus Hagander, Redpill Linpro AB
+#
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License
+# as published by the Free Software Foundation; version 2 dated June,
+# 1991.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+# 02110-1301 USA.
 
 =head1 NAME
 
-postgres_locks - Plugin to monitor size of PostgreSQL locks.
+postgres_locks_ - Plugin to monitor PostgreSQL locks.
 
 =head1 CONFIGURATION
 
-For configuration information, see Munin::Plugins::PgSQL
+Configuration is done through libpq environment variables, for example
+PGUSER, PGDATABASE, etc. For more information, see
L.
 
+To monitor a specific database, link to postgres_locks_.
+To monitor all databases, link to postgres_locks_ALL.
+
+=head1 SEE ALSO
+
+L
+
 =head1 AUTHOR
 
-Magnus Hagander
+Magnus Hagander , Redpill
Linpro AB
 
-=head1 LICENSE
+=head1 COPYRIGHT/License.
 
-GPL, put more text here :-)
+Copyright (c) 2009 Magnus Hagander, Redpill Linpro AB
 
+All rights reserved. This program is free software; you can
+redistribute it and/or modify it under the terms of the GNU General
+Public License as published by the Free Software Foundation; version 2
+dated June, 1991.
+
 =cut
 
 use strict;
 use warnings;
-use DBI;
 
 use Munin::Plugin::Pgsql;
 
 my $pg = Munin::Plugin::Pgsql->new(
-        basename=>'postgres_locks_',
-        title=>'PostgreSQL locks',
-        info=>'PostgreSQL locks',
-        vlabel=>'Locks',
-        basequery=>"SELECT lower(mode),count(*) FROM pg_locks WHERE
database IS NOT NULL %%FILTER%% GROUP BY lower(mode) ORDER BY 1",
-        wildcardfilter=>"AND database=(SELECT oid FROM pg_database WHERE
datname=?)",
-        configquery=>"VALUES
+    basename => 'postgres_locks_',
+    title    => 'PostgreSQL locks',
+    info     => 'PostgreSQL locks',
+    vlabel   => 'Locks',
+    basequery =>
+        "SELECT lower(mode),count(*) FROM pg_locks WHERE database IS NOT
NULL %%FILTER%% GROUP BY lower(mode) ORDER BY 1",
+    wildcardfilter =>
+        "AND database=(SELECT oid FROM pg_database WHERE datname=?)",
+    configquery => [
+        "VALUES
          ('accesssharelock','AccessShareLock','Used by read only
queries'),
          ('rowsharelock','RowShareLock','Used by SELECT FOR SHARE and
SELECT FOR UPDATE queries'),
          ('rowexclusivelock','RowExclusiveLock','Used by UPDATE, DELETE
and INSERT queries'),
@@ -41,8 +73,22 @@
          ('sharerowexclusivelock','ShareRowExclusiveLock','Only issued
explicitly from applications'),
          ('exclusivelock','ExclusiveLock','Infrequently issued on system
tables, or by applications'),
          ('accessexclusivelock','AccessExclusiveLock','Used by ALTER
TABLE, DROP TABLE, TRUNCATE, REINDEX, CLUSTER and VACUUM FULL queries')",
-	graphdraw=>'AREA',
-	stack=>1,
+        [
+            8.1,
+            "SELECT 'accesssharelock','AccessShareLock','Used by read only
queries' UNION ALL
+            SELECT 'rowsharelock','RowShareLock','Used by SELECT FOR SHARE
and SELECT FOR UPDATE queries' UNION ALL
+            SELECT 'rowexclusivelock','RowExclusiveLock','Used by UPDATE,
DELETE and INSERT queries' UNION ALL
+            SELECT
'shareupdateexclusivelock','ShareUpdateExclusiveLock','Used by VACUUM,
ANALYZE and CREATE INDEX CONCURRENTLY queries' UNION ALL
+            SELECT 'sharelock','ShareLock','Used by CREATE INDEX queries'
UNION ALL
+            SELECT 'sharerowexclusivelock','ShareRowExclusiveLock','Only
issued explicitly from applications' UNION ALL
+            SELECT 'exclusivelock','ExclusiveLock','Infrequently issued on
system tables, or by applications' UNION ALL
+            SELECT 'accessexclusivelock','AccessExclusiveLock','Used by
ALTER TABLE, DROP TABLE, TRUNCATE, REINDEX, CLUSTER and VACUUM FULL
queries'"
+        ]
+    ],
+    suggestquery =>
+        "SELECT datname FROM pg_database WHERE datallowconn AND NOT
datistemplate AND NOT datname='postgres' UNION ALL SELECT 'ALL' ORDER BY 1
LIMIT 10",
+    graphdraw => 'AREA',
+    stack     => 1,
 );
 
 $pg->Process();

Modified: trunk/plugins/node.d/postgres_querylength_.in
===================================================================
--- trunk/plugins/node.d/postgres_querylength_.in	2009-08-31 21:21:46 UTC
(rev 2387)
+++ trunk/plugins/node.d/postgres_querylength_.in	2009-09-01 15:17:41 UTC
(rev 2388)
@@ -1,42 +1,82 @@
 #[email protected]@[email protected]@
-# -*- perl -*-
+# -*- cperl -*-
+#
+# Copyright (C) 2009 Magnus Hagander, Redpill Linpro AB
+#
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License
+# as published by the Free Software Foundation; version 2 dated June,
+# 1991.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+# 02110-1301 USA.
 
 =head1 NAME
 
-postgres_queryage - Plugin to monitor length of PostgreSQL queries.
+postgres_querylength_ - Plugin to monitor PostgreSQL long running queries.
 
 =head1 CONFIGURATION
 
-For configuration information, see Munin::Plugins::PgSQL
+Configuration is done through libpq environment variables, for example
+PGUSER, PGDATABASE, etc. For more information, see
L.
 
+To monitor a specific database, link to
postgres_querylength_.
+To monitor all databases, link to postgres_querylength_ALL.
+
+=head1 SEE ALSO
+
+L
+
 =head1 AUTHOR
 
-Magnus Hagander
+Magnus Hagander , Redpill
Linpro AB
 
-=head1 LICENSE
+=head1 COPYRIGHT/License.
 
-GPL, put more text here :-)
+Copyright (c) 2009 Magnus Hagander, Redpill Linpro AB
 
+All rights reserved. This program is free software; you can
+redistribute it and/or modify it under the terms of the GNU General
+Public License as published by the Free Software Foundation; version 2
+dated June, 1991.
+
 =cut
 
 use strict;
 use warnings;
-use DBI;
 
 use Munin::Plugin::Pgsql;
 
 my $pg = Munin::Plugin::Pgsql->new(
-	basename=>'postgres_querylength_',
-        title=>'PostgreSQL query length',
-        info=>'Most long-running queries and transactions',
-        vlabel=>'Length (seconds)',
-        basequery=>"SELECT 'query',COALESCE(max(extract(epoch FROM
CURRENT_TIMESTAMP-query_start)),0) FROM pg_stat_activity %%FILTER%%
+    basename  => 'postgres_querylength_',
+    title     => 'PostgreSQL query length',
+    info      => 'Most long-running queries and transactions',
+    vlabel    => 'Age (seconds)',
+    basequery => [
+        "SELECT 'query',COALESCE(max(extract(epoch FROM
CURRENT_TIMESTAMP-query_start)),0) FROM pg_stat_activity WHERE
current_query NOT LIKE '" WHERE datname=?",
-	configquery=>"VALUES ('query','Oldest query'),('transaction','Oldest
transaction')",
-	suggestquery=>"SELECT datname FROM pg_database WHERE datallowconn UNION
ALL SELECT 'all' ORDER BY 1",
-	stack=>1
+        [
+            8.2,
+            "SELECT 'query',COALESCE(max(extract(epoch FROM
CURRENT_TIMESTAMP-query_start)),0) FROM pg_stat_activity WHERE
current_query NOT LIKE ' " AND datname=?",
+    configquery    => [
+        "VALUES ('query','Oldest query'),('transaction','Oldest
transaction')",
+        [8.2, "VALUES ('query','Oldest query')"],
+        [8.1, "SELECT 'query','Oldest query'"]
+    ],
+    suggestquery =>
+        "SELECT datname FROM pg_database WHERE datallowconn AND NOT
datistemplate AND NOT datname='postgres' UNION ALL SELECT 'ALL' ORDER BY 1
LIMIT 10",
+    stack => 1
 );
 
 $pg->Process();

Modified: trunk/plugins/node.d/postgres_size_.in
===================================================================
--- trunk/plugins/node.d/postgres_size_.in	2009-08-31 21:21:46 UTC (rev
2387)
+++ trunk/plugins/node.d/postgres_size_.in	2009-09-01 15:17:41 UTC (rev
2388)
@@ -1,41 +1,73 @@
 #[email protected]@[email protected]@
-# -*- perl -*-
+# -*- cperl -*-
+#
+# Copyright (C) 2009 Magnus Hagander, Redpill Linpro AB
+#
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License
+# as published by the Free Software Foundation; version 2 dated June,
+# 1991.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+# 02110-1301 USA.
 
 =head1 NAME
 
-postgres_size - Plugin to monitor size of PostgreSQL databases.
+postgres_size_ - Plugin to monitor PostgreSQL database size.
 
 =head1 CONFIGURATION
 
-For configuration information, see Munin::Plugins::PgSQL
+Configuration is done through libpq environment variables, for example
+PGUSER, PGDATABASE, etc. For more information, see
L.
 
+To monitor a specific database, link to postgres_size_.
+To monitor all databases, link to postgres_size_ALL.
+
+=head1 SEE ALSO
+
+L
+
 =head1 AUTHOR
 
-Magnus Hagander
+Magnus Hagander , Redpill
Linpro AB
 
-=head1 LICENSE
+=head1 COPYRIGHT/License.
 
-GPL, put more text here :-)
+Copyright (c) 2009 Magnus Hagander, Redpill Linpro AB
 
+All rights reserved. This program is free software; you can
+redistribute it and/or modify it under the terms of the GNU General
+Public License as published by the Free Software Foundation; version 2
+dated June, 1991.
+
 =cut
 
 use strict;
 use warnings;
-use DBI;
 
 use Munin::Plugin::Pgsql;
 
 my $pg = Munin::Plugin::Pgsql->new(
-        basename=>'postgres_size_',
-        title=>'PostgreSQL database size',
-        info=>'Size of database',
-        vlabel=>'Size',
-        basequery=>"SELECT datname,pg_database_size(oid) FROM pg_database
%%FILTER%% ORDER BY 1",
-        wildcardfilter=>"WHERE datname=?",
-        configquery=>"SELECT datname,datname FROM pg_database ORDER BY 1",
-	graphdraw=>'AREA',
-	stack=>1,
-	base=>1024
+    basename => 'postgres_size_',
+    title    => 'PostgreSQL database size',
+    info     => 'Size of database',
+    vlabel   => 'Size',
+    basequery =>
+        "SELECT datname,pg_database_size(oid) FROM pg_database %%FILTER%%
ORDER BY 1",
+    wildcardfilter => "WHERE datname=?",
+    configquery    => "SELECT datname,datname FROM pg_database ORDER BY
1",
+    suggestquery =>
+        "SELECT datname FROM pg_database WHERE datallowconn AND NOT
datistemplate AND NOT datname='postgres' UNION ALL SELECT 'ALL' ORDER BY 1
LIMIT 10",
+    graphdraw => 'AREA',
+    stack     => 1,
+    base      => 1024
 );
 
 $pg->Process();

Modified: trunk/plugins/node.d/postgres_transactions_.in
===================================================================
--- trunk/plugins/node.d/postgres_transactions_.in	2009-08-31 21:21:46 UTC
(rev 2387)
+++ trunk/plugins/node.d/postgres_transactions_.in	2009-09-01 15:17:41 UTC
(rev 2388)
@@ -1,43 +1,82 @@
 #[email protected]@[email protected]@
-# -*- perl -*-
+# -*- cperl -*-
+#
+# Copyright (C) 2009 Magnus Hagander, Redpill Linpro AB
+#
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License
+# as published by the Free Software Foundation; version 2 dated June,
+# 1991.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+# 02110-1301 USA.
 
 =head1 NAME
 
-postgres_transactions - Plugin to monitor number of PostgreSQL
transactions.
+postgres_transactions_ - Plugin to monitor PostgreSQL transactions.
 
 =head1 CONFIGURATION
 
-For configuration information, see Munin::Plugins::PgSQL
+Configuration is done through libpq environment variables, for example
+PGUSER, PGDATABASE, etc. For more information, see
L.
 
+To monitor a specific database, link to postgres_size_.
+To monitor all databases, link to postgres_size_ALL.
+
+=head1 SEE ALSO
+
+L
+
 =head1 AUTHOR
 
-Magnus Hagander
+Magnus Hagander , Redpill
Linpro AB
 
-=head1 LICENSE
+=head1 COPYRIGHT/License.
 
-GPL, put more text here :-)
+Copyright (c) 2009 Magnus Hagander, Redpill Linpro AB
 
+All rights reserved. This program is free software; you can
+redistribute it and/or modify it under the terms of the GNU General
+Public License as published by the Free Software Foundation; version 2
+dated June, 1991.
+
 =cut
 
 use strict;
 use warnings;
-use DBI;
 
 use Munin::Plugin::Pgsql;
 
 my $pg = Munin::Plugin::Pgsql->new(
-        basename=>'postgres_transactions_',
-        title=>'PostgreSQL transactions',
-        info=>'Transactions per second',
-        vlabel=>'Trans / sec',
-        basequery=>"SELECT 'commit',sum(pg_stat_get_db_xact_commit(oid))
FROM pg_database %%FILTER%% 
+    basename => 'postgres_transactions_',
+    title    => 'PostgreSQL transactions',
+    info     => 'Transactions per second',
+    vlabel   => 'Trans / sec',
+    basequery =>
+        "SELECT 'commit',sum(pg_stat_get_db_xact_commit(oid)) FROM
pg_database %%FILTER%%
                      UNION ALL
                     SELECT
'rollback',sum(pg_stat_get_db_xact_rollback(oid)) FROM pg_database
%%FILTER%%",
-        wildcardfilter=>"WHERE datname=?",
-        configquery=>"VALUES ('commit','Committed
transactions'),('rollback','Rolled back transactions')",
-	suggestquery=>"SELECT datname FROM pg_database WHERE datallowconn UNION
ALL SELECT 'all' ORDER BY 1",
-	stack=>1,
-	graphtype=>'DERIVE'
+    wildcardfilter => "WHERE datname=?",
+    configquery    => [
+        "VALUES ('commit','Committed transactions'),('rollback','Rolled
back transactions')",
+        [
+            8.1,
+            "SELECT 'commit','Committed transactions' UNION ALL SELECT
'rollback','Rolled back transactions'"
+        ]
+    ],
+    suggestquery =>
+        "SELECT datname FROM pg_database WHERE datallowconn AND NOT
datistemplate AND NOT datname='postgres' UNION ALL SELECT 'ALL' ORDER BY 1
LIMIT 10",
+    stack     => 1,
+    graphmin  => 0,
+    graphdraw => 'AREA',
+    graphtype => 'DERIVE'
 );
 
 $pg->Process();


------------------------------------------------------------------------------
Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day

trial. Simplify your report design, integration and deployment - and focus
on 
what you do best, core application coding. Discover what's new with 
Crystal Reports now.  http://p.sf.net/sfu/bobj-july
 
CD: 5ms