enable haproxy stats

How to Enable HAProxy Stats

HAProxy Stats is a useful application that provides useful information about total connection, data transfer, server state and more. Since it is browser-based you can easily get live stats about your HAProxy deployment via web browser. In this article, we will look at how to enable HAProxy Stats in your system. Follow these steps only if after you have installed and configured HAProxy on your server.


How to Enable HAProxy Stats

Here are the steps to Enable HAProxy Stats.


1. Enable HAProxy Statistics

Open terminal and run the following command to open HAProxy configuration file.

$ sudo vi /etc/haproxy/haproxy.cfg

Add the following lines in it, after ‘defaults’ section. Replace 192.168.1.1 with your server’s IP address.

listen  stats   192.168.1.1:1936
        mode            http
        log             global

        maxconn 10

        clitimeout      100s
        srvtimeout      100s
        contimeout      100s
        timeout queue   100s

        stats enable
        stats hide-version
        stats refresh 30s
        stats show-node
        stats auth admin:password
        stats uri  /haproxy?stats

In the above code, the IP address in first line is the IP at which HAProxy stats is available. Also, we have configured it to listen to port 1936. When you try to access HAProxy stats via web browser, you will be asked for username & password. The last but one line contains the username and password as admin and password respectively. You can change it as per your requirement. Also, the last line contains the URL at which you can access HAProxy stats.


2. Access HAProxy via web browser

Open web browser and go to http://192.168.1.1:1936/haproxy?stats

You will see a login prompt. Enter the username and password you have specified above.

That’s it. It is very to setup HAProxy stats.


3. Update Login Details

If you want to change login details open HAProxy configuration file and update the line

stats auth  admin:password

Replace admin and password with your new username and password respectively.


4. Change HAProxy Stats URL

If you want to change the URL at which HAProxy Stats is available, then open HAProxy configuration file and update the line.

stats uri  /haproxy?stats

to your new desired URL.

Save and exit configuration file. Restart HAProxy to apply changes.

HAProxy is one of the best load balancer to build high availability systems. It can be easily configured with popular servers like Apache, Tomcat, NGINX, etc. In this article, we have learnt how to enable HAProxy stats on your system. After you have installed and configured HAProxy on your system, you can enable its stats to get real-time information about your load balancer.

Also read:

How to Convert DEB to RPM in Linux
How to Configure ACL in Linux
How to Concatenate Multiple Lists in Python
How to Get MD5 Hash of String in Python
How to Split String by Delimiter in Python

Leave a Reply

Your email address will not be published. Required fields are marked *