As an administrator you know that monitoring a service is essential. With HAProxy, there are stats for which you will want to know that aren’t presented to you through TOP or in log files. To make these stats visible, HAProxy can create socket file that can then be accessed by a third-party application to extract the stats. One of the best and most popular is HATOP.
HATop is written in Python. Before you can use it to monitor your load balancer, you should ensure that Python 2 is installed. Most distributions install it by default, even in minimal installations.
The package is available from Ubuntu’s default repositories. This makes it a lot easier to install, as compared with other Linux Distributions.
- Install HATOP
sudo apt-get install hatop -y
CentOS \ Debian \ etc
To install HATOP on other Linux distributions, you will need to download the tar file from the project’s website.
- Download the latest tar file from the project’s website.
- Extract the contents from the downloaded tar file.
tar xvf hatop-0.7.7.tar.gz
- Change into the newly extracted directory.
- Install the HATOP python scripts to /usr/local/bin and set permissions to 755.
install -m 755 bin/hatop /usr/local/bin
- Install the HATOP man files.
install -m 644 man/hatop.1 /usr/local/share/man/man1
- Compress the man files.
Create HAPRoxy Socket
To allow HATOP to collect stats from HAProxy, we need to configure HAProxy so that it creates a socket file. This socket file is what HATOP needs to access the different statistics.
- Open the HAProxy configuration file in a text editor.
- Under the global section of the configuration file, add the stats option as seen in the example below.
stats socket /var/run/haproxy.sock mode 600 level admin
- Restart the HAProxy service to create the new socket.
sudo service haproxy restart
As an alternative, you could also reload haproxy instead to minimize down time in a production environment.