diff --git a/README.md b/README.md index 9595b1a..5a266ec 100644 --- a/README.md +++ b/README.md @@ -17,14 +17,14 @@ from within HAPRoxy, including: * Broken down by Service * Broken down by Host * Response Codes for Frontends - * Broken down by Service (aggregrated by Status Code) + * Broken down by Service (aggregating by Status Code) * Broken down by Status Code * Response Codes for Backends - * Broken down by Service (aggregrated by Server) + * Broken down by Service (aggregating by Server) * Broken down by Server - * Broken down by Service (aggregrated by Status Codes) - * Broken down by Status (aggregrated by Server) - * Brokwn down by Server + * Broken down by Service (aggregating by Status Codes) + * Broken down by Status (aggregating by Server) + * Broken down by Server ## Warning @@ -33,13 +33,13 @@ you can probably exceed over 1000 graphs being produced covering all the above. This setup either required some *very* fast hardware, or it's best to make sure that you are using something like `rrdcached` and SSDs to make sure that you -are aggregrating updates, caching reads, etc. Additionally, creating graphs +are aggregating updates, caching reads, etc. Additionally, creating graphs on-the-fly via CGI may end up being better, unless you can safely produce a very large number of graphs every five minutes with room to spare and grow! ## Usage -You will need Munin 2.0 as this is a multigraph plugin and will output all +You will need Munin 2.0 as this is a `multigraph` plugin and will output all graphs in a single run. [haproxyng*] @@ -55,15 +55,15 @@ graphs in a single run. configuration. For example if you're configuration is automatically generated and everything is prefixed with "staging-" or "production_" then put that (or any other regex) into `clean` and it will be cleaned from any - titles and output to Munin. + titles before being output to Munin. -Beyond that, copy/symlink it to the `plugins/` directory on the relevent node +Beyond that, copy/symlink it to the `plugins/` directory on the relevant node and wait for it to run. Running munin-run haproxyng config -is also possible to verify that it can see everything and output the config -data for Munin. +is also possible to verify that it can see everything and output the +configuration data for Munin. ## Licence diff --git a/haproxyng b/haproxyng index b31e328..a7d3599 100755 --- a/haproxyng +++ b/haproxyng @@ -2,7 +2,7 @@ # haproxyng Munin Plugin # Multigraph plugin which monitors the haproxy service. -# (c) 2014-2015 Jonathan Wright +# (c) 2014-2015 Jonathan Wright # # This program is free software; you can redistribute it and/or # modify it under the terms of the GNU General Public License @@ -31,8 +31,8 @@ use Data::Dumper; # Configure Program details our ($_program, $_version, $_author); $_program = 'haproxyng'; -$_version = '1.0.0'; -$_author = 'Jonathan Wright '; +$_version = '1.0.1'; +$_author = 'Jonathan Wright '; use constant { # Field names to locations for all the CSV data provided by HAProxy @@ -167,21 +167,21 @@ sub get_data { case TYPE_FRONTEND { $v{$stat[STAT_PROXY_NAME]} = { type => TYPE_FRONTEND, - connections => $stat[STAT_CONNECTIONS_TOTAL], - sessions => $stat[STAT_SESSIONS_CURRENT], + connections => ($stat[STAT_CONNECTIONS_TOTAL] || 0), + sessions => ($stat[STAT_SESSIONS_CURRENT] || 0), queued => 0, bandwidth => { - in => $stat[STAT_BYTES_IN], - out => $stat[STAT_BYTES_OUT], + in => ($stat[STAT_BYTES_IN] || 0), + out => ($stat[STAT_BYTES_OUT] || 0), }, responses => { - total => $stat[STAT_REQUESTS_TOTAL], - http1xx => $stat[STAT_RESPONSES_HTTP_1XX], - http2xx => $stat[STAT_RESPONSES_HTTP_2XX], - http3xx => $stat[STAT_RESPONSES_HTTP_3XX], - http4xx => $stat[STAT_RESPONSES_HTTP_4XX], - http5xx => $stat[STAT_RESPONSES_HTTP_5XX], - httpxxx => $stat[STAT_RESPONSES_HTTP_XXX], + total => ($stat[STAT_REQUESTS_TOTAL] || 0), + http1xx => ($stat[STAT_RESPONSES_HTTP_1XX] || 0), + http2xx => ($stat[STAT_RESPONSES_HTTP_2XX] || 0), + http3xx => ($stat[STAT_RESPONSES_HTTP_3XX] || 0), + http4xx => ($stat[STAT_RESPONSES_HTTP_4XX] || 0), + http5xx => ($stat[STAT_RESPONSES_HTTP_5XX] || 0), + httpxxx => ($stat[STAT_RESPONSES_HTTP_XXX] || 0), }, }; } @@ -192,28 +192,28 @@ sub get_data { # the backend's servers, so would override anything previously set # in TYPE_SERVER $v{$stat[STAT_PROXY_NAME]}{'type'} = TYPE_BACKEND; - $v{$stat[STAT_PROXY_NAME]}{'connections'} = $stat[STAT_CONNECTIONS_TOTAL]; - $v{$stat[STAT_PROXY_NAME]}{'sessions'} = $stat[STAT_SESSIONS_CURRENT]; - $v{$stat[STAT_PROXY_NAME]}{'queued'} = $stat[STAT_QUEUED_REQUESTS]; - $v{$stat[STAT_PROXY_NAME]}{'active'} = $stat[STAT_SERVERS_ACTIVE]; - $v{$stat[STAT_PROXY_NAME]}{'backup'} = $stat[STAT_SERVERS_BACKUP]; + $v{$stat[STAT_PROXY_NAME]}{'connections'} = ($stat[STAT_CONNECTIONS_TOTAL] || 0); + $v{$stat[STAT_PROXY_NAME]}{'sessions'} = ($stat[STAT_SESSIONS_CURRENT] || 0); + $v{$stat[STAT_PROXY_NAME]}{'queued'} = ($stat[STAT_QUEUED_REQUESTS] || 0); + $v{$stat[STAT_PROXY_NAME]}{'active'} = ($stat[STAT_SERVERS_ACTIVE] || 0); + $v{$stat[STAT_PROXY_NAME]}{'backup'} = ($stat[STAT_SERVERS_BACKUP] || 0); $v{$stat[STAT_PROXY_NAME]}{'bandwidth'} = { - in => $stat[STAT_BYTES_IN], - out => $stat[STAT_BYTES_OUT], + in => ($stat[STAT_BYTES_IN] || 0), + out => ($stat[STAT_BYTES_OUT] || 0), }; $v{$stat[STAT_PROXY_NAME]}{'responses'} = { - total => $stat[STAT_RESPONSES_HTTP_1XX] - + $stat[STAT_RESPONSES_HTTP_2XX] - + $stat[STAT_RESPONSES_HTTP_3XX] - + $stat[STAT_RESPONSES_HTTP_4XX] - + $stat[STAT_RESPONSES_HTTP_5XX] - + $stat[STAT_RESPONSES_HTTP_XXX], - http1xx => $stat[STAT_RESPONSES_HTTP_1XX], - http2xx => $stat[STAT_RESPONSES_HTTP_2XX], - http3xx => $stat[STAT_RESPONSES_HTTP_3XX], - http4xx => $stat[STAT_RESPONSES_HTTP_4XX], - http5xx => $stat[STAT_RESPONSES_HTTP_5XX], - httpxxx => $stat[STAT_RESPONSES_HTTP_XXX], + total => ($stat[STAT_RESPONSES_HTTP_1XX] || 0) + + ($stat[STAT_RESPONSES_HTTP_2XX] || 0) + + ($stat[STAT_RESPONSES_HTTP_3XX] || 0) + + ($stat[STAT_RESPONSES_HTTP_4XX] || 0) + + ($stat[STAT_RESPONSES_HTTP_5XX] || 0) + + ($stat[STAT_RESPONSES_HTTP_XXX] || 0), + http1xx => ($stat[STAT_RESPONSES_HTTP_1XX] || 0), + http2xx => ($stat[STAT_RESPONSES_HTTP_2XX] || 0), + http3xx => ($stat[STAT_RESPONSES_HTTP_3XX] || 0), + http4xx => ($stat[STAT_RESPONSES_HTTP_4XX] || 0), + http5xx => ($stat[STAT_RESPONSES_HTTP_5XX] || 0), + httpxxx => ($stat[STAT_RESPONSES_HTTP_XXX] || 0), }; } # Process all SERVER type entries, which are the most details and give @@ -227,33 +227,33 @@ sub get_data { up => ($stat[STAT_STATUS] eq 'UP' ? 1 : 0), down => ($stat[STAT_STATUS] eq 'DOWN' ? 1 : 0), disabled => ($stat[STAT_STATUS] =~ /^(MAINT|DRAIN|NOLB)/i ? 1 : 0), - connections => $stat[STAT_CONNECTIONS_TOTAL], - sessions => $stat[STAT_SESSIONS_CURRENT], - queued => $stat[STAT_QUEUED_REQUESTS], + connections => ($stat[STAT_CONNECTIONS_TOTAL] || 0), + sessions => ($stat[STAT_SESSIONS_CURRENT] || 0), + queued => ($stat[STAT_QUEUED_REQUESTS] || 0), bandwidth => { - in => $stat[STAT_BYTES_IN], - out => $stat[STAT_BYTES_OUT], + in => ($stat[STAT_BYTES_IN] || 0), + out => ($stat[STAT_BYTES_OUT] || 0), }, - status => $stat[STAT_STATUS], + status => ($stat[STAT_STATUS] || 0), timing => { - queue => $stat[STAT_TIME_QUEUE], - connect => $stat[STAT_TIME_CONNECT], - response => $stat[STAT_TIME_RESPONSE], - total => $stat[STAT_TIME_TOTAL] + queue => ($stat[STAT_TIME_QUEUE] || 0), + connect => ($stat[STAT_TIME_CONNECT] || 0), + response => ($stat[STAT_TIME_RESPONSE] || 0), + total => ($stat[STAT_TIME_TOTAL] || 0) }, responses => { - total => $stat[STAT_RESPONSES_HTTP_1XX] - + $stat[STAT_RESPONSES_HTTP_2XX] - + $stat[STAT_RESPONSES_HTTP_3XX] - + $stat[STAT_RESPONSES_HTTP_4XX] - + $stat[STAT_RESPONSES_HTTP_5XX] - + $stat[STAT_RESPONSES_HTTP_XXX], - http1xx => $stat[STAT_RESPONSES_HTTP_1XX], - http2xx => $stat[STAT_RESPONSES_HTTP_2XX], - http3xx => $stat[STAT_RESPONSES_HTTP_3XX], - http4xx => $stat[STAT_RESPONSES_HTTP_4XX], - http5xx => $stat[STAT_RESPONSES_HTTP_5XX], - httpxxx => $stat[STAT_RESPONSES_HTTP_XXX], + total => ($stat[STAT_RESPONSES_HTTP_1XX] || 0) + + ($stat[STAT_RESPONSES_HTTP_2XX] || 0) + + ($stat[STAT_RESPONSES_HTTP_3XX] || 0) + + ($stat[STAT_RESPONSES_HTTP_4XX] || 0) + + ($stat[STAT_RESPONSES_HTTP_5XX] || 0) + + ($stat[STAT_RESPONSES_HTTP_XXX] || 0), + http1xx => ($stat[STAT_RESPONSES_HTTP_1XX] || 0), + http2xx => ($stat[STAT_RESPONSES_HTTP_2XX] || 0), + http3xx => ($stat[STAT_RESPONSES_HTTP_3XX] || 0), + http4xx => ($stat[STAT_RESPONSES_HTTP_4XX] || 0), + http5xx => ($stat[STAT_RESPONSES_HTTP_5XX] || 0), + httpxxx => ($stat[STAT_RESPONSES_HTTP_XXX] || 0), }, }; } @@ -586,7 +586,7 @@ sub haproxy_timing { $total+=$data{$service}{'servers'}{$server}{'timing'}{'total'}; } - $values{$service} = ($total/$count); + $values{$service} = ($count > 0 ? $total/$count : 0); } mg_fetch(TYPE_BACKEND, ['timing'], \%values);