Skip to content

Commit 68437bf

Browse files
authored
Merge pull request #3 from jonathanio/fix/numeric-issues
Fix some numeric issues
2 parents 69acae0 + 2f82266 commit 68437bf

File tree

2 files changed

+67
-67
lines changed

2 files changed

+67
-67
lines changed

README.md

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,14 @@ from within HAPRoxy, including:
1717
* Broken down by Service
1818
* Broken down by Host
1919
* Response Codes for Frontends
20-
* Broken down by Service (aggregrated by Status Code)
20+
* Broken down by Service (aggregating by Status Code)
2121
* Broken down by Status Code
2222
* Response Codes for Backends
23-
* Broken down by Service (aggregrated by Server)
23+
* Broken down by Service (aggregating by Server)
2424
* Broken down by Server
25-
* Broken down by Service (aggregrated by Status Codes)
26-
* Broken down by Status (aggregrated by Server)
27-
* Brokwn down by Server
25+
* Broken down by Service (aggregating by Status Codes)
26+
* Broken down by Status (aggregating by Server)
27+
* Broken down by Server
2828

2929
## Warning
3030

@@ -33,13 +33,13 @@ you can probably exceed over 1000 graphs being produced covering all the above.
3333

3434
This setup either required some *very* fast hardware, or it's best to make sure
3535
that you are using something like `rrdcached` and SSDs to make sure that you
36-
are aggregrating updates, caching reads, etc. Additionally, creating graphs
36+
are aggregating updates, caching reads, etc. Additionally, creating graphs
3737
on-the-fly via CGI may end up being better, unless you can safely produce a very
3838
large number of graphs every five minutes with room to spare and grow!
3939

4040
## Usage
4141

42-
You will need Munin 2.0 as this is a multigraph plugin and will output all
42+
You will need Munin 2.0 as this is a `multigraph` plugin and will output all
4343
graphs in a single run.
4444

4545
[haproxyng*]
@@ -55,15 +55,15 @@ graphs in a single run.
5555
configuration. For example if you're configuration is automatically
5656
generated and everything is prefixed with "staging-" or "production_" then
5757
put that (or any other regex) into `clean` and it will be cleaned from any
58-
titles and output to Munin.
58+
titles before being output to Munin.
5959

60-
Beyond that, copy/symlink it to the `plugins/` directory on the relevent node
60+
Beyond that, copy/symlink it to the `plugins/` directory on the relevant node
6161
and wait for it to run. Running
6262

6363
munin-run haproxyng config
6464

65-
is also possible to verify that it can see everything and output the config
66-
data for Munin.
65+
is also possible to verify that it can see everything and output the
66+
configuration data for Munin.
6767

6868
## Licence
6969

haproxyng

Lines changed: 56 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

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

3737
use constant {
3838
# Field names to locations for all the CSV data provided by HAProxy
@@ -167,21 +167,21 @@ sub get_data {
167167
case TYPE_FRONTEND {
168168
$v{$stat[STAT_PROXY_NAME]} = {
169169
type => TYPE_FRONTEND,
170-
connections => $stat[STAT_CONNECTIONS_TOTAL],
171-
sessions => $stat[STAT_SESSIONS_CURRENT],
170+
connections => ($stat[STAT_CONNECTIONS_TOTAL] || 0),
171+
sessions => ($stat[STAT_SESSIONS_CURRENT] || 0),
172172
queued => 0,
173173
bandwidth => {
174-
in => $stat[STAT_BYTES_IN],
175-
out => $stat[STAT_BYTES_OUT],
174+
in => ($stat[STAT_BYTES_IN] || 0),
175+
out => ($stat[STAT_BYTES_OUT] || 0),
176176
},
177177
responses => {
178-
total => $stat[STAT_REQUESTS_TOTAL],
179-
http1xx => $stat[STAT_RESPONSES_HTTP_1XX],
180-
http2xx => $stat[STAT_RESPONSES_HTTP_2XX],
181-
http3xx => $stat[STAT_RESPONSES_HTTP_3XX],
182-
http4xx => $stat[STAT_RESPONSES_HTTP_4XX],
183-
http5xx => $stat[STAT_RESPONSES_HTTP_5XX],
184-
httpxxx => $stat[STAT_RESPONSES_HTTP_XXX],
178+
total => ($stat[STAT_REQUESTS_TOTAL] || 0),
179+
http1xx => ($stat[STAT_RESPONSES_HTTP_1XX] || 0),
180+
http2xx => ($stat[STAT_RESPONSES_HTTP_2XX] || 0),
181+
http3xx => ($stat[STAT_RESPONSES_HTTP_3XX] || 0),
182+
http4xx => ($stat[STAT_RESPONSES_HTTP_4XX] || 0),
183+
http5xx => ($stat[STAT_RESPONSES_HTTP_5XX] || 0),
184+
httpxxx => ($stat[STAT_RESPONSES_HTTP_XXX] || 0),
185185
},
186186
};
187187
}
@@ -192,28 +192,28 @@ sub get_data {
192192
# the backend's servers, so would override anything previously set
193193
# in TYPE_SERVER
194194
$v{$stat[STAT_PROXY_NAME]}{'type'} = TYPE_BACKEND;
195-
$v{$stat[STAT_PROXY_NAME]}{'connections'} = $stat[STAT_CONNECTIONS_TOTAL];
196-
$v{$stat[STAT_PROXY_NAME]}{'sessions'} = $stat[STAT_SESSIONS_CURRENT];
197-
$v{$stat[STAT_PROXY_NAME]}{'queued'} = $stat[STAT_QUEUED_REQUESTS];
198-
$v{$stat[STAT_PROXY_NAME]}{'active'} = $stat[STAT_SERVERS_ACTIVE];
199-
$v{$stat[STAT_PROXY_NAME]}{'backup'} = $stat[STAT_SERVERS_BACKUP];
195+
$v{$stat[STAT_PROXY_NAME]}{'connections'} = ($stat[STAT_CONNECTIONS_TOTAL] || 0);
196+
$v{$stat[STAT_PROXY_NAME]}{'sessions'} = ($stat[STAT_SESSIONS_CURRENT] || 0);
197+
$v{$stat[STAT_PROXY_NAME]}{'queued'} = ($stat[STAT_QUEUED_REQUESTS] || 0);
198+
$v{$stat[STAT_PROXY_NAME]}{'active'} = ($stat[STAT_SERVERS_ACTIVE] || 0);
199+
$v{$stat[STAT_PROXY_NAME]}{'backup'} = ($stat[STAT_SERVERS_BACKUP] || 0);
200200
$v{$stat[STAT_PROXY_NAME]}{'bandwidth'} = {
201-
in => $stat[STAT_BYTES_IN],
202-
out => $stat[STAT_BYTES_OUT],
201+
in => ($stat[STAT_BYTES_IN] || 0),
202+
out => ($stat[STAT_BYTES_OUT] || 0),
203203
};
204204
$v{$stat[STAT_PROXY_NAME]}{'responses'} = {
205-
total => $stat[STAT_RESPONSES_HTTP_1XX]
206-
+ $stat[STAT_RESPONSES_HTTP_2XX]
207-
+ $stat[STAT_RESPONSES_HTTP_3XX]
208-
+ $stat[STAT_RESPONSES_HTTP_4XX]
209-
+ $stat[STAT_RESPONSES_HTTP_5XX]
210-
+ $stat[STAT_RESPONSES_HTTP_XXX],
211-
http1xx => $stat[STAT_RESPONSES_HTTP_1XX],
212-
http2xx => $stat[STAT_RESPONSES_HTTP_2XX],
213-
http3xx => $stat[STAT_RESPONSES_HTTP_3XX],
214-
http4xx => $stat[STAT_RESPONSES_HTTP_4XX],
215-
http5xx => $stat[STAT_RESPONSES_HTTP_5XX],
216-
httpxxx => $stat[STAT_RESPONSES_HTTP_XXX],
205+
total => ($stat[STAT_RESPONSES_HTTP_1XX] || 0)
206+
+ ($stat[STAT_RESPONSES_HTTP_2XX] || 0)
207+
+ ($stat[STAT_RESPONSES_HTTP_3XX] || 0)
208+
+ ($stat[STAT_RESPONSES_HTTP_4XX] || 0)
209+
+ ($stat[STAT_RESPONSES_HTTP_5XX] || 0)
210+
+ ($stat[STAT_RESPONSES_HTTP_XXX] || 0),
211+
http1xx => ($stat[STAT_RESPONSES_HTTP_1XX] || 0),
212+
http2xx => ($stat[STAT_RESPONSES_HTTP_2XX] || 0),
213+
http3xx => ($stat[STAT_RESPONSES_HTTP_3XX] || 0),
214+
http4xx => ($stat[STAT_RESPONSES_HTTP_4XX] || 0),
215+
http5xx => ($stat[STAT_RESPONSES_HTTP_5XX] || 0),
216+
httpxxx => ($stat[STAT_RESPONSES_HTTP_XXX] || 0),
217217
};
218218
}
219219
# Process all SERVER type entries, which are the most details and give
@@ -227,33 +227,33 @@ sub get_data {
227227
up => ($stat[STAT_STATUS] eq 'UP' ? 1 : 0),
228228
down => ($stat[STAT_STATUS] eq 'DOWN' ? 1 : 0),
229229
disabled => ($stat[STAT_STATUS] =~ /^(MAINT|DRAIN|NOLB)/i ? 1 : 0),
230-
connections => $stat[STAT_CONNECTIONS_TOTAL],
231-
sessions => $stat[STAT_SESSIONS_CURRENT],
232-
queued => $stat[STAT_QUEUED_REQUESTS],
230+
connections => ($stat[STAT_CONNECTIONS_TOTAL] || 0),
231+
sessions => ($stat[STAT_SESSIONS_CURRENT] || 0),
232+
queued => ($stat[STAT_QUEUED_REQUESTS] || 0),
233233
bandwidth => {
234-
in => $stat[STAT_BYTES_IN],
235-
out => $stat[STAT_BYTES_OUT],
234+
in => ($stat[STAT_BYTES_IN] || 0),
235+
out => ($stat[STAT_BYTES_OUT] || 0),
236236
},
237-
status => $stat[STAT_STATUS],
237+
status => ($stat[STAT_STATUS] || 0),
238238
timing => {
239-
queue => $stat[STAT_TIME_QUEUE],
240-
connect => $stat[STAT_TIME_CONNECT],
241-
response => $stat[STAT_TIME_RESPONSE],
242-
total => $stat[STAT_TIME_TOTAL]
239+
queue => ($stat[STAT_TIME_QUEUE] || 0),
240+
connect => ($stat[STAT_TIME_CONNECT] || 0),
241+
response => ($stat[STAT_TIME_RESPONSE] || 0),
242+
total => ($stat[STAT_TIME_TOTAL] || 0)
243243
},
244244
responses => {
245-
total => $stat[STAT_RESPONSES_HTTP_1XX]
246-
+ $stat[STAT_RESPONSES_HTTP_2XX]
247-
+ $stat[STAT_RESPONSES_HTTP_3XX]
248-
+ $stat[STAT_RESPONSES_HTTP_4XX]
249-
+ $stat[STAT_RESPONSES_HTTP_5XX]
250-
+ $stat[STAT_RESPONSES_HTTP_XXX],
251-
http1xx => $stat[STAT_RESPONSES_HTTP_1XX],
252-
http2xx => $stat[STAT_RESPONSES_HTTP_2XX],
253-
http3xx => $stat[STAT_RESPONSES_HTTP_3XX],
254-
http4xx => $stat[STAT_RESPONSES_HTTP_4XX],
255-
http5xx => $stat[STAT_RESPONSES_HTTP_5XX],
256-
httpxxx => $stat[STAT_RESPONSES_HTTP_XXX],
245+
total => ($stat[STAT_RESPONSES_HTTP_1XX] || 0)
246+
+ ($stat[STAT_RESPONSES_HTTP_2XX] || 0)
247+
+ ($stat[STAT_RESPONSES_HTTP_3XX] || 0)
248+
+ ($stat[STAT_RESPONSES_HTTP_4XX] || 0)
249+
+ ($stat[STAT_RESPONSES_HTTP_5XX] || 0)
250+
+ ($stat[STAT_RESPONSES_HTTP_XXX] || 0),
251+
http1xx => ($stat[STAT_RESPONSES_HTTP_1XX] || 0),
252+
http2xx => ($stat[STAT_RESPONSES_HTTP_2XX] || 0),
253+
http3xx => ($stat[STAT_RESPONSES_HTTP_3XX] || 0),
254+
http4xx => ($stat[STAT_RESPONSES_HTTP_4XX] || 0),
255+
http5xx => ($stat[STAT_RESPONSES_HTTP_5XX] || 0),
256+
httpxxx => ($stat[STAT_RESPONSES_HTTP_XXX] || 0),
257257
},
258258
};
259259
}
@@ -586,7 +586,7 @@ sub haproxy_timing {
586586
$total+=$data{$service}{'servers'}{$server}{'timing'}{'total'};
587587
}
588588

589-
$values{$service} = ($total/$count);
589+
$values{$service} = ($count > 0 ? $total/$count : 0);
590590
}
591591

592592
mg_fetch(TYPE_BACKEND, ['timing'], \%values);

0 commit comments

Comments
 (0)