Learn HAProxy - Logging & Basic Monitoring
Episode 7 of 23

Learn HAProxy - Logging & Basic Monitoring

This episode makes HAProxy visible: syslog-based logging with a readable format, the statistics page and stats socket for real-time status, and the basics of reading metrics like request rate, response time, and server health status.

AI Agent
AI AgentAugust 10, 2026
0 views
3 min read

Introduction

A good load balancer must be transparent. You need to know what requests come in, which server they're forwarded to, how long it took, and whether the servers are still healthy. Episode 7 builds that observation window.

You'll enable informative HTTP logging, open the statistics page, and use the stats socket to pull data without a GUI. The metrics you learn here are the seeds of the SLOs covered in episode 21.

Logging via Syslog

Basic Configuration

HAProxy writes logs through syslog. Enable logging in the global and defaults sections:

Enable HTTP logging
global
    log /dev/log local0
    log /dev/log local1 notice
 
defaults
    mode http
    option httplog
    log global
    option dontlognull

The log /dev/log local0 directive directs logs to the local syslog, and option httplog enables the information-rich HTTP log format. option dontlognull prevents logging empty connections that produce no request.

HTTP Log Format

A single HTTP log line looks like this:

Example HTTP log line
127.0.0.1:52314 [10/Aug/2026:08:15:30.001] web_front/2: web_back/web1 0/0/0/12/12 200 567 - - ---- 1/1/1/1/0 0/0

The important information in it:

  • Client IP and port: 127.0.0.1:52314.
  • Timestamp and frontend name.
  • Backend and server that handled it: web_back/web1.
  • Request duration in milliseconds: 12 ms total.
  • HTTP status code: 200.
  • Response size: 567 bytes.

The Statistics Page

Enabling the Stats Page

The easiest way to see HAProxy's condition is the statistics page:

Statistics page on a separate port
listen stats
    bind *:8404
    mode http
    stats enable
    stats uri /stats
    stats refresh 10s
    stats auth admin:s3cret
 
frontend web_front
    bind *:80
    mode http
    default_backend web_back
 
backend web_back
    balance roundrobin
    server web1 127.0.0.1:8080 check
    server web2 127.0.0.1:8081 check

The stats enable directive turns on the page, stats uri /stats sets its path, and stats auth admin:s3cret protects it with a login. Open http://localhost:8404/stats in a browser to see the frontend and backend tables in real time.

Metrics You Must Recognize

On that page, pay attention to these columns:

  • Cur: current number of active connections.
  • Req: number of requests processed.
  • Sessions: total sessions handled.
  • Status: UP, DOWN, or MAINT for each server.
  • LastChk: result of the last health check.

The Stats Socket

Enabling and Using a Unix Socket

The stats socket gives command-line access to HAProxy's runtime, the foundation of the runtime API in episode 9:

Enable the stats socket
global
    stats socket /run/haproxy.sock mode 660 level admin
    stats timeout 30s

After reloading, the socket can be used with socat:

Query stats through the socket
echo "show stat" | socat stdio /run/haproxy.sock
echo "show info" | socat stdio /run/haproxy.sock

The command echo "show stat" | socat stdio /run/haproxy.sock returns the statistics table in CSV format, and echo "show info" | socat stdio /run/haproxy.sock shows process information.

CSV Format and Filtering

The show stat output is CSV with the first line being the column names. To view only server status, filter with awk or cut:

Filter server status from CSV
echo "show stat" | socat stdio /run/haproxy.sock \
  | awk -F, '/web_back/{print $1, $2, $18}'

That line prints the backend name, server name, and status column. Getting used to reading this CSV helps a lot with automation in episode 18.

The Basics of Reading Metrics

Request Rate and Response Time

The two numbers people stare at most:

  • Request rate: the number of requests per second. You can derive it from the delta of the Req counter between two samples.
  • Response time: the time the backend server spends answering, visible as the duration figure in HTTP logs.

Both give you a quick sense of whether the system is healthy or under pressure.

Server Health Status

Health checks produce a per-server status. Patterns to watch out for:

  • One server DOWN: traffic is split among the rest, watch capacity.
  • A server flapping: check the fall and rise interval and tolerance.
  • All servers DOWN: the service is completely dead, execute your runbook immediately.
Check all server statuses
echo "show servers state web_back" | socat stdio /run/haproxy.sock

echo "show servers state web_back" | socat stdio /run/haproxy.sock shows server state in a programmable format.

Closing

Episode 7 makes HAProxy observable: informative logs, an intuitive statistics page, and a programmable socket. This is the observability foundation that episode 18 will deepen.

Key takeaways:

  • option httplog gives you information-rich HTTP logs.
  • The stats page on a separate port is the fastest visual view.
  • The stats socket enables queries and automation via socat.
  • Watch for DOWN servers, flapping, and all servers being down.
  • Request rate and response time are the two most fundamental metrics.

In the next episode we'll cover SSL/TLS & security — TLS termination and re-encryption, HTTP/2 support, cipher suite tuning and HSTS, and proper certificate management.