1. The native statistics page #
A lightweight web interface to monitor your servers.
Configuring the listen block #
It is recommended to listen on a separate port and protect access with a password.
listen stats
bind *:8404
stats enable
stats uri /admin?stats
stats refresh 10s
stats auth admin:MonMotDePasse2. Integration with Prometheus #
Exposing metrics for long-term monitoring.
Using the prometheus-exporter module #
Since version 2.0, HAProxy can expose metrics directly in Prometheus format without a third-party agent.
frontend stats
bind *:8405
http-request use-service prometheus-exporter if { path /metrics }3. Native OpenTelemetry (OTLP) support #
HAProxy now integrates with the industry standard for traces and metrics.
Exporting to an OTLP collector #
Since version 2.9, HAProxy natively supports OpenTelemetry. This feature sends telemetry data directly to an OTel collector (or tools such as Jaeger, Honeycomb or Grafana Tempo) without an intermediate agent.
What it brings:
- Standardization: a single format for traces and metrics, compatible with all modern tools.
- Distributed traces: correlate a request going through HAProxy with your microservices' traces for end-to-end debugging.
- Rich data: export precise metadata about the HTTP request life cycle.
# Exemple de configuration (nécessite le module otlp.so)
module-load /usr/lib/haproxy/otlp.so
otlp
endpoint my-otel-collector:4317
interval 5s
add-header x-otel-traceid4. Interpreting key indicators #
Which metrics should you monitor first?
Sessions and errors #
- Cur: number of active connections.
- Rate: number of new connections per second.
- Check status: health of the backend servers.
- Errors (Req/Resp): 4xx or 5xx error rate.
Conclusion #
Observability is key.
Anticipating failures #
With statistics, you can detect a server that is slowing down before it fails completely.
Hands-on: stats page, Runtime API and Prometheus #
Enabling and using statistics.
Enabling the statistics page #
listen stats
bind 127.0.0.1:8404
mode http
stats enable
stats uri /stats
stats refresh 5s
stats auth admin:MotDePasseFort
stats admin if LOCALHOST # permet de mettre un serveur en maintenance depuis l'UIcurl -s -u admin:MotDePasseFort "http://127.0.0.1:8404/stats;csv" | head -3
ssh -L 8404:127.0.0.1:8404 admin@lb1 # accéder à la page sans l'exposerRuntime API with socat #
# global : stats socket /var/run/haproxy.sock mode 660 level admin
echo "show info" | sudo socat stdio /var/run/haproxy.sock | head
echo "show servers state" | sudo socat stdio /var/run/haproxy.sock
echo "set server app/web3 state maint" | sudo socat stdio /var/run/haproxy.sock # sortir un serveur
echo "set server app/web3 state ready" | sudo socat stdio /var/run/haproxy.sock
echo "set server app/web1 weight 50%" | sudo socat stdio /var/run/haproxy.sockExporting to Prometheus #
frontend prometheus
bind *:8405
mode http
http-request use-service prometheus-exporter if { path /metrics }
no log# prometheus.yml
scrape_configs:
- job_name: haproxy
static_configs: [{ targets: ["lb1:8405", "lb2:8405"] }]
# PromQL utiles
sum by (proxy) (rate(haproxy_frontend_http_responses_total{code="5xx"}[5m]))
haproxy_backend_up == 0
haproxy_backend_current_queue > 0My progress
Sign in to track your progress and take notes. Sign in
💬 Questions about this lesson
No questions yet: be the first to ask for help or share your configuration.
Recommended Articles
HAProxy in Kubernetes: the high-performance Ingress Controller
Discover in depth how HAProxy integrates with Kubernetes: direct-to-pod architecture, hot update ...
HAProxy: a detailed guide to configuration directives
A complete exploration of HAProxy's essential directives: from bind to http-check, learn how to c...
Visualizing your infrastructure with HAProxy Topology Visualizer
Learn how to use HAProxy Topology Visualizer to turn complex haproxy.cfg files into interactive d...
HAProxy as a Kubernetes Ingress Controller: the production guide
Learn how to use HAProxy as an Ingress Controller in Kubernetes: direct-to-pod architecture, TLS ...
HAProxy: adding and removing backends dynamically
Learn how to use the HAProxy Runtime API to create, configure and delete backends and servers on ...
HAProxy best practices: optimization, security and high availability
Discover the best practices for configuring HAProxy to ensure the performance, security and resil...
Mastering ACLs in HAProxy: the complete guide
A complete guide to HAProxy ACLs: learn how to configure smart routing, IP-based access control, ...
Mastering ACLs in HAProxy
A complete guide to HAProxy ACLs: learn how to configure smart routing, IP-based access control, ...
Anatomy of HAProxy configuration, clustering and high availability
Understand the structure of an haproxy.cfg file: the global, defaults, frontend (high performance...