This file is indexed.

/usr/share/munin/plugins/pgbouncer_connections is in munin-plugins-core 2.0.25-1+deb8u3.

This file is owned by root:root, with mode 0o755.

The actual contents of the file can be viewed below.

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
#!/usr/bin/perl
# -*- cperl -*-
#
# Copyright (C) 2010 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

pgbouncer_connections - Plugin to monitor pgbouncer connections.

=head1 CONFIGURATION

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

=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) 2010 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       => 'PgBouncer connections',
    info        => 'Number of connections',
    vlabel      => 'Connections',
    defaultdb   => 'pgbouncer',
    basequery   => "SHOW POOLS",
    postprocess => \&PgBouncerPoolCounter,
    configquery => "SHOW POOLS",
    postconfig  => \&PgBouncerPoolConfig,
);

$pg->Process();

sub PgBouncerPoolConfig {
    my $pgresult = shift;

    return [
        ["cl_active",  "Active clients"],
        ["cl_waiting", "Waiting clients"],
        ["sv_active",  "Active servers"],
        ["sv_idle",    "Idle servers"],
    ];
}

sub PgBouncerPoolCounter {
    my $pgresult = shift;

    my ($cl_active, $cl_waiting, $sv_active, $sv_idle) = (0, 0, 0, 0);

    foreach my $row (@$pgresult) {
        $cl_active  += $row->[2];
        $cl_waiting += $row->[3];
        $sv_active  += $row->[4];
        $sv_idle    += $row->[5];
    }

    return [
        ['cl_active',  $cl_active - 1],    # Subtract our own session
        ['cl_waiting', $cl_waiting],
        ['sv_active',  $sv_active],
        ['sv_idle',    $sv_idle],
    ];
}