sanic-healthcheck¶
sanic-healthcheck
provides a simple way to add health checks and readiness checks to
your Sanic application. This makes it easier to
monitor your application and ensure it is running in a health state. Monitoring or management
tools can ping these endpoints to determine application uptime and status, as well as perform
application restart to ensure your application isn’t running in a degraded state.
sanic-healthcheck
was inspired by and borrows from Runscope/healthcheck.
Installing¶
pip install sanic-healthcheck
Use Cases¶
Docker Compose¶
Docker Compose allows you to specify health checks
in your compose file configuration. With a health check enabled in your application, you can configure
your Compose deployment to monitor the health of your application (running on port 3000
):
healthcheck:
test: ['CMD', 'curl', '-f', 'http://localhost:3000/health']
interval: 10s
timeout: 3s
retries: 2
start_period: 10s
Kubernetes¶
Kubernetes allows you to define liveness and readiness probes. A health check is effectively equivalent to a liveness check.
apiVersion: v1
kind: Pod
metadata:
labels:
app: my-application
name: my-application
spec:
containers:
- name: my-application
image: my/application:1.0
livenessProbe:
httpGet:
path: /health
port: 3000
initialDelaySeconds: 10s
periodSeconds: 10s
readinessProbe:
httpGet:
path: /ready
port: 3000