Difference between revisions of "Haproxy"
Jump to navigation
Jump to search
| Line 19: | Line 19: | ||
``` | ``` | ||
#!/usr/bin/env python3 | #!/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 | + | # 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 | import json | ||
| Line 41: | Line 43: | ||
return json_data | return json_data | ||
| − | + | if __name__ == "__main__": | |
app.run(host='0.0.0.0', port=3333) | app.run(host='0.0.0.0', port=3333) | ||
``` | ``` | ||
Revision as of 00:42, 23 March 2020
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__)
def fstart():
json = haproxy.to_json()
return json
from flask import Flask
app = Flask(__name__)
@app.route("/")
def start():
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)
#!/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()