How to Monitor Your HAProxy Load Balancer with Vigilmon
HAProxy is the industry standard for high-performance TCP and HTTP load balancing. It handles traffic distribution for some of the world's most demanding production systems. But HAProxy failures are catastrophic: when your load balancer goes down, all backend services become unreachable simultaneously.
This guide shows you how to monitor HAProxy with Vigilmon — from the built-in stats page to backend server health.
HAProxy's Built-in Health Features
HAProxy has two native monitoring mechanisms:
1. Stats Page
HAProxy can expose a web-based stats page:
# In your haproxy.cfg
listen stats
bind *:8404
stats enable
stats uri /stats
stats refresh 30s
stats auth admin:strongpassword
This gives you real-time data on:
- Active/down backend servers
- Current connections and queue depth
- Request rates and response times
- Health check status per backend
2. Health Check on Frontend
You can expose a simple health endpoint for external monitoring:
frontend health-check
bind *:8405
default_backend health-backend
backend health-backend
server health-server 127.0.0.1:9000 check
errorfile 503 /etc/haproxy/errors/503-health.http
Step 1: Enable HAProxy Stats API
Enable the CSV stats endpoint:
listen stats
bind *:8404
stats enable
stats uri /stats
stats auth monitoring:$STATS_PASSWORD
stats hide-version
stats refresh 10s
Now curl http://localhost:8404/stats;csv returns machine-readable stats.
Step 2: Create a Health Proxy Application
Node.js example:
const express = require('express');
const axios = require('axios');
const csvParser = require('csv-parse/sync');
const app = express();
app.get('/health/haproxy', async (req, res) => {
try {
const response = await axios.get(
`http://localhost:8404/stats;csv`,
{
auth: { username: 'monitoring', password: process.env.STATS_PASSWORD },
timeout: 5000
}
);
// Parse CSV
const rows = csvParser.parse(response.data, { columns: true, skip_empty_lines: true });
// Find backend servers with DOWN status
const backends = rows.filter(r => r.svname !== 'FRONTEND' && r.svname !== 'BACKEND');
const downServers = backends.filter(r => r.status === 'DOWN');
if (downServers.length > 0) {
return res.status(503).json({
status: 'degraded',
down_servers: downServers.map(s => ({
backend: s['# pxname'],
server: s.svname,
last_check: s.lastchk
}))
});
}
// Check if all backends are UP
const allDown = backends.every(r => r.status === 'DOWN');
if (allDown && backends.length > 0) {
return res.status(503).json({ status: 'all_backends_down' });
}
res.json({
status: 'ok',
total_servers: backends.length,
active_servers: backends.filter(r => r.status === 'UP').length
});
} catch (err) {
res.status(503).json({ status: 'error', message: err.message });
}
});
app.listen(3000);
Python example:
from fastapi import FastAPI, Response
import httpx
import csv
import io
import json
app = FastAPI()
@app.get("/health/haproxy")
async def health_haproxy():
try:
async with httpx.AsyncClient(timeout=5.0) as client:
r = await client.get(
"http://localhost:8404/stats;csv",
auth=("monitoring", "password")
)
r.raise_for_status()
reader = csv.DictReader(io.StringIO(r.text))
servers = [row for row in reader
if row['svname'] not in ('FRONTEND', 'BACKEND')]
down = [s for s in servers if s['status'] == 'DOWN']
if down:
return Response(
content=json.dumps({"status": "degraded", "down": len(down)}),
status_code=503
)
return {"status": "ok", "servers": len(servers)}
except Exception as e:
return Response(content=str(e), status_code=503)
Step 3: Add Vigilmon HTTP Monitors
- Log in to vigilmon.online → Add Monitor
-
Monitor 1 — HAProxy health:
- URL:
https://your-domain.com/health/haproxy - Alert if: Status != 200
- URL:
-
Monitor 2 — Public frontend check:
- URL:
https://your-domain.com(the HAProxy frontend) - Alert if: Status != 200 or > 2000ms
- URL:
- Interval: 60 seconds
Vigilmon checks from multiple global regions — so you'll know if HAProxy is failing in one geographic area but not another.
Step 4: SSL Certificate Monitoring
If HAProxy terminates SSL (common setup), add a Vigilmon SSL certificate monitor:
- Add Monitor → Type: SSL Certificate
- Hostname:
your-domain.com - Alert: If expires in < 14 days
HAProxy Monitoring Coverage Table
| Monitor | Endpoint | Alerts On |
|---|---|---|
| HAProxy health | /health/haproxy |
Backend servers DOWN |
| Public frontend | https://your-domain.com |
HAProxy itself down |
| SSL certificate | your-domain.com |
Cert expiry < 14 days |
Common HAProxy Failure Patterns
Backend server goes offline: One of three web servers in a backend pool crashed. HAProxy's own health checks marked it DOWN, but the traffic continued to the remaining 2 servers. Vigilmon's backend monitor immediately alerted on the degraded state — allowing the team to investigate before the remaining 2 servers were overloaded.
HAProxy process crash: HAProxy's master process died after a misconfigured reload. All traffic stopped. The public frontend monitor caught it within 60 seconds.
SSL cert expires on HAProxy: A wildcard SSL cert wasn't renewed before expiry. HAProxy terminated connections with an expired cert. Vigilmon's SSL monitor would have alerted 14 days earlier.
Conclusion
HAProxy is a critical single point of failure for your infrastructure. Vigilmon's multi-region HTTP monitoring ensures you know the moment HAProxy or any backend server fails — not when your users start reporting problems.
Top comments (0)