Skip to content

Instantly share code, notes, and snippets.

@hggh
Created May 17, 2014 12:03
Show Gist options
  • Save hggh/814c47dd889494a3406c to your computer and use it in GitHub Desktop.
Save hggh/814c47dd889494a3406c to your computer and use it in GitHub Desktop.
haproxy curconns with instance support
#!/usr/bin/env perl
# haproxy_curconn_l1 symlink in etc/munin/plugins
use strict;
use IO::Socket::UNIX;
my $ha_name;
if ($0 =~m /haproxy_maxconn_(.*)/ ) {
$ha_name = $1;
}
my $socket = exists $ENV{'socket'} ? $ENV{'socket'} : "/var/run/haproxy.socket";
my $name = exists $ENV{'name'} ? $ENV{'name'} : $ha_name;
if ( exists $ARGV[0] and $ARGV[0] eq "config" ) {
print "graph_title haproxy curconns $name\n";
print "graph_vlabel connections\n";
print "graph_category haproxy\n";
print "curconns.label current connections\n";
print "graph_args -l 0\n";
}
else {
my $currconns = "U";
if ( -S $socket) {
my $sock = IO::Socket::UNIX->new(
Peer => $socket,
);
print $sock "show info\n";
while (my $line = <$sock>) {
last if $line =~ /^\n/;
chomp($line);
if ($line =~m /CurrConns: (.*)/) {
$currconns = $1;
}
}
}
print "curconns.value $currconns\n";
}
# /etc/munin/plugin-conf.d/haproxy_curconn_l1.conf
[haproxy_curconn_l1]
user root
env.socket /var/run/haproxy-l1.socket
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment