Giter Site home page Giter Site logo

perdy / health-check Goto Github PK

View Code? Open in Web Editor NEW
31.0 3.0 16.0 101 KB

Health Check is an application that provides an API to check the health health_check of some parts and some utilities like ping requests. This application can works as standalone or included in a Django project.

License: Other

JavaScript 40.39% Python 51.71% HTML 5.83% CSS 2.08%
python health checker resources django status

health-check's Introduction

Health Check

Version: 3.4.1
Status: Production/Stable
Author: José Antonio Perdiguero López

Health Check is an application that provides an API to check the health status of some parts and some utilities like ping requests. This application can works as standalone or included in a Django project.

This application defines the following terms:

Provider
Function that does a quick check or stats gathering and returns a json serializable value, such as dict, list or simple types.
Resource
A service or functionality whose status needs to be known.

Said this, providers are grouped by resources. So you can use resource as a simple group, or as a component of your application. E.g: A resource that represents your database with some checks over it, such as simple ping, check if your application tables are created, if it contains data...

Quick start

  1. Install this package using pip:
pip install health-check
  1. (Django) Add PROJECT_PATH to your django settings module.
  2. (Django) Add health_check to your INSTALLED_APPS settings like this:
INSTALLED_APPS = (
    ...
    'health_check',
)
  1. (Django) Add Health Check urls to your project urls:
urlpatterns = [
    ...
    url(r'^health/', include('health_check.urls')),
]

Check Providers

Health Check provides a mechanism to add new custom check functions through check providers. Each check provider will generate a new API method with an URL that uses the name of the provider. These functions must accept *args and **kwargs and will return a JSON-serializable object through json.dumps() method, for example a ping function:

def ping(*args, **kwargs):
    return {'pong': True}

By default Health Check provides the follow checks:

Ping

A ping to application.

URL: /api/health/ping

Databases

Check if databases are running.

URL: /api/health/databases

Caches

Check if caches are running.

URL: /api/health/caches

Celery

Check if celery workers defined in settings are running.

URL: /api/health/celery

Databases stats

Show stats for all databases.

URL: /api/stats/databases

Celery stats

Show celery worker stats.

URL: /api/stats/celery

Code

Source code stats such as current active branch, last commit, if debug is active...

URL: /api/stats/code

Run providers

The main goal of this application is to provide an easy way to run checks over defined resources, so there are different ways to do it.

Command

Health Check provides a command to query current health of a resource. This command can be call as:

health_check {resource} [options]

Call a specific provider from a resource:

health_check {resource} {provider} [options]

To get current status of health checks, and exit with an error if some check is failing:

health_check health -e

Each resource has its own set of options that can be displayed through command help:

health_check -h

Code

To run all providers of a specific resource:

from health_check.providers import Resource

resource = Resource('resource_name')
providers_result = resource()

A single provider can be executed:

from health_check.providers import Provider

provider = Provider('path.to.provider_function')
provider_result = provider()

Django

Health check adds some useful behavior to your Django application.

Health Check website

A website that shows Health Check data is available in this application. It's possible access to follow URLs to get a detailed view of your system health status. Those three pages will show results of providers configured (as explained in settings section):

http://www.website.com/health/
http://www.website.com/health/health/
http://www.website.com/health/stats/

Health Check API

Health Check API can be used as a standalone application including only their urls:

urlpatterns = [
    ...
    url(r'^health/', include('health.api.urls')),
]

This API have a single url for each provider, that are grouped by resources. Each provider can be queried alone, returning his current health status:

http://your_domain/health/api/health/ping

Also there is a resource view that will return the health status of all providers:

http://your_domain/health/api/health

For last, there is a root view that will return the health status of all providers from all resources:

http://your_domain/health/api

Django management commands

Previous command can be used as Django management command:

python manage.py health_check {resource} {provider} [options]

Settings

Health check settings can be added directly to Django settings module or create an specific module for them. If a custom module (or class) is used, you must specify it through HEALTH_CHECK_SETTINGS environment variable.

To use a custom module for settings is necessary to specify the full path: project.package.settings. The same applies to objects: project.package.settings:SettingsObject.

health_check_providers

List of additional check providers. Each provider consists in a tuple of name, function complete path, args and kwargs.

Example:

HEALTH_CHECK_PROVIDERS = {
    'resource': (
        ('test', 'application.module.test_function', [1, 2], {'foo': 'bar'}),
    )
}

Default:

providers = getattr(settings, 'HEALTH_CHECK_PROVIDERS', {
    'health': (
        ('ping', 'health_check.providers.health.ping', None, None),
        ('databases', 'health_check.providers.django.health.databases', None, None),
        ('caches', 'health_check.providers.django.health.caches', None, None),
    ),
    'stats': (
        ('databases', 'health_check.providers.django.stats.databases', None, None),
        ('code', 'health_check.providers.stats.code', None, None),
    )
}

health_check_celery_workers

List of hostname from celery workers to be checked. If any worker is defined, two additional providers listed previously will be added to default set.

Default:

health_check_celery_workers = ()

health-check's People

Contributors

ezhvsalate avatar mbarrientos avatar perdy 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

Watchers

 avatar  avatar  avatar

health-check's Issues

migrate command is failing due to ugetext_lazy

Error trace

2023-04-03 13:31:26,552 P7288 [INFO] Command 01_migrate
2023-04-03 13:31:27,238 P7288 [INFO] -----------------------Command Output-----------------------
2023-04-03 13:31:27,239 P7288 [INFO] 	Traceback (most recent call last):
2023-04-03 13:31:27,239 P7288 [INFO] 	  File "manage.py", line 22, in <module>
2023-04-03 13:31:27,239 P7288 [INFO] 	    main()
2023-04-03 13:31:27,239 P7288 [INFO] 	  File "manage.py", line 18, in main
2023-04-03 13:31:27,239 P7288 [INFO] 	    execute_from_command_line(sys.argv)
2023-04-03 13:31:27,240 P7288 [INFO] 	  File "/var/app/venv/staging-LQM1lest/lib/python3.8/site-packages/django/core/management/__init__.py", line 446, in execute_from_command_line
2023-04-03 13:31:27,240 P7288 [INFO] 	    utility.execute()
2023-04-03 13:31:27,240 P7288 [INFO] 	  File "/var/app/venv/staging-LQM1lest/lib/python3.8/site-packages/django/core/management/__init__.py", line 420, in execute
2023-04-03 13:31:27,240 P7288 [INFO] 	    django.setup()
2023-04-03 13:31:27,240 P7288 [INFO] 	  File "/var/app/venv/staging-LQM1lest/lib/python3.8/site-packages/django/__init__.py", line 24, in setup
2023-04-03 13:31:27,240 P7288 [INFO] 	    apps.populate(settings.INSTALLED_APPS)
2023-04-03 13:31:27,240 P7288 [INFO] 	  File "/var/app/venv/staging-LQM1lest/lib/python3.8/site-packages/django/apps/registry.py", line 91, in populate
2023-04-03 13:31:27,241 P7288 [INFO] 	    app_config = AppConfig.create(entry)
2023-04-03 13:31:27,241 P7288 [INFO] 	  File "/var/app/venv/staging-LQM1lest/lib/python3.8/site-packages/django/apps/config.py", line 123, in create
2023-04-03 13:31:27,241 P7288 [INFO] 	    mod = import_module(mod_path)
2023-04-03 13:31:27,241 P7288 [INFO] 	  File "/usr/lib64/python3.8/importlib/__init__.py", line 127, in import_module
2023-04-03 13:31:27,241 P7288 [INFO] 	    return _bootstrap._gcd_import(name[level:], package, level)
2023-04-03 13:31:27,241 P7288 [INFO] 	  File "<frozen importlib._bootstrap>", line 1014, in _gcd_import
2023-04-03 13:31:27,241 P7288 [INFO] 	  File "<frozen importlib._bootstrap>", line 991, in _find_and_load
2023-04-03 13:31:27,241 P7288 [INFO] 	  File "<frozen importlib._bootstrap>", line 975, in _find_and_load_unlocked
2023-04-03 13:31:27,241 P7288 [INFO] 	  File "<frozen importlib._bootstrap>", line 671, in _load_unlocked
2023-04-03 13:31:27,242 P7288 [INFO] 	  File "<frozen importlib._bootstrap_external>", line 783, in exec_module
2023-04-03 13:31:27,242 P7288 [INFO] 	  File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
2023-04-03 13:31:27,242 P7288 [INFO] 	  File "/var/app/venv/staging-LQM1lest/lib/python3.8/site-packages/health_check/apps.py", line 5, in <module>
2023-04-03 13:31:27,242 P7288 [INFO] 	    from django.utils.translation import ugettext_lazy as _
2023-04-03 13:31:27,242 P7288 [INFO] 	ImportError: cannot import name 'ugettext_lazy' from 'django.utils.translation' (/var/app/venv/staging-LQM1lest/lib/python3.8/site-packages/django/utils/translation/__init__.py)

cause of the error

in -> health_check/apps.py you're importing ugettext_lazy which is deprecated start from Django==3.0 and removed at Django==4.0

references

ImportError: cannot import name 'ugettext_lazy' from 'django.utils.translation' (/var/app/venv/staging-LQM1lest/lib/python3.8/site-packages/django/utils/translation/__init__.py)

django.utils.translation.ugettext(), ugettext_lazy(), ugettext_noop(), ungettext(), and ungettext_lazy() are deprecated in favor of the functions that they’re aliases for: django.utils.translation.gettext(), gettext_lazy(), gettext_noop(), ngettext(), and ngettext_lazy().

https://docs.djangoproject.com/en/3.0/internals/deprecation/

https://docs.djangoproject.com/en/3.0/releases/3.0/#id3

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.