Skip to content

Instantly share code, notes, and snippets.

@haproxytechblog
Last active March 3, 2022 21:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save haproxytechblog/1eca89c80614e2cdb31e0cee2b233264 to your computer and use it in GitHub Desktop.
Save haproxytechblog/1eca89c80614e2cdb31e0cee2b233264 to your computer and use it in GitHub Desktop.
HAProxy Now Exposes a Prometheus Metrics Endpoint
sudo apt update
sudo apt install -y git ca-certificates gcc libc6-dev liblua5.3-dev libpcre3-dev libssl-dev libsystemd-dev make wget zlib1g-dev
git clone https://github.com/haproxy/haproxy.git
cd haproxy
make TARGET=linux-glibc USE_LUA=1 USE_OPENSSL=1 USE_PCRE=1 USE_ZLIB=1 USE_SYSTEMD=1 USE_PROMEX=1
sudo make install-bin
sudo systemctl stop haproxy
sudo cp /usr/local/sbin/haproxy /usr/sbin/haproxy
sudo systemctl start haproxy
haproxy -vv
Built with the Prometheus exporter as a service
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
- job_name: 'haproxy'
static_configs:
- targets: ['localhost:8404']
haproxy_frontend_http_requests_rate_current
sum(haproxy_frontend_http_requests_rate_current{proxy="fe_main",job="haproxy"})
rule_files:
- 'alerts.yml'
alerting:
alertmanagers:
- static_configs:
- targets:
- localhost:9093
groups:
- name: be_servers_alert
rules:
- alert: be_servers_no_backends
expr: haproxy_backend_active_servers{proxy="be_servers"} < 1
for: 15s
labels:
severity: page
annotations:
summary: HAProxy reports all servers are unhealthy for be_app.
global:
resolve_timeout: 5m
smtp_from: 'alertmanager@example.com'
smtp_smarthost: example.com:587
smtp_auth_username: 'username'
smtp_auth_password: 'password'
route:
group_by: ['alertname']
group_wait: 10s
group_interval: 10s
repeat_interval: 1h
receiver: 'email'
- alert: fe_main_rate_double
expr: haproxy_frontend_http_requests_rate_current{proxy="fe_main"} > avg_over_time(haproxy_frontend_http_requests_rate_current{proxy="fe_main"}[24h])*2
for: 15s
labels:
severity: page
annotations:
summary: HAProxy frontend request rate doubled for fe_main
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment