mirror of
https://github.com/outbackdingo/patroni.git
synced 2026-09-01 00:59:24 +00:00
Created tatuspage, a health check for a PostgreSQL cluster served using http.
The StatusPage uses a BaseHTTPServer to server 3 simple http endpoints: - pg_master, returns 200 if PostgreSQL is running as master - pg_slave, returns 200 if PostgreSQL is running as slave - pg_status, returns some information about the cluster It does this by relying on the PostgreSQL connection of the Governor.
This commit is contained in:
+1
-1
@@ -11,7 +11,7 @@ RUN apt-get update -y
|
||||
RUN apt-get upgrade -y
|
||||
|
||||
ENV PGVERSION 9.4
|
||||
RUN apt-get install curl python python-pip python-psycopg2 python-yaml python-cherrypy postgresql-${PGVERSION} -y
|
||||
RUN apt-get install curl python python-pip python-psycopg2 python-yaml postgresql-${PGVERSION} -y
|
||||
|
||||
RUN ln -s /usr/lib/postgresql/* /usr/lib/postgresql/current
|
||||
ENV PATH /usr/lib/postgresql/current/bin:$PATH
|
||||
|
||||
@@ -0,0 +1,56 @@
|
||||
#!/usr/bin/env python
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
from BaseHTTPServer import BaseHTTPRequestHandler
|
||||
|
||||
|
||||
class StatusPage(BaseHTTPRequestHandler):
|
||||
|
||||
def do_GET(self):
|
||||
try:
|
||||
if self.path == '/pg_master':
|
||||
response = (200 if postgresql.is_leader else 503)
|
||||
self.send_response(response)
|
||||
elif self.path == '/pg_slave':
|
||||
response = (503 if postgresql.is_leader else 200)
|
||||
self.send_response(response)
|
||||
elif self.path == '/pg_status':
|
||||
self.send_response(200)
|
||||
self.end_headers()
|
||||
self.wfile.write(postgresql.status())
|
||||
else:
|
||||
self.send_response(404)
|
||||
except:
|
||||
self.send_response(500)
|
||||
|
||||
|
||||
def getHTTPServer(postgresql, http_port=8081, listen_address='0.0.0.0'):
|
||||
server = HTTPServer((listen_address, http_port), StatusPage)
|
||||
server.postgresql = postgresql
|
||||
|
||||
return server
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
import sys
|
||||
import logging
|
||||
from BaseHTTPServer import HTTPServer
|
||||
|
||||
logging.basicConfig(format='%(levelname)-6s %(asctime)s - %(message)s', level=logging.DEBUG)
|
||||
logging.debug('Starting as a standalone application')
|
||||
|
||||
# # Create a dummy configuration to be able to use the Postgresql class
|
||||
from postgresql import Postgresql
|
||||
postgres_config = {
|
||||
'name': 'dummy',
|
||||
'listen': 'localhost:5432',
|
||||
'data_dir': None,
|
||||
'replication': {'username': None, 'password': None},
|
||||
}
|
||||
aws_host_address = None
|
||||
if len(sys.argv) > 1:
|
||||
postgres_config['listen'] = sys.argv[1]
|
||||
postgresql = Postgresql(postgres_config, aws_host_address)
|
||||
|
||||
getHTTPServer(postgresql, 8081, '0.0.0.0').serve_forever()
|
||||
logging.debug('Abc')
|
||||
@@ -0,0 +1,2 @@
|
||||
PyYAML
|
||||
psycopg2
|
||||
Reference in New Issue
Block a user