How to Monitor haproxy with Cacti
Install package
yum install net-snmp net-snmp-utils –y
Verify installation
rpm -qa | grep net-snmp*
net-snmp-agent-libs-5.7.2-24.el7.x86_64
net-snmp-5.7.2-24.el7.x86_64
net-snmp-libs-5.7.2-24.el7.x86_64
net-snmp-utils-5.7.2-24.el7.x86_64
Edit SNMP configuration file
vi /etc/snmp/snmpd.conf
rocommunity ec1980
syscontact Root <root@localhost> (configure /etc/snmp/snmp.local.conf)
view systemview included .1.3.6.1.2.1.1
view systemview included .1.3.6.1.2.1.25.1.1
access notConfigGroup “” any noauth exact systemview none none
disablePerl false
perl do ‘/etc/snmp/haproxy.pl’;
Open firewall UDP port 161
firewall-cmd –permanent –add-port=161/udp
firewall-cmd –reload
firewall-cmd –list-all
systemctl stop firewalld
systemctl disable firewalld
Start SNMP service
systemctl start snmpd
systemctl enable snmpd
Edit haproxy configuration file # Global settings
vi /etc/haproxy/haproxy.cfg
#———————————————————————
# Global settings
#———————————————————————
global
# to have these messages end up in /var/log/haproxy.log you will
# need to:
.
.
.
.
# stats socket /var/lib/haproxy/stats
stats socket /var/run/haproxy.stat mode 666
Download haproxy installation files from haproxy website to /tmp folder
cd /tmp/
wget http://www.haproxy.org/download/1.5/src/haproxy-1.5.16.tar.gz
tar zxvf haproxy-1.5.16.tar.gz
cd haproxy-1.5.16
cd contrib
cd netsnmp-perl
Copy haproxy.pl to snmp folder
cp haproxy.pl /etc/snmp/
Install perl-Net-SNMP package
yum provides ‘*/Net/SNMP.pm’
yum install epel-release
yum install perl-Net-SNMP
Verify Installation
rpm -qa | grep net-snmp*
net-snmp-agent-libs-5.7.2-24.el7.x86_64
net-snmp-5.7.2-24.el7.x86_64
net-snmp-perl-5.7.2-24.el7.x86_64
net-snmp-libs-5.7.2-24.el7.x86_64
net-snmp-utils-5.7.2-24.el7.x86_64
Restart snmp service
systemctl restart snmp
Restart haproxy service
service haproxy restart
Validate haproxy perl script
perl /etc/snmp/haproxy.pl # even if this doesn’t work check that the query works.
Validate internal SNMP query works
snmpwalk -v 1 -c ec1980 -O e 127.0.0.1
snmpbulkwalk -c ec1980 -v2c 127.0.0.1 1.3.6.1.4.1.29385.106.2.0
Copy cacti XML files from haproxy installation files to cacti resource folders
C:\inetpub\wwwroot\cacti\resource\snmp_queries
cacti_data_query_haproxy_backends.xml
cacti_data_query_haproxy_frontends.xml
haproxy_backend.xml
haproxy_frontend.xml
haproxy_socket.xml
C:\inetpub\wwwroot\cacti\resource\script_queries
haproxy_backend.xml
haproxy_frontend.xml
haproxy_socket.xml
C:\inetpub\wwwroot\cacti\resource\script_server
haproxy_backend.xml
haproxy_frontend.xml
haproxy_socket.xml
Add data query and graphs
Finish!