How to Interpret HAProxy Stats Page Metrics: Active Connections, Sessions, and Rates


1 views

The HAProxy stats page (accessible via haproxy?stats) provides crucial real-time metrics about your load balancer's performance. For backend monitoring, the most relevant columns are:


# Sample HAProxy stats configuration
listen stats
    bind *:1936
    stats enable
    stats uri /haproxy?stats
    stats refresh 10s

Session vs. Sessions Rate:

  • Session: Shows the current number of active connections to the backend
  • Sessions Rate: Displays new connections per second (a rate metric)

Here's how to parse these values programmatically:


import requests
from bs4 import BeautifulSoup

def get_active_sessions(stats_url):
    response = requests.get(stats_url)
    soup = BeautifulSoup(response.text, 'html.parser')
    
    # Find backend row (adjust selector as needed)
    backend_row = soup.select('tr.backend_row')[0]
    active_sessions = backend_row.select('td.session')[0].text
    
    return int(active_sessions)
Column Description
Last session Seconds since last connection
Queue Current requests waiting
Errors Connection/response errors

For production systems, consider these thresholds:


# Alert if active sessions exceed capacity
if active_sessions > (max_connections * 0.8):
    trigger_alert("Backend nearing capacity")

When working with HAProxy's stats page (typically accessed via http://your-haproxy-ip:port/haproxy?stats), the metrics can be overwhelming without proper context. Let's break down the key columns that matter for backend monitoring.

The Session column shows the total number of sessions since startup, while Sess Rate displays new sessions per second. For current active connections, you should look at:

# Sample haproxy.cfg snippet for stats
listen stats
    bind *:1936
    stats enable
    stats hide-version
    stats uri /haproxy?stats
    stats refresh 30s
Column Meaning Critical for
Cur Current connections Real-time load
Max Maximum connections Capacity planning
Rate Connections per second Traffic spikes

To extract current active connections programmatically:

# Using curl and awk to monitor active connections
curl -s "http://haproxy:1936/haproxy?stats;csv" | \
awk -F, '/backend_name/ {print $5}'  # Column 5 is 'Cur'

Combine multiple metrics for better insights:

  • High Cur with low Sess Rate = Long-lived connections
  • Spiking Rate + high Err = Potential issues