I wanted to monitor the haproxy metrics and read some examples from others using special scripts and also using unix socket and socat. I made some progress but wanted a simpler solution that would be more flexible and easy to add more items when new services were added to haproxy's config.
Here is my solution:
I first need to allow accessing the stats via http. So in the haproxy.cfg file I added:
listen admin
bind *:8080
stats enable
stats auth admin:<MyPASSWORD>
I use curl to access the metrics in csv format. So on the haproxy host I made sure curl was installed (it already was) and then added the following zabbiz config file:
/etc/zabbix/zabbix_agentd.d/userparameter_haproxy.conf
In it I placed:
UserParameter=haproxy.stats[*], curl -u admin:<MyPASSWORD> "http://localhost:8080/haproxy?stats;csv" 2>/dev/null | grep "^$1,$2" | cut -d, -f $3
Now its simple, all I need to do is send 3 params: proxyname, servicename and the column number (+1) of the metric I'm looking for.
So from the zabbix server I can do:
> zabbix_get -s haproxy_hostname -k [haproxy.stats["ProxyName","BACKEND","18"]
< OK
NOTE: passing column # 18 is actualy metric item 17 as reported in the CSV table here: http://cbonte.github.io/haproxy-dcon...n-1.4.html#9.1
Now its easy to add zabbix items for all the metrics needed from haproxy.
I hope this helps others...
-Glen
Here is my solution:
I first need to allow accessing the stats via http. So in the haproxy.cfg file I added:
listen admin
bind *:8080
stats enable
stats auth admin:<MyPASSWORD>
I use curl to access the metrics in csv format. So on the haproxy host I made sure curl was installed (it already was) and then added the following zabbiz config file:
/etc/zabbix/zabbix_agentd.d/userparameter_haproxy.conf
In it I placed:
UserParameter=haproxy.stats[*], curl -u admin:<MyPASSWORD> "http://localhost:8080/haproxy?stats;csv" 2>/dev/null | grep "^$1,$2" | cut -d, -f $3
Now its simple, all I need to do is send 3 params: proxyname, servicename and the column number (+1) of the metric I'm looking for.
So from the zabbix server I can do:
> zabbix_get -s haproxy_hostname -k [haproxy.stats["ProxyName","BACKEND","18"]
< OK
NOTE: passing column # 18 is actualy metric item 17 as reported in the CSV table here: http://cbonte.github.io/haproxy-dcon...n-1.4.html#9.1
Now its easy to add zabbix items for all the metrics needed from haproxy.

I hope this helps others...
-Glen

Comment