HAProxy Traffic Capture

This guide shows you how to use Qtap to capture HTTP traffic flowing through HAProxy, the industry-standard high-performance load balancer. You'll learn how to observe both incoming client requests and outgoing backend connections, all without proxies or code changes.

What You'll Learn

  • Capture HAProxy ingress traffic (client requests)

  • Capture HAProxy egress traffic (backend server requests)

  • Monitor load balancing across multiple backends

  • Observe health checks and failover behavior

  • Apply conditional capture rules for specific backends

  • Set up HAProxy + Qtap in Docker for testing

  • Deploy production-ready configurations

Use Cases

Why capture HAProxy traffic?

  • Load Balancer Analytics: Understand traffic distribution across backend servers

  • Health Check Monitoring: Observe health check behavior and failover events

  • Performance Analysis: Measure latency and identify slow backends

  • Debugging Load Balancing: Verify sticky sessions and routing algorithms

  • API Gateway Monitoring: Track all API calls through your edge load balancer

  • Compliance & Audit: Record all traffic for regulatory requirements

  • Troubleshooting: Debug issues between client and backend servers


Prerequisites

  • Linux system with kernel 5.10+ and eBPF support

  • Docker installed (for this guide's examples)

  • Root/sudo access

  • Basic understanding of HAProxy configuration


Part 1: HAProxy Load Balancer Setup

HAProxy uses its own configuration file format. Let's set up a load balancer with multiple backend servers.

Step 1: Create Project Directory

Step 2: Create HAProxy Configuration

Create haproxy.cfg:

Step 3: Create Backend Service

Create backend-service.py:

Step 4: Create Qtap Configuration

Create qtap.yaml:

Step 5: Create Docker Compose Setup

Create docker-compose.yaml:

Key HAProxy Concepts:

  • Frontend: Listens for incoming connections

  • Backend: Defines pool of servers to route to

  • ACL (Access Control List): Rules for routing decisions

  • Balance Algorithm: roundrobin, leastconn, source, etc.

  • Health Checks: Automatic checking of backend server health


Part 2: Running and Testing

Step 1: Start the Services

Step 2: Generate Test Traffic

Step 3: View Captured Traffic

What you should see:

Key indicators:

  • "exe" contains haproxy - Process identified

  • Direction: INGRESS - Client → HAProxy

  • Direction: EGRESS - HAProxy → Backend server

  • Two transactions per request (ingress + egress)

  • ✅ Load distribution visible (different backend servers)

  • ✅ Backend server name in egress URL


Part 3: Advanced Configurations

Configuration 1: Monitor Load Balancing Distribution

Capture only egress traffic to see which backend serves each request:

Analyze logs to see traffic distribution across backends.

Configuration 2: Capture Health Check Failures

Monitor health check behavior and backend failures:

Configuration 3: Backend-Specific Capture

Capture different levels for different backend pools:

Configuration 4: Production Setup with S3


Part 4: Real-World Use Cases

Use Case 1: Debugging Sticky Sessions

Monitor sticky session behavior (source IP-based persistence):

haproxy.cfg:

qtap.yaml:

Generate traffic from same IP and verify it goes to the same backend.

Use Case 2: Blue/Green Deployment Monitoring

Monitor traffic split during blue/green deployments:

haproxy.cfg:

qtap.yaml:

Analyze logs to verify 90/10 split and monitor error rates per version.

Use Case 3: API Rate Limiting Detection

Monitor for rate limiting and throttling:

qtap.yaml:

Use Case 4: Multi-Datacenter Load Balancing

Monitor traffic distribution across multiple datacenters:

haproxy.cfg:

qtap.yaml:


Understanding HAProxy + Qtap

Dual Capture for Load Balancing

When HAProxy routes a request, Qtap captures two transactions:

Transaction 1: INGRESS (Client → HAProxy)

Transaction 2: EGRESS (HAProxy → Backend)

This lets you:

  • See which backend served each request

  • Measure HAProxy overhead (ingress duration - egress duration)

  • Verify load balancing algorithm behavior

  • Detect backend-specific issues

HAProxy-Specific Features

Process Identification:

  • Look for exe containing haproxy

  • Typically /usr/local/sbin/haproxy

Load Balancing Algorithms:

  • roundrobin: Rotate through backends equally

  • leastconn: Send to backend with fewest connections

  • source: Sticky sessions based on source IP

  • uri: Route based on request URI

Qtap shows which backend was chosen for each request.

Health Checks:

  • HAProxy constantly health checks backends

  • Qtap captures these checks (can be filtered out)

  • Failed health checks visible in logs


Troubleshooting

Not Seeing HAProxy Traffic?

Check 1: Is HAProxy running?

Check 2: Is Qtap running before requests?

Check 3: Are backends healthy?

Check 4: Is ignore_loopback correct?

Seeing Only Health Checks?

Health checks are noisy. Filter them out:

Or in rules:

Backend Server Down?

If a backend is down, HAProxy won't route to it. Check logs:

Too Much Traffic?

Apply conditional capture:


Performance Considerations

HAProxy + Qtap Performance

  • CPU: ~1-3% overhead

  • Memory: ~50-200MB for Qtap

  • Latency: Zero additional latency (passive observation)

HAProxy is extremely performance-sensitive. Best practices:

  1. Use level: summary for high volume

  2. Filter health checks (very noisy)

  3. Capture selectively with rules

  4. Send to S3 with batching

  5. Monitor Qtap resource usage

Scaling Recommendations

Traffic Volume

Recommended Level

Notes

< 1000 req/sec

full

Capture everything

1000-10000 req/sec

details

Headers only

10000-100000 req/sec

summary

Metadata only

> 100000 req/sec

conditional

Errors only, aggressive filtering

HAProxy can handle millions of connections. Qtap scales with it.


HAProxy vs NGINX/Caddy/Traefik

Purpose:

  • HAProxy: Dedicated load balancer (Layer 4 + Layer 7)

  • NGINX: Web server + reverse proxy + load balancer

  • Caddy: Web server + automatic HTTPS

  • Traefik: Cloud-native reverse proxy

Performance:

  • HAProxy: Extreme performance, lowest latency

  • Others: Fast, but not HAProxy-level

Configuration:

  • HAProxy: Own syntax, focused on load balancing

  • NGINX: nginx.conf

  • Caddy: Caddyfile

  • Traefik: Docker labels/YAML

Qtap Compatibility:

  • All work perfectly with Qtap

  • Same capture quality across all


Next Steps

Learn More About Qtap:

Production Deployment:

Related Guides:

Alternative: Cloud Management:

  • Qplane - Manage Qtap with visual dashboards


Cleanup


This guide uses validated configurations. All examples are tested and guaranteed to work with HAProxy and Qtap.

Last updated