Picon

ha proxy Nagios plugin


Hi all,

For our own needs, a Nagios plugin has been developed to check haproxy activity (and hosts status).
The plugin checks HAProxy statistic url (csv) and gets UP and DOWN services.

plugin code :
http://cvs.orion.education.fr/viewvc/viewvc.cgi/nagios-plugins-perl/trunk/plugins/check_haproxy.pl?revision=131&view=markup
conf example :
http://cvs.orion.education.fr/viewvc/viewvc.cgi/nagios-plugins-perl/trunk/configs/check_haproxy.cfg?revision=134&view=markup

   Regards,

      Stéphane URBANOVSKI and Jean-Christophe TOUSSAINT.

--
Jean-Christophe TOUSSAINT
Administrateur Systèmes & Réseaux

DSI - DIT
Rectorat de l'académie de Nancy-Metz
mail : jean-christophe.toussaint@...

Willy Tarreau | 2 Mar 22:48
Picon
Favicon

Re: ha proxy Nagios plugin

Hi Jean-Christophe & Stéphane,

On Tue, Mar 02, 2010 at 02:28:57PM +0100, Jean-Christophe TOUSSAINT wrote:
> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
> 
> Hi all,
> 
> For our own needs, a Nagios plugin has been developed to check haproxy activity (and hosts status).
> The plugin checks HAProxy statistic url (csv) and gets UP and DOWN services.
> 
> - - plugin code :
> http://cvs.orion.education.fr/viewvc/viewvc.cgi/nagios-plugins-perl/trunk/plugins/check_haproxy.pl?revision=131&view=markup
> - - conf example :
> http://cvs.orion.education.fr/viewvc/viewvc.cgi/nagios-plugins-perl/trunk/configs/check_haproxy.cfg?revision=134&view=markup

Cool, thanks. Are you interested in getting it merged into
mainline ? If so, we can create an entry into the "contrib"
directory.

Also, it seems to rely only on the HTTP socket. Do you think
it can easily be adapted to also support the unix socket, which
is global and does not require opening a TCP port ?

Regards,
Willy

Picon

Re: ha proxy Nagios plugin

Willy Tarreau a écrit :
> Hi Jean-Christophe & Stéphane,
> 
> On Tue, Mar 02, 2010 at 02:28:57PM +0100, Jean-Christophe TOUSSAINT wrote:
>> -----BEGIN PGP SIGNED MESSAGE-----
>> Hash: SHA1
>>
>> Hi all,
>>
>> For our own needs, a Nagios plugin has been developed to check haproxy activity (and hosts status).
>> The plugin checks HAProxy statistic url (csv) and gets UP and DOWN services.
>>
>> - - plugin code :
>> http://cvs.orion.education.fr/viewvc/viewvc.cgi/nagios-plugins-perl/trunk/plugins/check_haproxy.pl?revision=131&view=markup
>> - - conf example :
>> http://cvs.orion.education.fr/viewvc/viewvc.cgi/nagios-plugins-perl/trunk/configs/check_haproxy.cfg?revision=134&view=markup
> 
> Cool, thanks. Are you interested in getting it merged into
> mainline ? If so, we can create an entry into the "contrib"
> directory.

No objections, but I'm not sure it is the best place. A link in the README should be enough.

> Also, it seems to rely only on the HTTP socket. Do you think
> it can easily be adapted to also support the unix socket, which
> is global and does not require opening a TCP port ?

The plugin works with Nagios which is not installed on the same host. So a remote access in a way or other is mandatory.

Regards
(Continue reading)

Willy Tarreau | 8 Mar 22:19
Picon
Favicon

Re: ha proxy Nagios plugin

Hi,

On Mon, Mar 08, 2010 at 02:58:14PM +0100, Stéphane Urbanovski wrote:
> >Cool, thanks. Are you interested in getting it merged into
> >mainline ? If so, we can create an entry into the "contrib"
> >directory.
> 
> No objections, but I'm not sure it is the best place. A link in the README 
> should be enough.

OK will do that then. In fact, projects that people want to maintain
are more suited out of tree, and the ones that are written as one-shot
and have no reason to change in the future are better merged (eg: the
net-snmp plugin is a good example). That's why I asked.

> >Also, it seems to rely only on the HTTP socket. Do you think
> >it can easily be adapted to also support the unix socket, which
> >is global and does not require opening a TCP port ?
> 
> The plugin works with Nagios which is not installed on the same host. So a 
> remote access in a way or other is mandatory.

hey, that obviously makes sense !

Thanks,
Willy

Re: ha proxy Nagios plugin


On Mar 8, 2010, at 1:19 PM, Willy Tarreau wrote:

Hi,

On Mon, Mar 08, 2010 at 02:58:14PM +0100, Stéphane Urbanovski wrote:
Cool, thanks. Are you interested in getting it merged into
mainline ? If so, we can create an entry into the "contrib"
directory.

No objections, but I'm not sure it is the best place. A link in the README
should be enough.

OK will do that then. In fact, projects that people want to maintain
are more suited out of tree, and the ones that are written as one-shot
and have no reason to change in the future are better merged (eg: the
net-snmp plugin is a good example). That's why I asked.

Also, it seems to rely only on the HTTP socket. Do you think
it can easily be adapted to also support the unix socket, which
is global and does not require opening a TCP port ?

The plugin works with Nagios which is not installed on the same host. So a
remote access in a way or other is mandatory.

hey, that obviously makes sense !

I was looking at the Nagios script that Jean-Christophe wrote and I think there may be a need for something a bit different.

I feel that we might want to have the Nagios plugin monitor a specific frontend/backend service combination, rather than the entire HAProxy setup.  This would be useful because we could focus on individual HAProxy services and their specific health.  If we try and write one plugin for all HAProxy services things start to get muddled.

Here is what I am thinking:
- Specify a listen and backend service(s) or a single listen service where the frontend and backend have the same name
- Specify thresholds for sessions, errors, queue, etc... Make this dynamic in case any fields change..
- Since most the stats are based on counters the nagios plugin would have to maintain persistent counters, most likely in an external file
- To keep the load down on the admin requests to haproxy perhaps we have the script cache the csv data and check it for freshness every run..  
- Specify thresholds for how many backend services can be up or down as a percentage, so like if 50% of backend services are down, go critical, if only 25% of them are down make it a warning or something..
- Output performance data for sessions, errors, queue, etc.. so that we can trend and make pretty pictures

We could try and use Ton Voon's new multiple threshold syntax specified here.. 

That's about all I have for now..

Thoughts?

-Josh Brown
chantra | 11 Mar 13:20
Favicon
Gravatar

Re: ha proxy Nagios plugin

Hi,

I have a small patch that seems to address an issue to get the 'type' csv values

Also, this add -U and -P switches to supply username/password credentials for http basic auth.


Chantra !DSPAM:4b98e00261671119019326!
diff -r fd7ee65c064b check_haproxy.pl
--- a/check_haproxy.pl	Thu Mar 11 11:25:18 2010 +0100
+++ b/check_haproxy.pl	Thu Mar 11 13:07:33 2010 +0100
@@ -55,13 +55,23 @@
 my $np = Nagios::Plugin->new(
 	version => $VERSION,
 	blurb => _gt('Plugin to check HAProxy stats url'),
-	usage => "Usage: %s [ -v|--verbose ]  -u <url> [-t <timeout>] [ -c|--critical=<threshold> ] [
-w|--warning=<threshold> ]",
+	usage => "Usage: %s [ -v|--verbose ]  -u <url> [-t <timeout>] [-U <username>] [-P <password>] [
-c|--critical=<threshold> ] [ -w|--warning=<threshold> ]",
 	timeout => $TIMEOUT+1
 );
 $np->add_arg (
 	spec => 'debug|d',
 	help => _gt('Debug level'),
 	default => 0,
+);
+$np->add_arg (
+  spec => 'username|U=s',
+  help => _gt('Username for HTTP Auth'),
+  required => 0, 
+);
+$np->add_arg (
+  spec => 'password|P=s',
+  help => _gt('Password for HTTP Auth'),
+  required => 0, 
 );
 $np->add_arg (
 	spec => 'w=f',
@@ -86,6 +96,8 @@

 $DEBUG = $np->opts->get('debug');
 my $verbose = $np->opts->get('verbose');
+my $username = $np->opts->get('username');
+my $password = $np->opts->get('password');

 # Thresholds :
 # time
@@ -114,6 +126,10 @@

 # Build and submit an http request :
 my $request = HTTP::Request->new('GET', $url);
+# Authenticate if username and password are supplied
+if ( defined($username) && defined($password) ) {
+  $request->authorization_basic($username, $password);
+}
 my $timer = time();
 my $http_response = $ua->request( $request );
 $timer = time()-$timer;
@@ -181,7 +197,7 @@
 		if ( !defined($stats{$values[0]}{$values[1]}) ) {
 			$stats{$values[0]}{$values[1]} = {};
 		}
-		for ( my $x = 2,; $x < $#values; $x++ ) {
+		for ( my $x = 2,; $x <= $#values; $x++ ) {
 			# $stats{pxname}{svname}{valuename}
 			$stats{$values[0]}{$values[1]}{$fields[$x]} = $values[$x];
 		}

Gmane