Overview
The Heartbeat system includes:- Health Checks: Continuous monitoring of system health
- Steering Commands: Runtime configuration management
- Hooks System: Custom event handling
- Learning Commands: Model performance analysis
CLI Commands
switchAILocal provides several system management commands:Health Monitoring
Streaming Configuration
Configure heartbeat intervals for streaming requests inconfig.yaml:
config.yaml
- keepalive-seconds: Send SSE heartbeat comments to prevent connection timeouts
- bootstrap-retries: Retry authentication/connection before streaming starts
Monitoring Endpoints
Use the management API for health checks:- Metrics
- Health Check
- Provider Status
Get comprehensive system metrics:Example Response:
Steering Commands
Steering allows runtime configuration changes without restarting:Reload Configuration
- Update intelligence matrix
- Add/remove API keys
- Adjust Superbrain settings
- Modify routing strategies
Dynamic Matrix Updates
Update the intelligence matrix at runtime:1
Edit config.yaml
config.yaml
2
Reload configuration
3
Verify changes
Hooks System
Hooks allow custom event handling for routing decisions, failures, and other events.Hook Types
- Pre-Request
- Post-Request
- On-Error
Execute before routing decisions:
plugins/hooks/pre-request.lua
Configuration
config.yaml
Learning Commands
The Learning system analyzes model performance and optimizes routing:Performance Analysis
Configuration
config.yaml
Operational Best Practices
1
Monitor Metrics Regularly
Set up automated monitoring:
2
Configure Health Checks
Use the health endpoint for load balancer health checks:
nginx.conf
3
Enable Audit Logging
Track all management operations:
config.yaml
4
Set Up Alerts
Monitor critical metrics:
- Request failure rate > 5%
- Average latency > 5000ms
- Disk usage > 90%
- Superbrain healing success rate < 80%
5
Regular Backups
Back up configuration and memory data:
Monitoring Stack Integration
Prometheus
Export metrics to Prometheus:docker-compose.yml
Grafana Dashboard
Key metrics to monitor:- Request Metrics
- Intelligence Metrics
- Superbrain Metrics
- System Metrics
- Requests per second
- Success rate
- Average latency (p50, p95, p99)
- Error rate by type
Troubleshooting
High latency on health checks
High latency on health checks
Symptom: Health check endpoint taking > 1s to respondPossible causes:
- System under heavy load
- Database/disk I/O bottleneck
- Network connectivity issues
- Reduce concurrent request limit
- Increase server resources
- Enable request queuing
Steering reload fails
Steering reload fails
Error:
Failed to reload configurationCheck:- Management key is correct
- config.yaml syntax is valid
- File permissions allow reading config.yaml
Streaming requests timing out
Streaming requests timing out
Symptom: Streaming requests disconnect after 15-30 secondsSolution:
Increase keepalive interval:
config.yaml
Emergency Procedures
Service Degradation
If performance degrades:1
Check metrics
2
Identify bottleneck
- High latency? Scale horizontally
- High error rate? Check provider status
- High memory? Reduce retention period
3
Apply quick fixes
config.yaml
4
Reload configuration
Complete Outage
If switchAILocal stops responding:1
Check process status
2
Review logs
3
Restart service
4
Verify health
Next Steps
Configuration Guide
Learn about all configuration options
Management API
Explore management endpoints