Nova Coder includes a comprehensive health monitoring system that provides real-time metrics for system health, resource usage, and service status. The health monitoring system is accessible via the REST API and displayed in the web dashboard.
Components
novacoder/api/routes_system.py, Health check endpoint with detailed metricsnovacoder/api/_html.py, Dashboard UI for health metrics displaypsutil, System metrics collection library
Health Endpoint
The /api/health endpoint provides comprehensive health information. It is intentionally public so load balancers, monitoring probes, and the web dashboard can check status without authentication.
Recent fixes
ServicesServicerecursion: The services monitoring service previously called its ownhealth()while listing other services, causing an exponential cascade of health checks. It now usessuper().health()when inspecting itself.AIService.health()thread safety: Async providerhealth_check()calls now run in a dedicated thread with their own event loop, preventingRuntimeWarning/RecursionErrorin synchronous health paths.Lifecycle.health()deduplication: Each service'shealth()is evaluated once per application health check, reducing redundant work such as repeated Ollama provider probes.
curl http://localhost:8000/api/health
Response Format
{
"status": "healthy",
"message": "All systems operational",
"services": {
"memory": {
"status": "running",
"healthy": true,
"message": "Memory service operational"
},
"ai": {
"status": "running",
"healthy": true,
"message": "AI provider available"
}
},
"metrics": {
"memory": {
"rss_mb": 125.5,
"vms_mb": 450.2,
"percent": 12.3
},
"database": {
"status": "connected"
},
"ai_provider": {
"available": true,
"provider_count": 1
},
"queue_depth": 0
}
}
Metrics
Memory Metrics
- RSS (Resident Set Size): Actual physical memory used by the process in MB
- VMS (Virtual Memory Size): Total virtual memory allocated in MB
- Memory Percentage: Percentage of total system memory used
import psutil
process = psutil.Process()
memory_info = process.memory_info()
memory_percent = process.memory_percent()
Database Metrics
- Connection Status: Whether the database connection is active
- Database Type: SQLite (with WAL mode enabled)
- Connection Health: Connection validation status
AI Provider Metrics
- Provider Availability: Whether AI providers are accessible
- Provider Count: Number of configured AI providers
- Provider Status: Individual provider health status
Queue Metrics
- Queue Depth: Number of pending requests in the processing queue
- Queue Status: Whether the queue is processing normally
- Backlog Warning: Alert if queue depth exceeds threshold
Dashboard Integration
The web dashboard displays health metrics in real-time:
Dashboard Cards
- Memory Usage: Shows memory percentage and RSS usage
- Database Status: Shows database connection status
- AI Provider Status: Shows provider availability
- Queue Depth: Shows pending request count
- Service Status: Overall system health indicator
Auto-Refresh
The dashboard automatically refreshes health metrics every 20 seconds to provide near real-time monitoring.
Health Status Levels
- healthy: All systems operational, no issues detected
- degraded: Some services have issues but system is functional
- error: Critical issues affecting system functionality
- unknown: Health check failed or metrics unavailable
Fallback Behavior
If detailed metrics collection fails, the health endpoint falls back to basic status reporting:
{
"status": "unknown",
"message": "Metrics collection failed",
"services": {}
}
This ensures the health endpoint remains functional even if metrics collection encounters issues.
Configuration
Health monitoring is automatically enabled when the API server starts. No additional configuration is required.
Dependencies
The health monitoring system requires psutil for system metrics collection:
pip install psutil
This is included in the API optional dependencies:
pip install novacoder[api]
Monitoring Best Practices
For Users
- Monitor memory usage trends over time
- Check database status if experiencing memory issues
- Review queue depth during high-load periods
- Set up alerts for degraded or error status
For Developers
- Add custom health checks for new services
- Log health check failures with context
- Implement graceful degradation for missing metrics
- Test health endpoint under load conditions
Adding Custom Health Checks
To add custom health checks for new services:
- Add service status to the health endpoint in
novacoder/api/routes_system.py - Include service-specific metrics in the response
- Add corresponding UI cards in
novacoder/api/_html.py - Test health check failure scenarios
# Example custom health check
custom_status = {
"status": "running",
"healthy": True,
"message": "Custom service operational"
}
Troubleshooting
High Memory Usage
- Check for memory leaks in long-running processes
- Review memory purge intervals
- Consider increasing system memory if consistently high
Database Connection Issues
- Verify database file permissions
- Check disk space for database growth
- Review WAL mode checkpoint intervals
AI Provider Unavailable
- Verify API key configuration
- Check network connectivity to AI provider
- Review provider-specific rate limits
Queue Depth Growing
- Check for stuck requests
- Review processing bottlenecks
- Consider scaling resources
Related Documentation
- REST API
- Memory
- AI Runtime
- Configuration
Web UI Integration
The Health system is fully integrated into the Nova Coder Web UI with a dedicated "Health" navigation item under the Administration section.
Health UI Features
The Health UI provides:
- System Status Display: Overall system health status (healthy, degraded, error, unknown)
- System Message Display: Descriptive message about current system state
- Memory Metrics Display: RSS memory usage, VMS memory usage, and memory percentage
- Database Status Display: Database connection status
- AI Provider Status Display: AI provider availability and status
- Service Health Counts: Total services count and healthy services count
API Endpoints Used
The Health UI integrates with the following API endpoint:
GET /api/health- Get detailed health metrics including memory usage, database status, and AI provider availability
UI Navigation
Access the Health UI by:
- Navigate to the Administration section in the sidebar
- Click on "Health"
- The UI displays health metrics in a grid layout
JavaScript Integration
The Health UI is implemented in novacoder/web/react/src/pages/Monitoring.tsx with the following functions:
renderHealth()- Main render function for the Health pageloadHealthData()- Load and display health metrics
Response Handling
The UI handles API responses according to the actual response structure from the health endpoint:
- Health Response: Expects status, message, services (object with service names as keys), and metrics (object containing memory, database, ai_providers, and queue)
- Memory Metrics: Expects rss_mb, vms_mb, and percent fields
- Database Metrics: Expects status field
- AI Provider Metrics: Expects status field
- Services: Expects object with service names as keys, each containing healthy, status, and message fields
Display Format
The Health UI displays metrics in a grid layout with:
- Status Badge: Color-coded badge indicating system health (green for healthy, yellow for degraded, red for error)
- Memory Metrics: RSS and VMS in MB, memory percentage
- Database Status: Connection status with badge
- AI Provider Status: Provider availability status
- Service Counts: Total services and healthy services count