Monitor HAProxy in Linux via Check-MK

centos, linux
$ sudo grep -v "#" /etc/haproxy/haproxy.cfg | grep "stats socket"
stats socket /run/haproxy/admin.sock mode 660 level admin expose-fd listeners
$ cd /usr/lib/check_mk_agent/plugins/
$ cat mk_haproxy.linux
if [ -f /var/run/haproxy.pid ]; then
echo "<<>>"
echo "show stat" | socat - UNIX-CONNECT:/run/haproxy/admin.sock
fi
$ chmod +x mk_haproxy.linux

Explanation

  1. Get the location of configured sock for HAProxy from /etc/haproxy/haproxy.cfg
    $ sudo grep -v "#" /etc/haproxy/haproxy.cfg | grep "stats socket"
  2. Get to check-mk plugin directory and write a file named mk_haproxy.linux with above content then save
    $ cd /usr/lib/check_mk_agent/plugins/; vi mk_haproxy.linux
  3. Change permission so it can be executed
    $ chmod +x mk_haproxy.linux
  4. Try to discover the new service in check-mk