- A Cloud Guru
Exploring Basic HAProxy Monitoring Techniques
It’s not enough to just set up an HAProxy installation, we need to keep an eye on the status of the environment and the servers in our backend. Whether this means keeping an eye on statistics or the contents of logs, HAProxy has you covered. In this lab, we’re going to get hands-on with managing an HAProxy environment. We’re going to explore some monitoring options that are installed along with HAProxy. Upon completion of this lab, you will know how to leverage some included features to monitor your HAProxy environment.
Table of Contents
Interact Directly with the HAProxy stats Socket
Look at and monitor the status of our HAProxy installation by directly interacting with the
Look at the socket, using
Let's try some non-interactive commands. Pull raw data from the
nc, by sending the
show statcommand to the
It returns a lot of information in a format that's not really human-friendly, but it can be reformatted.
Add some formatting using
column, and a looping mechanism using
watch. Pick as many or as few fields as you like. Play around with the formatting and see what you can come up with.
You should see that we're getting statistics for the fields we specified in the
cutcommand, then using
columnto make a nicely formatted table. The
watchcommand refreshes every second until we interrupt it with
Try an interactive connection using
This will connect us to the socket and allow us to enter one command.
promptcommand to get an interactive interface. If you'd like help, use
?. Sending an empty line or using the
quitcommand followed by
ENTERwill get you out of the prompt.
So, this is the most direct, hands-on way to do it, but it's a lot of overhead for daily use, unless we put a framework around it. Is there a better way?
Using the HAProxy stats Web Interface
/var/lib/haproxy/statssocket is extremely useful, but manual interaction is a bit cumbersome. What if we had a better way to leverage it?
Add a code block to the end of the
/etc/haproxy/haproxy.cfgfile that starts an HAProxy
statsweb server on port
8050for all addresses at the URI of
Hide the version of HAProxy in the statistics report for better security.
Connect to the
statsweb page on port
8050on the public IP (or DNS) of the lab server and check things out.
We've got a nice, clean, web-based interface that presents our statistics in an easy-to-read format. If we want to update our statistics, we're just a refresh away.
Examining HAProxy Logs Using HALog
Another handy utility we can use to get a handle on what's happening in our HAProxy environment is the inlcuded
Before we dig deeper into the logs, we need to put more data in.
Launch 2 ApacheBench sessions:
ab -n 100 -c 10 https://www.site1.com/ > ~/ab_site1.log > /dev/null 2>&1 &
ab -n 100 -c 10 https://www.site2.com/ > ~/ab_site2.log > /dev/null 2>&1 &
Pull HTTP traffic using
for conn in `seq 1 100` ; do curl -k https://www.site1.com/ ; done > /dev/null 2>&1 &
for conn in `seq 1 100` ; do curl -k https://www.site2.com/ ; done > /dev/null 2>&1 &
Pull HTTP traffic using
for conn in `seq 1 100` ; do wget --no-check-certificate -O - https://www.site1.com/test.txt ; done > /dev/null 2>&1 &
for conn in `seq 1 100` ; do wget --no-check-certificate -O - https://www.site2.com/test.txt ; done > /dev/null 2>&1 &
for conn in `seq 1 100` ; do bash -c 'scp -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null -P 2222 [email protected]:/sshfiles/ssh-test.txt . &' ; done > /dev/null 2>&1 &
Now that our logs are filled with data, we can proceed!
Extract data from the
- Pull data on per-server HTTP statistics
- List URLs by the number of HTTP requests
- List URLs with 429 errors
- List URLs by the number of errors generated
- Try some of your own!
halogis a handy tool for parsing HAProxy logs to present the information contained within in an easy-to-read format that tells us exactly what we're looking for.
Congratulations, Cloud Guru! You mastered 3 helpful monitoring methods that come with HAProxy!
What's a lab?
Hands-on Labs are real environments created by industry experts to help you learn. These environments help you gain knowledge and experience, practice without compromising your system, test without risk, destroy without fear, and let you learn from your mistakes. Hands-on Labs: practice your skills before delivering in the real world.