Monitor Haproxy with Munin

15 09 2012

I wrote several plugins to monitor haproxy with munin. Basically, they draw the ​values in the ​Haproxy csv  file.

The installation is very simple:

– Install dependencies:
# apt-get install curl socat coreutils

– Download plugins from Munin Contrib repository:

haproxy_abort_backend
haproxy_active_backend
haproxy_bytes_backend
haproxy_bytes_frontend
haproxy_denied_backend
haproxy_denied_frontend
haproxy_errors_backend
haproxy_errors_frontend
haproxy_queue_backend
haproxy_rate_backend
haproxy_rate_frontend
haproxy_reqrate_frontend
haproxy_responses_backend
haproxy_responses_frontend
haproxy_sessions_backend
haproxy_sessions_frontend
haproxy_sessions_total_backend
haproxy_sessions_total_frontend
haproxy_warnings_backend

https://github.com/munin-monitoring/contrib/tree/master/plugins/haproxy

– Copy the files to “/etc/munin/plugins/”

– Edit the file “/etc/munin/plugin-conf.d/munin-node” and add the following content. You can monitor Haproxy trought http or unix sockets, this is http method:
[haproxy*]
user root
env.backend back-name1 back-name2 back-name3 back-back-name4
env.frontend front-name1 front-name2 front-name3
env.url http://USER:PASSWD@IP:PORT/admin?stats;csv

and this if for unix sockets:
[haproxy*]
user root
env.backend back-name1 back-name2 back-name3 back-back-name4
env.frontend front-name1 front-name2 front-name3
env.socket /var/lib/haproxy/stats.socket

In Haproxy, you can configure the request of the csv trought unix sockets or trought http:

Trought unix socket, add this to the global section (change user and group with the correc user and group):
stats socket /var/run/haproxy.sock mode 0644 user group

and ensure that this works with:
# echo 'show stat' | socat unix-connect:/var/lib/haproxy/stats.socket stdio

Trought http, add this to the conf, basically create a listen: (change ip, port, user, pass):
listen proxy-stats IP:PORT
mode http
option httplog
stats enable
stats show-legends
stats uri /admin?stats
stats realm Haproxy\ Statistics
stats auth user:pass
stats refresh 5s

and ensure that this works with:
# curl 'http://USER:PASSWD@IP:PORT/admin?stats;csv'

– Restart munin-node and wait a few minutes until the graphs will be painted.
# /etc/init.d/munin-node restart

Here are several examples of the graphs:

haproxy_abort_backend-day.png

haproxy_active_backend-day.png

haproxy_bytes_backend-day.png

haproxy_bytes_frontend-day.png

haproxy_denied_backend-day.png

haproxy_denied_frontend-day.png

haproxy_errors_backend-day.png

haproxy_errors_frontend-day.png

haproxy_queue_backend-day.png

haproxy_rate_backend-day.png

haproxy_rate_frontend-day.png

haproxy_reqrate_frontend-day.png

haproxy_responses_backend-day.png

haproxy_responses_frontend-day.png

haproxy_sessions_backend-day.png

haproxy_sessions_frontend-day.png

haproxy_sessions_total_backend-day.png

haproxy_sessions_total_frontend-day.png

haproxy_warnings_backend-day.png

More info:
http://haproxy.1wt.eu/
http://munin-monitoring.org/

Advertisements

Actions

Information

9 responses

17 06 2013
Iskandar

I have problem with generating the images. The graphs somehow did not generated, but the html was generated

26 06 2013
Andy

I had the same problem, but found a fix. In the configuration section, remove the space between haproxy and *, so

[haproxy*]
user root
….etc…

5 07 2013
rfrail3

Fixed, Thanks!

17 03 2015
Michael

Hello,

I have problem with some plugins, only haproxy_bytes_frontend works.

For example : munin-run haproxy_abort_backend

cli_abrt69b9a2ad6626e841b22c5a51f39f684d.value
srv_abrt69b9a2ad6626e841b22c5a51f39f684d.value
cli_abrtf6343cd81c9877b3fc41726a5a5b8695.value
srv_abrtf6343cd81c9877b3fc41726a5a5b8695.value
cli_abrtdc593d53801330a4c53cdd71a48b1b1d.value
srv_abrtdc593d53801330a4c53cdd71a48b1b1d.value
cli_abrtd3a98f9d3819cc4f94e002c350b7ffcc.value
srv_abrtd3a98f9d3819cc4f94e002c350b7ffcc.value
cli_abrtf87d49fac2db59a3d8c79ba42b2af665.value
srv_abrtf87d49fac2db59a3d8c79ba42b2af665.value
cli_abrt29e00a817dc352f02217f69202ec29e3.value
srv_abrt29e00a817dc352f02217f69202ec29e3.value
cli_abrt90b425bf5a228d74998925659a5e2ebb.value
srv_abrt90b425bf5a228d74998925659a5e2ebb.value
cli_abrt8559d5316adfd51a832771f413352e60.value
srv_abrt8559d5316adfd51a832771f413352e60.value
cli_abrt59768e2629fbd94a529f48a51f6d6212.value
srv_abrt59768e2629fbd94a529f48a51f6d6212.value

my configuration file /etc/munin/plugin-conf.d/munin-node

[haproxy*]
user root
env.backend xxx.com yyy
env.frontend webx weby
env.url https://admin:xxx@127.0.0.1:2222/admin?stats;csv

haproxy 1.7.0
munin 2.0.6-4
debian 7.8

Do you have an idea ?

Best Regards.

17 03 2015
rfrail3

Can you try to get the stats with socket, avoiding url?

Regards,

17 03 2015
Michael

I changed to this :

env.socket /tmp/haproxy_prod_admin.sock
env.stats socket /tmp/haproxy_prod_admin.sock mode 0644 root haproxy

my tmp file haproxy_prod_admin.sock (owner root haproxy)

when i try munin-run :

munin-run haproxy_active_backend
2015/03/17 17:14:00 socat[19866] E write(1, 0x1ef8ba0, 3232): Broken pipe
act69b9a2ad6626e841b22c5a51f39f684d.value 2
1
2
2
2
2015/03/17 17:14:00 socat[19885] E write(1, 0x151dba0, 3232): Broken pipe
actf6343cd81c9877b3fc41726a5a5b8695.value 2
2015/03/17 17:14:00 socat[19904] E write(1, 0x1aafba0, 3232): Broken pipe
actdc593d53801330a4c53cdd71a48b1b1d.value 1
actd3a98f9d3819cc4f94e002c350b7ffcc.value 4
2015/03/17 17:14:00 socat[19942] E write(1, 0x262bba0, 3232): Broken pipe
actf87d49fac2db59a3d8c79ba42b2af665.value 4
act29e00a817dc352f02217f69202ec29e3.value 1
2015/03/17 17:14:00 socat[19980] E write(1, 0x264eba0, 3232): Broken pipe
act90b425bf5a228d74998925659a5e2ebb.value 9
act8559d5316adfd51a832771f413352e60.value 1
2015/03/17 17:14:00 socat[20018] E write(1, 0x17b3ba0, 3232): Broken pipe
act59768e2629fbd94a529f48a51f6d6212.value 1
17

I have values but i get an broken pipe error ? do you have an idea ?

Regards

19 03 2015
Michael

Hi,

Any idead ?

Regards

20 03 2015
rfrail3

Please, can you give the output of:
echo ‘show stat’ | socat unix-connect:/tmp/haproxy_prod_admin.sock stdio

23 03 2015
Michael

Hi,

this is the output of the command :

echo ‘show stat’ | socat unix-connect:/tmp/haproxy_prod_admin.sock stdio
# pxname,svname,qcur,qmax,scur,smax,slim,stot,bin,bout,dreq,dresp,ereq,econ,eresp,wretr,wredis,status,weight,act,bck,chkfail,chkdown,lastchg,downtime,qlimit,pid,iid,sid,throttle,lbtot,tracked,type,rate,rate_lim,rate_max,check_status,check_code,check_duration,hrsp_1xx,hrsp_2xx,hrsp_3xx,hrsp_4xx,hrsp_5xx,hrsp_other,hanafail,req_rate,req_rate_max,req_tot,cli_abrt,srv_abrt,comp_in,comp_out,comp_byp,comp_rsp,lastsess,last_chk,last_agt,qtime,ctime,rtime,ttime,
web1,FRONTEND,,,41,168,2048,186080,9111409836,13999214643,7,0,25270,,,,,OPEN,,,,,,,,,1,2,0,,,,0,1,0,64,,,,0,457094,24966,36260,148,11,,9,120,518506,,,0,0,0,0,,,,,,,,
xxx.xxx.xxx,web3,0,0,0,6,,7461,3564177,407313305,,0,,0,0,0,0,UP,1,1,0,0,0,39170,0,,1,11,1,,7461,,2,0,,22,L4OK,,0,0,6113,778,570,0,0,0,,,,24,0,,,,,9,,,0,0,2,402,
yyy,BACKEND,0,0,0,0,205,0,0,0,0,0,,0,0,0,0,UP,2,2,1,,0,39170,0,,1,12,0,,0,,1,0,,0,,,,0,0,0,0,0,0,,,,,0,0,0,0,0,0,-1,,,0,0,0,0,
zzz-ppr27,BACKEND,0,0,0,0,205,0,0,0,0,0,,0,0,0,0,UP,2,2,0,,1,18338,48,,1,17,0,,0,,1,0,,0,,,,0,0,0,0,0,0,,,,,0,0,0,0,0,0,-1,,,0,0,0,0,
noname,prod5,0,0,0,1,,66,8580,10560,,0,,0,0,0,0,UP,1,1,0,0,0,39170,0,,1,18,1,,66,,2,0,,1,L4OK,,0,0,66,0,0,0,0,0,,,,0,0,,,,,459,,,0,1,113,113,
admin,FRONTEND,,,0,2,2048,85155,278445,49181293,0,0,83057,,,,,OPEN,,,,,,,,,1,26,0,,,,0,0,0,99,,,,0,2098,0,83058,0,0,,0,99,85156,,,0,0,0,0,,,,,,,,
admin,BACKEND,0,0,0,0,205,0,278445,49181293,0,0,,0,0,0,0,UP,0,0,0,,0,39170,0,,1,26,0,,0,,1,0,,0,,,,0,0,0,0,0,0,,,,,0,0,0,0,0,0,135,,,0,0,0,6,

my configuration

/etc/munin/plugin-conf.d/munin-node

[haproxy*]
user root
env.backend yyy zzz xxx
env.frontend web1 web2
env.socket /tmp/haproxy_prod_admin.sock

srw-rw—- 1 root nagios 0 Mar 23 04:55 haproxy_prod_admin.sock

Regards

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s




%d bloggers like this: