All Projects → LCOGT → django-vitals

LCOGT / django-vitals

Licence: other
A django app that provides health check endpoints for vital services.

Programming Languages

python
139335 projects - #7 most used programming language

Projects that are alternatives of or similar to django-vitals

cli
Railway CLI
Stars: ✭ 167 (+695.24%)
Mutual labels:  infrastructure
grucloud
Generate diagrams and code from cloud infrastructures: AWS, Azure,GCP, Kubernetes
Stars: ✭ 76 (+261.9%)
Mutual labels:  infrastructure
vpc-tutorials
Companion scripts to VPC tutorials
Stars: ✭ 14 (-33.33%)
Mutual labels:  infrastructure
casper
Yelp's internal caching proxy, powered by Nginx and OpenResty at its core
Stars: ✭ 81 (+285.71%)
Mutual labels:  infrastructure
infrabin
Like httpbin, but for infrastructure
Stars: ✭ 19 (-9.52%)
Mutual labels:  infrastructure
partinfra-terraform
Terraform configuration for Participation Infrastructure
Stars: ✭ 46 (+119.05%)
Mutual labels:  infrastructure
devopsish.com
DevOps, Cloud Native, Hybrid Cloud, Open Source, industry news, culture, and the ‘ish between.
Stars: ✭ 33 (+57.14%)
Mutual labels:  infrastructure
partyfactsdata
Party Facts data import
Stars: ✭ 31 (+47.62%)
Mutual labels:  infrastructure
netris-operator
The Kubernetes Operator for Netris
Stars: ✭ 28 (+33.33%)
Mutual labels:  infrastructure
argo
The administrative discovery interface for Stanford's Digital Object Registry
Stars: ✭ 19 (-9.52%)
Mutual labels:  infrastructure
common-osint-model
Converting data from services like Censys and Shodan to a common data model
Stars: ✭ 35 (+66.67%)
Mutual labels:  infrastructure
pocket-js
The Official Javascript Client of the Pocket Network
Stars: ✭ 26 (+23.81%)
Mutual labels:  infrastructure
terraform-templates
Terraform templates, examples, etc.
Stars: ✭ 16 (-23.81%)
Mutual labels:  infrastructure
terraform-provider-cisco-aci
Terraform provider for automating Cisco ACI enabled networks
Stars: ✭ 14 (-33.33%)
Mutual labels:  infrastructure
StackJanitor
StackJanitor is a serverless, event-driven stack cleanup tool.
Stars: ✭ 37 (+76.19%)
Mutual labels:  infrastructure
infrastructure
A repository containing scripts for managing infrastructure
Stars: ✭ 18 (-14.29%)
Mutual labels:  infrastructure
chef
Chef configuration management repo for configuring & maintaining the OpenStreetMap servers.
Stars: ✭ 94 (+347.62%)
Mutual labels:  infrastructure
testing.cloudposse.co
Example Terraform Reference Architecture that implements a Geodesic Module for an Automated Testing Organization in AWS
Stars: ✭ 22 (+4.76%)
Mutual labels:  infrastructure
terraform-aws-ecs-cluster
Terraform module for building an ECS cluster in AWS
Stars: ✭ 42 (+100%)
Mutual labels:  infrastructure
terraform-otc
Terraform integration modules for Open Telekom Cloud
Stars: ✭ 20 (-4.76%)
Mutual labels:  infrastructure

django-vitals

A django app that provides health check endpoints for vital services.

Build Status Coverage Status

It is often useful to get the status of services from the perspective of the application that needs them. django-vitals provides a simple mechanism for writing a running health checks. These checks can then be exposed via an endpoint:

{
    "ok": [
        "DatabaseCheck",
        "CacheCheck",
        "StorageCheck"
    ],
    "failed": {}
}

Which in the above case, would return a status code of 200

If something is down:

{
    "ok": [
        "DatabaseCheck",
        "CacheCheck",
        "StorageCheck"
    ],
    "failed": {
        "OtherMicroServiceEndpointCheck": [
            "Endpoint http://suchabadsite11112222.com unreachable: Failed to establish a new connection: [Errno -2] Name or service not known"
        ]
    }
}

a http code 500 is returned instead.

Subsets of checks can be run by passing the check parameter to the endpoint: ?checks=DatabaseCheck,CacheCheck

This can be particularity useful when used along with load balancers, container orchestration and other infrastructure tools that can take automatic actions when problems arise.

Requirements

Tested with all combinations of:

  • Python 3.4+
  • Django 1.8+

Python 2.7 probably works, but I have no interest in testing it. Support will be on a best effort basis.

Installation

Install the package from pypi:

pip install django-vitals

Add vitals to INSTALLED_APPS:

INSTALLED_APPS = (
    ...
    'vitals'
    ...
)

Add vitals.urls to your urlconf:

urlpatterns = [
    ...
    url(r'^healthz/', include('vitals.urls', namespace='vitals')),
    ...
]

Visit the url in your browser.

That's it if all you want is the default checks (DatabaseCheck, CacheCheck, StorageCheck) HTTPCheck is included but not enabled by default.

Configuration

By default 3 health checks are run: DatabaseCheck, CacheCheck and StorageCheck. Add VITALS_ENABLED_CHECKS to your settings.py to customize:

VITALS_ENABLED_CHECKS = [
    {
        'NAME': 'DatabaseCheck',
        'CLASS': 'vitals.checks.DatabaseCheck'
    },
    {
        'NAME': 'CacheCheck',
        'CLASS': 'vitals.checks.CacheCheck'
    },
    {
        'NAME': 'StorageCheck',
        'CLASS': 'vitals.checks.StorageCheck'
    },
    {
        'NAME': 'HTTPCheck',
        'CLASS': 'vitals.checks.HTTPCheck',
        'OPTIONS': {
            'url': 'https://google.com'
        }
    }
]

Included Checks

DatabaseCheck

Options: None

Iterates over every database in settings.DATABASES and attempts to access the list of tables for each.

CacheCheck

Options: None

Iterates over every cache in settings.CACHES and attempts to set a value, get it and remove it.

StorageCheck

Options: None

Using the default storage backend, attempts to write a small file and delete it.

HTTPCheck

Options: url

Attempts to GET the url provided by the url option. Will fail if the GET results in anything other than a 200 response code.

Writing Custom Checks

You are not limited to the included health checks. To write a custom check, simply subclass BaseHealthCheck and implement the check() method:

from vitals.checks import BaseHealthCheck

class MyHealthCheck(BaseHealthCheck):
    def check(self):
        assert 2 == 2

Any exceptions thrown by your check will be added as errors. You can also manually add errors using self.add_error(error):

from vitals.checks import BaseHealthCheck

class MyHealthCheck(BaseHealthCheck):
    def check(self):
        try:
            assert 1 == 2
        except AssertionError as exc:
            self.add_error('Strange error! {}'.format(exc))

Arguments can be passed to health checks by setting the OPTIONS key in settings:

VITALS_ENABLED_CHECKS = [
     {
        'NAME': 'MyFailingHealthCheck',
        'CLASS': 'foo.MyHealthCheck',
        'OPTIONS': {
            'number': 3
        }
    }
]

They will be passed a kwargs to your class constructor:

from vitals.checks import BaseHealthCheck

class MyHealthCheck(BaseHealthCheck):
    def __init__(self, *args, **kwargs):
        self.number = kwargs.pop('number')
        super(MyHealthCheck, self).__init__(*args, **kwargs)

    def check(self):
        assert self.number == 2

Add your custom checks to VITALS_ENABLED_CHECKS in settings.py providing the path to them in the CLASS key.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].