How to Efficiently Monitor HAProxy with Prometheus and Grafana
This guide explains how to set up HAProxy monitoring by configuring a Prometheus exporter, adding HAProxy targets to Prometheus, verifying metric collection, and visualizing the data in Grafana with a ready-made dashboard, ensuring reliable and performant services.
In today's fast‑moving internet era, users expect high availability and fast response from online services, and operators must keep websites and applications running 24/7. HAProxy is a popular load‑balancer, but effective monitoring is essential for its health.
Enable HAProxy Monitoring
Deploy a Prometheus exporter on HAProxy by adding a frontend that listens on port 8405 and exposes the
/metricsendpoint.
<code>frontend prometheus
bind *:8405
mode http
http-request use-service prometheus-exporter if { path /metrics }
no log
</code>Tip: Restart the HAProxy service after making configuration changes.
Prometheus Collects HAProxy Metrics
Edit the Prometheus ConfigMap to add a job named
haproxywith the HAProxy instances as static targets.
<code>$ kubectl -n kube-system edit cm prometheus
- job_name: 'haproxy'
static_configs:
- targets:
- "172.139.20.3:8405"
- "172.139.20.92:8405"
</code>Verify that metrics are being collected with a curl query to the Prometheus API:
<code>$ curl -u admin -s $(kubectl -n kube-system get svc prometheus -ojsonpath='{.spec.clusterIP}:{.spec.ports[0].port}')/prometheus/api/v1/query --data-urlencode 'query=up{job=~"haproxy"}' | jq '.data.result[]'
</code>Add HAProxy Dashboard to Grafana
Import dashboard ID
12693in Grafana to visualize HAProxy metrics.
Conclusion
By building a comprehensive HAProxy monitoring system, you can detect and resolve potential issues early and obtain data to optimize performance. Monitoring is a continuous process that must be regularly refined to keep services stable and deliver the best user experience.
Linux Ops Smart Journey
The operations journey never stops—pursuing excellence endlessly.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.