Difference between revisions of "Haproxy"

From UVOO Tech Wiki
Jump to navigation Jump to search
Line 3: Line 3:
 
     bind *:8404
 
     bind *:8404
 
     stats enable
 
     stats enable
    # stats uri /stats
 
 
     stats uri /stats
 
     stats uri /stats
 
     stats refresh 10s
 
     stats refresh 10s
 +
    stats admin if LOCALHOST
 
     mode http
 
     mode http
     stats auth admin:admin
+
     # stats auth admin:admin
    # stats admin if LOCALHOST
 
 
     # acl network_allowed src 10.x.x.x 1.1.1.1 2.2.2.2 10.0.0.0/8
 
     # 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
 
     # stats admin if network_allowed
Line 17: Line 16:
  
 
- https://github.com/bcicen/haproxy-stats
 
- 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                                                                                             
 +
 +
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)
 +
```
 +
  
 
```
 
```

Revision as of 00:39, 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
#!/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                                                                                              

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()