Operations 4 min read

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.

Linux Ops Smart Journey
Linux Ops Smart Journey
Linux Ops Smart Journey
How to Efficiently Monitor HAProxy with Prometheus and Grafana

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 /metrics endpoint.

frontend prometheus
  bind *:8405
  mode http
  http-request use-service prometheus-exporter if { path /metrics }
  no log

Tip: Restart the HAProxy service after making configuration changes.

Prometheus Collects HAProxy Metrics

Edit the Prometheus ConfigMap to add a job named haproxy with the HAProxy instances as static targets.

$ kubectl -n kube-system edit cm prometheus
- job_name: 'haproxy'
  static_configs:
  - targets:
    - "172.139.20.3:8405"
    - "172.139.20.92:8405"

Verify that metrics are being collected with a curl query to the Prometheus API:

$ 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[]'

Add HAProxy Dashboard to Grafana

Import dashboard ID 12693 in 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.

Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

monitoringOperationsKubernetesPrometheusGrafanaHAProxy
Linux Ops Smart Journey
Written by

Linux Ops Smart Journey

The operations journey never stops—pursuing excellence endlessly.

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.