Last active
March 3, 2022 21:59
-
-
Save haproxytechblog/1eca89c80614e2cdb31e0cee2b233264 to your computer and use it in GitHub Desktop.
HAProxy Now Exposes a Prometheus Metrics Endpoint
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| sudo systemctl stop haproxy | |
| sudo cp /usr/local/sbin/haproxy /usr/sbin/haproxy | |
| sudo systemctl start haproxy |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| haproxy -vv | |
| Built with the Prometheus exporter as a service |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| - job_name: 'haproxy' | |
| static_configs: | |
| - targets: ['localhost:8404'] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| haproxy_frontend_http_requests_rate_current |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| sum(haproxy_frontend_http_requests_rate_current{proxy="fe_main",job="haproxy"}) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| rule_files: | |
| - 'alerts.yml' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| alerting: | |
| alertmanagers: | |
| - static_configs: | |
| - targets: | |
| - localhost:9093 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| - 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