HAProxy integration for Grafana Cloud
HAProxy is a free, very fast and reliable solution offering high availability, load balancing, and proxying for TCP and HTTP-based applications. It is particularly suited for very high traffic web sites and powers quite a number of the world’s most visited ones. Over the years it has become the de-facto standard opensource load balancer, is now shipped with most mainstream Linux distributions, and is often deployed by default in cloud platforms. This integration allows you to collect metrics from the HAProxy instance and visualize them through pre-built dashboard in Grafana cloud.
This integration includes 3 useful alerts and 4 pre-built dashboards to help monitor and visualize HAProxy metrics.
Before you begin
This integration monitors an HAProxy Server app that exposes metrics through the built-in HAProxy Prometheus Exporter which can be built into the version 2.x+ binary.
A frontend configuration which is compatible with your existing HAProxy configuration is required. This configuration can be used as an example.
frontend stats
bind *:8404
option http-use-htx
http-request use-service prometheus-exporter if { path /metrics }
stats enable
stats uri /stats
stats refresh 10s
Install HAProxy integration for Grafana Cloud
- In your Grafana Cloud stack, click Connections in the left-hand menu.
- Find HAProxy and click its tile to open the integration.
- Review the prerequisites in the Configuration Details tab and set up Grafana Agent to send HAProxy metrics to your Grafana Cloud instance.
- Click Install to add this integration’s pre-built dashboards and alerts to your Grafana Cloud instance, and you can start monitoring your HAProxy setup.
Configuration snippets for Grafana Alloy
Simple mode
These snippets are configured to scrape a single HAProxy instance running locally with default ports.
First, manually copy and append the following snippets into your alloy configuration file.
Metrics snippets
discovery.relabel "metrics_integrations_integrations_haproxy" {
targets = [{
__address__ = "localhost:8404",
}]
rule {
target_label = "instance"
replacement = constants.hostname
}
}
prometheus.scrape "metrics_integrations_integrations_haproxy" {
targets = discovery.relabel.metrics_integrations_integrations_haproxy.output
forward_to = [prometheus.remote_write.metrics_service.receiver]
job_name = "integrations/haproxy"
}
Advanced mode
The following snippets provide examples to guide you through the configuration process.
To instruct Grafana Alloy to scrape your HAProxy instances, manually copy and append the snippets to your alloy configuration file, then follow subsequent instructions.
Advanced metrics snippets
discovery.relabel "metrics_integrations_integrations_haproxy" {
targets = [{
__address__ = "localhost:8404",
}]
rule {
target_label = "instance"
replacement = constants.hostname
}
}
prometheus.scrape "metrics_integrations_integrations_haproxy" {
targets = discovery.relabel.metrics_integrations_integrations_haproxy.output
forward_to = [prometheus.remote_write.metrics_service.receiver]
job_name = "integrations/haproxy"
}
To monitor your HAProxy instance, you must use a discovery.relabel component to discover your HAProxy Prometheus endpoint and apply appropriate labels, followed by a prometheus.scrape component to scrape it.
Configure the following properties within each discovery.relabel
component:
__address__
: The address to your HAProxy Prometheus metrics endpoint.instance
label:constants.hostname
sets theinstance
label to your Grafana Alloy server hostname. If that is not suitable, change it to a value uniquely identifies this HAProxy instance.
If you have multiple HAProxy servers to scrape, configure one discovery.relabel
for each and scrape them by including each under targets
within the prometheus.scrape
component.
Grafana Agent static configuration (deprecated)
The following section shows configuration for running Grafana Agent in static mode which is deprecated. You should use Grafana Alloy for all new deployments.
Before you begin
This integration monitors an HAProxy Server app that exposes metrics through the built-in HAProxy Prometheus Exporter which can be built into the version 2.x+ binary.
A frontend configuration which is compatible with your existing HAProxy configuration is required. This configuration can be used as an example.
frontend stats
bind *:8404
option http-use-htx
http-request use-service prometheus-exporter if { path /metrics }
stats enable
stats uri /stats
stats refresh 10s
Install HAProxy integration for Grafana Cloud
- In your Grafana Cloud stack, click Connections in the left-hand menu.
- Find HAProxy and click its tile to open the integration.
- Review the prerequisites in the Configuration Details tab and set up Grafana Agent to send HAProxy metrics to your Grafana Cloud instance.
- Click Install to add this integration’s pre-built dashboards and alerts to your Grafana Cloud instance, and you can start monitoring your HAProxy setup.
Post-install configuration for the HAProxy integration
After enabling the metrics generation, instruct Grafana Agent to scrape your HAProxy nodes.
HAProxy exposes a /metrics
endpoint. To scrape it, add the provided snippet to your agent configuration file.
Make sure to change targets
in the snippet according to your environment.
Configuration snippets for Grafana Agent
Below metrics.configs.scrape_configs
, insert the following lines and change the URLs according to your environment:
- job_name: integrations/haproxy
static_configs:
- targets: ['localhost:8404']
relabel_configs:
- action: replace
replacement: '<your-instance-name>'
target_label: instance
Full example configuration for Grafana Agent
Refer to the following Grafana Agent configuration for a complete example that contains all the snippets used for the HAProxy integration. This example also includes metrics that are sent to monitor your Grafana Agent instance.
integrations:
prometheus_remote_write:
- basic_auth:
password: <your_prom_pass>
username: <your_prom_user>
url: <your_prom_url>
agent:
enabled: true
relabel_configs:
- action: replace
source_labels:
- agent_hostname
target_label: instance
- action: replace
target_label: job
replacement: "integrations/agent-check"
metric_relabel_configs:
- action: keep
regex: (prometheus_target_sync_length_seconds_sum|prometheus_target_scrapes_.*|prometheus_target_interval.*|prometheus_sd_discovered_targets|agent_build.*|agent_wal_samples_appended_total|process_start_time_seconds)
source_labels:
- __name__
# Add here any snippet that belongs to the `integrations` section.
# For a correct indentation, paste snippets copied from Grafana Cloud at the beginning of the line.
logs:
configs:
- clients:
- basic_auth:
password: <your_loki_pass>
username: <your_loki_user>
url: <your_loki_url>
name: integrations
positions:
filename: /tmp/positions.yaml
scrape_configs:
# Add here any snippet that belongs to the `logs.configs.scrape_configs` section.
# For a correct indentation, paste snippets copied from Grafana Cloud at the beginning of the line.
metrics:
configs:
- name: integrations
remote_write:
- basic_auth:
password: <your_prom_pass>
username: <your_prom_user>
url: <your_prom_url>
scrape_configs:
# Add here any snippet that belongs to the `metrics.configs.scrape_configs` section.
# For a correct indentation, paste snippets copied from Grafana Cloud at the beginning of the line.
- job_name: integrations/haproxy
static_configs:
- targets: ['localhost:8404']
relabel_configs:
- action: replace
replacement: '<your-instance-name>'
target_label: instance
global:
scrape_interval: 60s
wal_directory: /tmp/grafana-agent-wal
Dashboards
The HAProxy integration installs the following dashboards in your Grafana Cloud instance to help monitor your system.
- HAProxy / Backend
- HAProxy / Frontend
- HAProxy / Overview
- HAProxy / Server
Alerts
The HAProxy integration includes the following useful alerts:
Metrics
The most important metrics provided by the HAProxy integration, which are used on the pre-built dashboards and Prometheus alerts, are as follows:
- haproxy_backend_bytes_in_total
- haproxy_backend_bytes_out_total
- haproxy_backend_check_up_down_total
- haproxy_backend_connect_time_average_seconds
- haproxy_backend_connection_attempts_total
- haproxy_backend_connection_errors_total
- haproxy_backend_http_requests_total
- haproxy_backend_internal_errors_total
- haproxy_backend_max_connect_time_seconds
- haproxy_backend_max_queue_time_seconds
- haproxy_backend_max_response_time_seconds
- haproxy_backend_max_total_time_seconds
- haproxy_backend_queue_time_average_seconds
- haproxy_backend_response_errors_total
- haproxy_backend_response_time_average_seconds
- haproxy_backend_status
- haproxy_backend_total_time_average_seconds
- haproxy_frontend_bytes_in_total
- haproxy_frontend_bytes_out_total
- haproxy_frontend_connections_total
- haproxy_frontend_http_requests_total
- haproxy_frontend_internal_errors_total
- haproxy_frontend_request_errors_total
- haproxy_frontend_status
- haproxy_process_current_connections
- haproxy_process_dropped_logs_total
- haproxy_process_limit_connection_rate
- haproxy_process_limit_session_rate
- haproxy_process_limit_ssl_rate
- haproxy_process_max_connections
- haproxy_process_max_fds
- haproxy_process_max_memory_bytes
- haproxy_process_max_pipes
- haproxy_process_max_sockets
- haproxy_process_nbproc
- haproxy_process_nbthread
- haproxy_process_pool_allocated_bytes
- haproxy_process_pool_used_bytes
- haproxy_process_start_time_seconds
- haproxy_server_bytes_in_total
- haproxy_server_bytes_out_total
- haproxy_server_check_up_down_total
- haproxy_server_connect_time_average_seconds
- haproxy_server_connection_attempts_total
- haproxy_server_connection_errors_total
- haproxy_server_http_responses_total
- haproxy_server_internal_errors_total
- haproxy_server_max_connect_time_seconds
- haproxy_server_max_queue_time_seconds
- haproxy_server_max_response_time_seconds
- haproxy_server_max_total_time_seconds
- haproxy_server_queue_time_average_seconds
- haproxy_server_response_errors_total
- haproxy_server_response_time_average_seconds
- haproxy_server_status
- haproxy_server_total_time_average_seconds
- up
Changelog
Cost
By connecting your HAProxy instance to Grafana Cloud, you might incur charges. To view information on the number of active series that your Grafana Cloud account uses for metrics included in each Cloud tier, see Active series and dpm usage and Cloud tier pricing.