Repository
Munin (master)
Last change
2018-04-07
Family
auto
Capabilities
Language
Perl
License
PostgreSQL
Authors

postgres_connections_db

Name

postgres_connections_db - Plugin to monitor PostgreSQL connections per database.

Configuration

Configuration is done through libpq environment variables, for example PGUSER, PGDATABASE, etc. For more information, see Munin::Plugin::Pgsql.

To monitor several instances, link to postgres_<tag>_connections_db The <tag> can be what you want but without “_”. It allows you to define several database configuration.

Example : [postgres_pg91_*] env.PGPORT 5432 [postgres_pg92_*] env.PGPORT 5432

See Also

Munin::Plugin::Pgsql

Magic Markers

#%# family=auto
#%# capabilities=autoconf

Author

Magnus Hagander magnus@hagander.net, Redpill Linpro AB

Copyright/License.

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.

#!/usr/bin/perl
#
# 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 PostgreSQL connections per
database.

=head1 CONFIGURATION

Configuration is done through libpq environment variables, for example
PGUSER, PGDATABASE, etc. For more information, see L<Munin::Plugin::Pgsql>.

To monitor several instances, link to postgres_<tag>_connections_db
The <tag> can be what you want but without "_". It allows you to define several
database configuration.

Example :
  [postgres_pg91_*]
  env.PGPORT 5432
  [postgres_pg92_*]
  env.PGPORT 5432

=head1 SEE ALSO

L<Munin::Plugin::Pgsql>

=head1 MAGIC MARKERS

 #%# family=auto
 #%# capabilities=autoconf

=head1 AUTHOR

Magnus Hagander <magnus@hagander.net>, Redpill Linpro AB

=head1 COPYRIGHT/License.

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 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 pid != pg_backend_pid() GROUP BY datname) AS tmp ON pg_database.datname=tmp.datname WHERE datallowconn ORDER BY 1",
        [ 9.4,
            "SELECT pg_database.datname,COALESCE(count,0) AS count FROM pg_database LEFT JOIN (SELECT datname,count(*) FROM pg_stat_activity WHERE pid != pg_backend_pid() GROUP BY datname) AS tmp ON pg_database.datname=tmp.datname WHERE datallowconn ORDER BY 1",
        ],
        [ 9.1,
            "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();