Skip to content

Instantly share code, notes, and snippets.

@haproxytechblog
Created February 8, 2021 19:20
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/303b10b129cd21e115d66bdd98d7c7d1 to your computer and use it in GitHub Desktop.
Save haproxytechblog/303b10b129cd21e115d66bdd98d7c7d1 to your computer and use it in GitHub Desktop.
Using HAProxy as an API Gateway, Part 4 Metrics
frontend stats
bind :8404
stats enable
stats uri /
stats refresh 10s
global
stats socket /var/run/haproxy.sock user haproxy group haproxy mode 660 level admin
global
stats socket ipv4@127.0.0.1:9999 user haproxy group haproxy mode 660 level admin
$ echo "show stat json" | socat tcp-connect:127.0.0.1:9999 - | python3 -m json.tool
$ watch 'echo "show stat" | socat tcp-connect:127.0.0.1:9999 - | cut -d "," -f 1-2,16,18,43,44,47,61 | column -s, -t'
# pxname svname wretr status hrsp_4xx hrsp_5xx req_rate rtime
fe_api FRONTEND OPEN 0 0 10
be_api s1 0 UP 0 0 4
be_api s2 0 UP 0 0 4
be_api s3 0 UP 0 0 5
be_api s4 0 UP 0 0 5
be_api s5 0 UP 0 0 5
be_api BACKEND 0 UP 0 0 4
$ haproxy -vv | grep "Prometheus exporter"
Built with the Prometheus exporter as a service
frontend stats
bind :8404
stats enable
stats uri /
stats refresh 5s
http-request use-service prometheus-exporter if { path /metrics }
global:
scrape_interval: 5s
evaluation_interval: 5s
scrape_configs:
- job_name: 'haproxy'
static_configs:
- targets: ['172.25.0.11:8404']
global
stats socket ipv4@*:9999 user haproxy group haproxy mode 660 level admin
$ metricbeat modules enable haproxy
output.elasticsearch:
hosts: ["172.25.0.19:9200"]
- module: haproxy
metricsets: ["info", "stat"]
period: 10s
hosts: ["tcp://172.25.0.11:9999"]
enabled: true
$ sudo service metricbeat start
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment