This document describes the HTTP health check endpoints exposed by the Python IMDB Bot for monitoring and load balancing purposes.
The bot runs a lightweight HTTP server on port 8080 that provides three health check endpoints:
/health- Basic health check/ready- Readiness check with database connectivity/metrics- Application metrics
Basic health check endpoint that verifies the bot is running.
Response (200 OK):
{
"status": "healthy",
"timestamp": "2025-01-12T08:00:00.123456",
"uptime_seconds": 3600.5
}Response Fields:
status(string): Always "healthy" if the endpoint respondstimestamp(string): ISO 8601 formatted timestampuptime_seconds(number): Seconds since the bot started
Readiness check that verifies both bot health and database connectivity.
Response (200 OK):
{
"status": "ready",
"database": "connected",
"timestamp": "2025-01-12T08:00:00.123456"
}Response (503 Service Unavailable):
{
"status": "not ready",
"database": "disconnected",
"error": "Connection timeout",
"timestamp": "2025-01-12T08:00:00.123456"
}Response Fields:
status(string): "ready" or "not ready"database(string): "connected" or "disconnected"timestamp(string): ISO 8601 formatted timestamperror(string): Error message if database connection fails (only in error responses)
Provides basic application metrics for monitoring.
Response (200 OK):
{
"guilds_configured": 5,
"movies_tracked": 120,
"ratings_total": 450,
"timestamp": "2025-01-12T08:00:00.123456"
}Response (500 Internal Server Error):
{
"error": "Failed to fetch metrics",
"details": "Database connection error"
}Response Fields:
guilds_configured(integer): Number of Discord guilds with configured channelsmovies_tracked(integer): Total number of movies stored in databaseratings_total(integer): Total number of ratings across all moviestimestamp(string): ISO 8601 formatted timestamp
# docker-compose.yml
services:
imdb-bot:
# ... other config
healthcheck:
test: ["CMD", "curl", "-f", "http://localhost:8080/health"]
interval: 30s
timeout: 10s
retries: 3
start_period: 60s# nginx.conf
upstream imdb_bot {
server bot1:8080;
server bot2:8080;
}
server {
listen 80;
location /health {
proxy_pass http://imdb_bot/health;
proxy_connect_timeout 5s;
proxy_send_timeout 5s;
proxy_read_timeout 5s;
}
}# Python monitoring script
import requests
import time
def check_health():
try:
response = requests.get("http://localhost:8080/health", timeout=5)
return response.status_code == 200
except:
return False
def get_metrics():
try:
response = requests.get("http://localhost:8080/metrics", timeout=5)
return response.json()
except:
return None200 OK: Endpoint is healthy and responding503 Service Unavailable: Readiness check failed (database issues)500 Internal Server Error: Metrics endpoint failed to fetch data
- Health endpoints are unauthenticated and should only be exposed internally
- Use firewall rules or reverse proxy to restrict access to monitoring systems
- Consider implementing API keys for production environments
- Health checks are lightweight and designed for frequent polling
- Database queries are optimized with
LIMIT 1to minimize load - Endpoints use connection pooling to avoid connection overhead
- Metrics endpoint may have slight performance impact on busy systems