All Projects → Runscope → Healthcheck

Runscope / Healthcheck

Licence: mit
Write simple healthcheck functions for your Flask apps.

Programming Languages

python
139335 projects - #7 most used programming language

Projects that are alternatives of or similar to Healthcheck

py-healthcheck
Write simple healthcheck functions for your Flask or Tornado apps.
Stars: ✭ 92 (-63.78%)
Mutual labels:  health-check
pingbot
A website monitoring/health-checking tool based on serverless architecture.
Stars: ✭ 132 (-48.03%)
Mutual labels:  health-check
polaris-go
Lightweight Go SDK as Data Plane of Proxyless Service Governance Solution
Stars: ✭ 35 (-86.22%)
Mutual labels:  health-check
heartcheck
A simple way to check if everything is good in your app
Stars: ✭ 22 (-91.34%)
Mutual labels:  health-check
netapp-cdot-nagios
Nagios-Checks for monitoring NetApp cDOT-Systems via NetApp Perl API
Stars: ✭ 40 (-84.25%)
Mutual labels:  health-check
ngx stream upstream check module
nginx health checker (tcp/udp/http) for stream upstream servers.
Stars: ✭ 18 (-92.91%)
Mutual labels:  health-check
node-healthchecks-api
The Node.js implementation of the Health Checks API by Hootsuite
Stars: ✭ 25 (-90.16%)
Mutual labels:  health-check
pgdoctor
Simple, lightweight web service to perform health checks on PostgreSQL instances
Stars: ✭ 64 (-74.8%)
Mutual labels:  health-check
dbaTDPMon
dbaTDPMon - Troubleshoot Database Performance and Monitoring
Stars: ✭ 20 (-92.13%)
Mutual labels:  health-check
aarogya seva
A beautiful 😍 covid-19 app with self - assessment and more.
Stars: ✭ 118 (-53.54%)
Mutual labels:  health-check
golang-health-checker
A simple package to allow you to track your application healthy
Stars: ✭ 12 (-95.28%)
Mutual labels:  health-check
nodejs-health-checker
This is a Node package that allows you to track the health of your application providing readiness and liveness functionalities.
Stars: ✭ 34 (-86.61%)
Mutual labels:  health-check
health
A simple and flexible health check library for Go.
Stars: ✭ 494 (+94.49%)
Mutual labels:  health-check
polaris-java
Lightweight Java SDK used as Proxyless Service Governance Solution
Stars: ✭ 84 (-66.93%)
Mutual labels:  health-check
k8s-healthcheck
A simple app that returns the health statuses of the Kubernetes control-plane components, cluster nodes and deployments
Stars: ✭ 23 (-90.94%)
Mutual labels:  health-check
redis-healthy
It retrieves metrics, periodically, from Redis (or sentinel) and send them to Logstash
Stars: ✭ 62 (-75.59%)
Mutual labels:  health-check
polaris-cpp
Lightweight C/C++ SDK used as Proxyless Service Governance Solution
Stars: ✭ 14 (-94.49%)
Mutual labels:  health-check
News Search Engine
新闻搜索引擎
Stars: ✭ 254 (+0%)
Mutual labels:  flask
KInspector
KInspector is an application for analyzing health, performance and security of your Kentico solution.
Stars: ✭ 54 (-78.74%)
Mutual labels:  health-check
polaris
Service Governance Center for Distributed and Microservice Architecture
Stars: ✭ 1,062 (+318.11%)
Mutual labels:  health-check

Healthcheck

Healthcheck wraps a Flask app object and adds a way to write simple healthcheck functions that can be used to monitor your application. It's useful for asserting that your dependencies are up and running and your application can respond to HTTP requests. The Healthcheck functions are exposed via a user defined flask route so you can use an external monitoring application (monit, nagios, Runscope, etc.) to check the status and uptime of your application.

New in version 1.1: Healthcheck also gives you a simple Flask route to view information about your application's environment. By default, this includes data about the operating system, the Python environment, the current process, and the application config. You can customize which sections are included, or add your own sections to the output.

Installing

pip install healthcheck

Usage

Here's an example of basic usage:

from flask import Flask
from healthcheck import HealthCheck, EnvironmentDump

app = Flask(__name__)

# wrap the flask app and give a heathcheck url
health = HealthCheck(app, "/healthcheck")
envdump = EnvironmentDump(app, "/environment")

# add your own check function to the healthcheck
def redis_available():
    client = _redis_client()
    info = client.info()
    return True, "redis ok"

health.add_check(redis_available)

# add your own data to the environment dump
def application_data():
	return {"maintainer": "Frank Stratton",
	        "git_repo": "https://github.com/Runscope/healthcheck"}

envdump.add_section("application", application_data)

To run all of your check functions, make a request to the healthcheck URL you specified, like this:

curl "http://localhost:5000/healthcheck"

And to view the environment data, make a check to the URL you specified for EnvironmentDump:

curl "http://localhost:5000/environment"

The HealthCheck class

Check Functions

Check functions take no arguments and should return a tuple of (bool, str). The boolean is whether or not the check passed. The message is any string or output that should be rendered for this check. Useful for error messages/debugging.

# add check functions
def addition_works():

	if 1 + 1 == 2:
		return True, "addition works"
	else:
		return False, "the universe is broken"

Any exceptions that get thrown by your code will be caught and handled as errors in the healthcheck:

# add check functions
def throws_exception():
	bad_var = None
	bad_var['explode']

Will output:

{
	"status": "failure",
		"results": [
		{
			"output": "'NoneType' object has no attribute '__getitem__'",
			"checker": "throws_exception",
			"passed": false
		}
	]
}

Note, all checkers will get run and all failures will be reported. It's intended that they are all separate checks and if any one fails the healthcheck overall is failed.

Caching

In Runscope's infrastructure, the /healthcheck endpoint is hit surprisingly often. haproxy runs on every server, and each haproxy hits every healthcheck twice a minute. (So if we have 30 servers in our infrastructure, that's 60 healthchecks per minute to every Flask service.) Plus, monit hits every healthcheck 6 times a minute.

To avoid putting too much strain on backend services, health check results can be cached in process memory. By default, health checks that succeed are cached for 27 seconds, and failures are cached for 9 seconds. These can be overridden with the success_ttl and failed_ttl parameters. If you don't want to use the cache at all, initialize the Healthcheck object with success_ttl=None, failed_ttl=None.

Customizing

You can customize the status codes, headers, and output format for success and failure responses.

The EnvironmentDump class

Built-in data sections

By default, EnvironmentDump data includes these 4 sections:

  • os: information about your operating system.
  • python: information about your Python executable, Python path, and installed packages.
  • process: information about the currently running Python process, including the PID, command line arguments, and all environment variables.
  • config: information about your Flask app's configuration, pulled from app.config.

Some of the data is scrubbed to avoid accidentally exposing passwords or access keys/tokens. Config keys and environment variable names are scanned for key, token, or pass. If those strings are present in the name of the variable, the value is not included.

Disabling built-in data sections

For security reasons, you may want to disable an entire section. You can disable sections when you instantiate the EnvironmentDump object, like this:

envdump = EnvironmentDump(app, "/environment",
                          include_python=False, include_os=False,
                          include_process=False, include_config=False)

Adding custom data sections

You can add a new section to the output by registering a function of your own. Here's an example of how this would be used:

def application_data():
	return {"maintainer": "Frank Stratton",
	        "git_repo": "https://github.com/Runscope/healthcheck"}

envdump = EnvironmentDump(app, "/environment")
envdump.add_section("application", application_data)
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].