Giter Site home page Giter Site logo

thumbtack / pgdoctor Goto Github PK

View Code? Open in Web Editor NEW
68.0 194.0 7.0 87 KB

Simple, lightweight web service to perform health checks on PostgreSQL instances

License: Apache License 2.0

Makefile 3.30% C 96.70%
postgresql postgresql-monitoring health-check c database postgres loadbalancing

pgdoctor's Introduction

pgDoctor

Simple, lightweight, web service used to define and run custom health checks on PostgreSQL instances.

Dependencies

  • Header files for libpq5 (PostgreSQL library)
  • GNU libmicrohttpd
  • check, a unit test framework for C

On a Debian-based system, these can easily be installed by running

sudo apt-get install libpq-dev libmicrohttpd-dev check

Build and install

  • Running tests (optional):

    The default configuration parameters for running tests rely on a local PostgreSQL instance listening on port 5432. Connections will be established with the postgres user and no password.

    If this does not match the system you're using, simply edit the relevant pg_* parameters on tests/pgdoctor.cfg.

    To actually run the tests all we need to do is execute

    make check

    If the last line of the output shows something like 100%: Checks: X, Failures: 0, Errors: 0, where X is the number of checks performed, all is good.

  • Building:

    make

  • Installing

    sudo make install

Configuration

A default configuration file is created under /etc/pgdoctor.cfg. Each setting is preceded by a comment describing it briefly.

Runtime settings

Parameter Description Default
http_port Port to listen on 8071
syslog_facility Syslog facility (local) to messages log to local7

Target PostgreSQL instance

Parameter Description Default
pg_host Host name of the instance pgDoctor will connect to localhost
pg_port Port on which the target server is listening 5432
pg_user User to connect with postgres
pg_password Password to use with pg_user empty
pg_database Name of the database to connect to postgres

Health checks

Parameter Description Default
pg_connection_timeout Timeout (seconds) when connecting to PostgreSQL 3
pg_max_replication_lag Maximum acceptable delay (seconds) on streaming replication -1 (disabled)

Custom health checks

pgDoctor supports the definition of custom health checks in the form of arbitrary SQL queries — one check per line.

These may be defined in two forms:

  • a plain SQL query, and the health check is considered successful if and only if it is executed without any errors;
  • a SQL query (must return exactly one field) and a condition, in which case the health check is considered successful when the query is executed without and errors and the condition evaluates to true.

Conditional checks are of the form

"QUERY" comparion_operator "VALUE"

where comparison_operator is one of <, >, or =. QUERY is any valid SQL command (surrounded by double-quotes), and VALUE (also surrounded by double-quotes) is the expected result from QUERY.

When using =, a string comparison is performed. For both < and > floating point values are used.


Simple examples — each health check passes iff the query runs without any errors

  • "SELECT 1"
  • "SELECT NOW()"

Conditional example — successful iff on_rotation equals 1

  • "SELECT on_rotation FROM maintenance WHERE hostname = 'production-replica3'" = "1"

Contact

  • pgdoctor group — general discussion list.

pgdoctor's People

Contributors

marcoalmeida avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

pgdoctor's Issues

Possible wrong information about replication lag

As I found pgdoctor using next query to determine replication lag:
"SELECT extract('epoch' from " \ "(now()-pg_last_xact_replay_timestamp())) " \ "AS replication_lag;"
This query may return incorrect value in case when there are no updates for database for some period. So if last update (delete or insert) was, for example, a hour ago this query will return value of replication_lag eq to 1 hour but it is not true! There are just no new date, so actually no replication lag.

Interesting project

Marco,
This is an interesting project, that might be useful to many people.
A great improvement would be adding some documentation on hot to use pgDoctor.
Actual usage is not clear without extensive studying of source codes, which would be a brier for adoption.
Igor

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.