Skip to content

Commit

Permalink
Merge pull request #3 from jonathanio/fix/numeric-issues
Browse files Browse the repository at this point in the history
Fix some numeric issues
  • Loading branch information
jonathanio authored Nov 16, 2016
2 parents 69acae0 + 2f82266 commit 68437bf
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 67 deletions.
22 changes: 11 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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*]
Expand All @@ -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

Expand Down
112 changes: 56 additions & 56 deletions haproxyng
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

# haproxyng Munin Plugin
# Multigraph plugin which monitors the haproxy service.
# (c) 2014-2015 Jonathan Wright <github@jon.than.io>
# (c) 2014-2015 Jonathan Wright <jon@than.io>
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
Expand Down Expand Up @@ -31,8 +31,8 @@ use Data::Dumper;
# Configure Program details
our ($_program, $_version, $_author);
$_program = 'haproxyng';
$_version = '1.0.0';
$_author = 'Jonathan Wright <github@jon.than.io>';
$_version = '1.0.1';
$_author = 'Jonathan Wright <jon@than.io>';

use constant {
# Field names to locations for all the CSV data provided by HAProxy
Expand Down Expand Up @@ -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),
},
};
}
Expand All @@ -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
Expand All @@ -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),
},
};
}
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit 68437bf

Please sign in to comment.