Health Monitoring¶
Overview¶
The AI-Pi project implements comprehensive health monitoring across all services to ensure system reliability and quick issue detection.
Architecture¶
graph TD
A[Health Monitor] --> B[Client Health]
A --> C[Server Health]
A --> D[AI Health]
A --> E[MongoDB Health]
B --> F[WebSocket]
C --> F
D --> F
E --> F
F --> G[Health Dashboard]
Health Check Protocol¶
Each service implements a standardized health check endpoint that returns:
{
"status": "string", // "healthy" or "unhealthy"
"timestamp": "number", // Unix timestamp in milliseconds
"version": "string", // Service version
"service": "string", // Service name
"dependencies": { // Status of dependent services
"service1": "string", // "connected" or "disconnected"
"service2": "string"
}
}
Service Health Endpoints¶
Service | Endpoint | Port |
---|---|---|
Client | /health | 3000 |
Server | /health | 8080 |
AI | /health | 5000 |
MongoDB | (Internal) | 27017 |
Docker Integration¶
Docker Compose configures health checks for each service:
healthcheck:
test: ["CMD", "curl", "-f", "http://localhost:<port>/health"]
interval: 30s
timeout: 10s
retries: 3
Monitoring Tools¶
-
Docker Health
-
Health Check Script
-
Logging
Error Handling¶
- Automatic Recovery
- Services attempt to reconnect to dependencies
-
Docker restarts unhealthy containers
-
Notifications
- Log critical health issues
- Alert on repeated failures
Best Practices¶
- Implementation
- Keep health checks lightweight
- Include relevant metrics
-
Handle timeouts gracefully
-
Monitoring
- Check health regularly
- Log health status changes
-
Track dependency health
-
Maintenance
- Update health checks with new features
- Review health metrics regularly
- Test failure scenarios
Version History¶
- v1.0: Initial health monitoring
- v1.1: Added dependency checks
- v1.2: Enhanced Docker integration
- v2.0: Updated for simplified battle mechanics