Skip to content
This repository has been archived by the owner on Nov 18, 2017. It is now read-only.

Commit

Permalink
add haproxy_status.py
Browse files Browse the repository at this point in the history
  • Loading branch information
Joshua Deare committed Sep 28, 2016
1 parent 982a5a2 commit 49ffc42
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 0 deletions.
40 changes: 40 additions & 0 deletions haproxy_status.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
#!/usr/bin/env python

from BaseHTTPServer import BaseHTTPRequestHandler
import sys, yaml, socket
import requests

f = open(sys.argv[1], "r")
config = yaml.load(f.read())
f.close()

class StatusHandler(BaseHTTPRequestHandler):
def do_GET(self):
return self.do_ANY()
def do_OPTIONS(self):
return self.do_ANY()
def do_ANY(self):
base_url = "http://localhost:" + str(config["api_port"])
is_leader_resp = requests.get(base_url + "/ha/is_leader")
running_as_leader_resp = requests.get(
base_url + "/service/running_as_leader")
is_healthy_resp = requests.get(base_url + "/service/is_healthy")
if is_healthy_resp.json()["data"]["is_healthy"] and \
is_leader_resp.json()["data"]["is_leader"] and \
running_as_leader_resp.json()["data"]["running_as_leader"]:
self.send_response(200)
else:
self.send_response(503)
self.end_headers()
self.wfile.write('\r\n')
return

try:
from BaseHTTPServer import HTTPServer
host, port = config["haproxy_status"]["listen"].split(":")
server = HTTPServer((host, int(port)), StatusHandler)
print 'listening on %s:%s' % (host, port)
server.serve_forever()
except KeyboardInterrupt:
print('^C received, shutting down server')
server.socket.close()
2 changes: 2 additions & 0 deletions postgres0.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
loop_wait: 1000 #milliseconds
data_dir: "data/postgres0" #canoe and pg data will go here
api_port: 5000
haproxy_status:
listen: 127.0.0.1:2345
fsm:
raft_port: 1234
cluster_config_port: 1244
Expand Down
2 changes: 2 additions & 0 deletions postgres1.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
loop_wait: 1000 #milliseconds
data_dir: "data/postgres1" #canoe and pg data will go here
api_port: 5001
haproxy_status:
listen: 127.0.0.1:2346
fsm:
raft_port: 1235
cluster_config_port: 1245
Expand Down
2 changes: 2 additions & 0 deletions postgres2.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
loop_wait: 1000 #milliseconds
data_dir: "data/postgres2" #canoe and pg data will go here
api_port: 5002
haproxy_status:
listen: 127.0.0.1:2347
fsm:
raft_port: 1236
cluster_config_port: 1246
Expand Down

0 comments on commit 49ffc42

Please sign in to comment.