File: haproxy_.in

package info (click to toggle)
munin 2.0.76-5
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 7,064 kB
  • sloc: perl: 11,684; java: 1,924; sh: 1,632; makefile: 636; javascript: 365; python: 267
file content (105 lines) | stat: -rw-r--r-- 2,592 bytes parent folder | download | duplicates (3)
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
102
103
104
105
#!@@PERL@@ -w
# -*- cperl -*-

=head1 NAME

haproxy_ - Graph stats from the haproxy daemon

=head1 APPLICABLE SYSTEMS

Any haproxy host

=head1 CONFIGURATION

This is a wildcard plugin to support fetching status from multiple
instances of haproxy that each need a distinct configurations, e.g.:

   haproxy_backend

and

   haproxy_frontend

Each with a separate configuration.  The following example shows the
default URL used by the plugin for the imaginary backend:

   [haproxy_backend]
	env.url http://localhost/haproxy-status;csv;norefresh

If you need authenticated access to the URL you can specify the
username and password in the URL.  For example:

   [haproxy_backend]
	env.url http://munin:spamalot@localhost/haproxy-status;csv;norefresh

This will provide for HTTP basic authentication.

=head1 MAGIC MARKERS

  #%# family=contrib

=head1 AUTHOR

Jimmy Olsen (based on some Apache plugin).  Documented by Nicolai Langfeldt.

=head1 LICENSE

GPLv2

=cut

use Munin::Plugin;

my $ret = undef;
if (! eval "require LWP::UserAgent;")
{
	$ret = "LWP::UserAgent not found";
}

my $URL = exists $ENV{'url'} ? $ENV{'url'} : "http://localhost/haproxy-status;csv;norefresh";

my $ua = LWP::UserAgent->new(timeout => 30,
		agent => sprintf("munin/%s (libwww-perl/%s)", $Munin::Common::Defaults::MUNIN_VERSION, $LWP::VERSION));

my $url = $URL;
my $response = $ua->request(HTTP::Request->new('GET',$url));
my $content = $response->content;
my %backends = ();

if ( exists $ARGV[0] and $ARGV[0] eq "config" )
{
	my $clusterid = "unknown cluster";
	if ($content =~ /\n([^,]+),FRONTEND/) {
		$clusterid = $1;
	}
	print "graph_title HAProxy statistics for $clusterid\n";
	print "graph_args --base 1000 -l 0\n";
	print "graph_vlabel connections per \${graph_period}\n";
	print "graph_category haproxy\n";
	while ($content =~ /\n([^,]+),([^,]+),[^,]+,[^,]+,[^,]+,[^,]+,[^,]*,([^,]+),[^,]+,[^,]+,[^,]*,[^,]+,/g) {
		next if $2 eq "BACKEND";
		my $field_name = clean_fieldname($2);
		next if defined $backends{$field_name};
		$backends{$field_name} = 1;
		print "s$field_name.label ", $2, "\n";
		print "s$field_name.type DERIVE\n";
		print "s$field_name.min 0\n";
		print "s$field_name.draw AREASTACK\n";
	}
	exit 0;
}

while ($content =~ /\n([^,]+),([^,]+),[^,]+,[^,]+,[^,]+,[^,]+,[^,]*,([^,]+),[^,]+,[^,]+,[^,]*,[^,]+,/g) {
	next if $2 eq "BACKEND";
	my $field_name = clean_fieldname($2);
	if (defined ($field_name)) {
		$backends{$field_name} += $3;
	} else {
		$backends{$field_name} = $3;
	}
}

foreach my $be (keys %backends) {
	print "s$be.value ", $backends{$be}, "\n";
}
# vim:syntax=perl