Healthcheck extension for Pyramid
Project description
Simple healthcheck endpoint for Pyramid, with maintenance mode and application checks.
Bitbucket: https://bitbucket.org/Ludia/pyramid_health
Installation
Install using setuptools, e.g. (within a virtualenv):
$ pip install pyramid_health
Setup
Once pyramid_health is installed, you must use the config.include mechanism to include it into your Pyramid project’s configuration. In your Pyramid project’s __init__.py:
config = Configurator(.....)
config.include('pyramid_health')
Alternately you can use the pyramid.includes configuration value in your .ini file:
[app:myapp]
pyramid.includes = pyramid_health
Usage
Pyramid_health configuration (values are defaults):
[app:myapp]
healthcheck.url = /health
healthcheck.disablefile = /tmp/maintenance # touch this file to activate
healthcheck.maintenance_code = 503 # Code to return in maintenance mode
healthcheck.failure_code = 503 # Code to return when one or more checks fail
Operation
When your application is healthy, pyramid_health endpoint returns 200 OK. When you enable the maintenance mode, the endpoint returns 503 MAINTENANCE and logs Health response: MAINTENANCE. If at least one application check return an error, the endpoint returns 503 ERROR and logs Health response: ERROR (<all-check-results>).
Application checks
To add an application check:
from pyramid.events import subscriber
from pyramid_health import HealthCheckEvent
@subscriber(HealthCheckEvent)
def db_check(event):
try:
db.ping()
except:
event.report(name='db', status='NOK', message='ping failed')
else:
event.report(name='db', status='OK')
Notes:
You may or may not report succeeding checks
Maintenance mode
In maintenance mode, the healthcheck endpoint’s response is changed to inform the HTTP client that this backend is unavailable. Typically a loadbalancer polling the backends would stop sending traffic to a backend in maintenance mode.
The response status code is 503 MAINTENANCE by default. You can change it with healthcheck.maintenance_code.
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
File details
Details for the file pyramid_health-1.0.0.tar.gz
.
File metadata
- Download URL: pyramid_health-1.0.0.tar.gz
- Upload date:
- Size: 3.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 577d9a8290becabad4bda73bf25caaeccaadcfe8950a2fc0c6b89db07a9b5e9a |
|
MD5 | 45d04f6a807fa5f649bfa009d5935759 |
|
BLAKE2b-256 | d8309e9273a1a46c2c81d6ac55f084ac101595cc83819a10b812e26f0712b76e |