Networking HowTos
Networking HowTos

Viewing HAProxy Statistics

March 29, 2012 Linux, Ubuntu

HAProxy is a very capable load balance, but unless you set up the statistics site, you wont easily be able to view the statistics, and in later versions, take down, and bring up back end servers. This is a great feature that allows you to take one of your back end servers offline without shutting down the back end server, or changing any config files. Simply turning off the back end server would do the trick, but sometimes you may want to keep it on, to perform updates, testing, etc, while no one is accessing that particular server.
This guide will step you through the process of setting up access to the statistics web page on the HAProxy server.
Open the haproxy.conf file in your favorite editor.

$ sudo nano /etc/haproxy/haproxy.conf

go to the bottom of the file, and add in the following:

listen stats       #Listen on all IP's on port 9000
    mode http
    timeout client 5000
    timeout connect 4000
    timeout server 30000
    #This is the virtual URL to access the stats page
    stats uri /haproxy_stats
    #Authentication realm. This can be set to anything. Escape space characters with a backslash.
    stats realm HAProxy\ Statistics
    #The user/pass you want to use. Change this password!
    stats auth admin:passwordhere
    #This allows you to take down and bring up back end servers.
    #This will produce an error on older versions of HAProxy.
    stats admin if TRUE

Save your config and exit the editor.
Restart haproxy, or reload the config.
Restart HAProxy:

$ sudo /etc/init.d/haproxy restart

or reload the config (see the Reload HAProxy Config with Minimal Downtime page for more details):

$ sudo haproxy -p /var/run/ -sf $(cat /var/run/

(Note: If you receive an error at this stage, you may have a older version of HAProxy, in which case you will need to comment out the last line that you added above. Eg: the “stats admin if TRUE” line.)
Now you should be able to load a browser on another PC and connect to the IP of the HAProxy server (in my example below,, on port 9000, with the stats URL added to the end:
You should be presented with a username/password prompt. Enter in the details saved in the haproxy.conf file, that you set before.
You should be presented with the statistics page similar to the image below.

You can now enable/disable any back end servers on the fly, and view stats regarding the various front ends and back ends.

You Might Also Like