How to Monitor Your Sanic Application with Vigilmon (Python)
Sanic is a Python web framework built for speed, using async/await syntax to handle thousands of concurrent requests. As a high-performance async framework, Sanic production deployments need robust external monitoring to catch outages before your users do.
This guide shows you how to set up monitoring for your Sanic application with Vigilmon.
Why Sanic Applications Need External Monitoring
Sanic's async model gives you great throughput, but it also means:
- A crashed worker process won't restart itself
- The event loop can block if a non-async call sneaks in
- SSL certificate expiry silently breaks HTTPS connections
- You need external eyes watching your uptime 24/7
Step 1: Add a Health Endpoint to Sanic
Create a simple health check route:
from sanic import Sanic
from sanic.response import json
app = Sanic('MyApp')
@app.get('/health')
async def health_check(request):
return json({'status': 'ok', 'service': 'sanic-app'})
if __name__ == '__main__':
app.run(host='0.0.0.0', port=8000, workers=4)
Step 2: Configure Vigilmon
- Sign up at vigilmon.online (free tier: 5 monitors)
- Click Add Monitor → HTTP/HTTPS
- Enter
https://yourapp.com/health - Set interval to 1 minute
- Set response time threshold to alert at > 2 seconds
Step 3: Monitor Sanic Workers
If you run multiple Sanic workers with workers=N, monitor each worker port individually to detect per-worker failures:
# Start workers on different ports for independent monitoring
# Worker 1: port 8001, Worker 2: port 8002, etc.
# Monitor load balancer + individual workers in Vigilmon
Step 4: SSL Certificate Monitoring
Vigilmon automatically tracks SSL expiry for HTTPS endpoints and alerts you 30 and 14 days before expiry.
For Sanic with TLS:
app.run(
host='0.0.0.0',
port=443,
ssl={'cert': '/path/to/cert.pem', 'key': '/path/to/key.pem'}
)
Point your Vigilmon monitor at https://yourapp.com/health to track both uptime and SSL health.
Step 5: Set Up Alerts
Vigilmon alert channels:
- Email — instant notification on downtime
- Slack — webhook to your ops channel
- PagerDuty — for on-call rotation
- Custom webhooks — trigger your own workflows
Monitoring Sanic Background Tasks
For Sanic apps that run background tasks, add a task health indicator:
from sanic import Sanic
from sanic.response import json
import asyncio
app = Sanic('MyApp')
app.ctx.background_healthy = True
@app.before_server_start
async def start_background(app, loop):
app.add_task(background_worker(app))
async def background_worker(app):
while True:
try:
# your background work
app.ctx.background_healthy = True
await asyncio.sleep(60)
except Exception:
app.ctx.background_healthy = False
@app.get('/health')
async def health(request):
if not request.app.ctx.background_healthy:
return json({'status': 'degraded'}, status=503)
return json({'status': 'ok'})
Vigilmon treats HTTP 5xx responses as downtime events.
Status Page for Your Users
Vigilmon generates a free hosted status page. Share https://status.vigilmon.online/your-slug with your users for transparent uptime communication.
Summary
In 5 minutes you get:
- Uptime checks every 60 seconds
- SSL certificate expiry alerts
- Response time monitoring
- Email/Slack alerts on downtime
- Free public status page
Top comments (0)