Haproxy
Jump to navigation
Jump to search
frontend stats
bind *:8404
stats enable
stats uri /stats
stats refresh 10s
stats admin if LOCALHOST
mode http
# stats auth admin:admin
# acl network_allowed src 10.x.x.x 1.1.1.1 2.2.2.2 10.0.0.0/8
# stats admin if network_allowed
- http://10.x.x.x:8404/stats
- http://10.x.x.x:8404/stats?stats;csv;norefresh
- https://github.com/bcicen/haproxy-stats
#!/usr/bin/env python3
# This creates a http server for getting stats.
# You could easily write a simple loop to pump telemetry data somewhere via http post
# You could setup cache to limit queries to proxy data.
import json
from flask import Flask
from haproxystats import HAProxyServer
haproxy = HAProxyServer('127.0.0.1:8404/stats') app = Flask(__name__)
from flask import Flask
app = Flask(__name__)
@app.route("/") @app.route("/")
def stats():
json_data = haproxy.to_json()
json_data = json.loads(json_data)
json_data = json.dumps(json_data, indent=4, sort_keys=True)
return json_data
if __name__ == "__main__":
app.run(host='0.0.0.0', port=3333)
Let's look at some data from the above
import requests
r = requests.get("http://127.0.0.1:3333")
data = r.json()
data['10.x.x.x']['backends'][2]['listeners'][1]['name'] # o: haptest2
data['10.x.x.x']['backends'][2]['listeners'][1]['status'] # o: UP
#!/usr/bin/env python3
import time
from haproxystats import HAProxyServer
haproxy = HAProxyServer('10.64.4.51:8404/stats')
while True:
json = haproxy.to_json()
time.sleep(5)
print(json)
from haproxystats import HAProxyServer
haproxy = HAProxyServer('10.64.4.51:8404/stats')
for b in haproxy.backends:
print('%s: %s' % (b.name, b.status))
haproxy.to_json()