Skip to main content
The Heartbeat system provides health checks, monitoring, and operational commands for managing switchAILocal in production environments.

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
The Heartbeat, Steering, Hooks, and Learning commands are currently in development. This page documents the planned architecture based on the source code structure.

CLI Commands

switchAILocal provides several system management commands:

Health Monitoring

Streaming Configuration

Configure heartbeat intervals for streaming requests in config.yaml:
config.yaml
Purpose:
  • 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:
Get comprehensive system metrics:
Example Response:

Steering Commands

Steering allows runtime configuration changes without restarting:

Reload Configuration

Use cases:
  • Update intelligence matrix
  • Add/remove API keys
  • Adjust Superbrain settings
  • Modify routing strategies
Some configuration changes (like port or tls) require a full restart.

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

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:
  • Requests per second
  • Success rate
  • Average latency (p50, p95, p99)
  • Error rate by type

Troubleshooting

Symptom: Health check endpoint taking > 1s to respondPossible causes:
  1. System under heavy load
  2. Database/disk I/O bottleneck
  3. Network connectivity issues
Solutions:
  • Reduce concurrent request limit
  • Increase server resources
  • Enable request queuing
Error: Failed to reload configurationCheck:
  1. Management key is correct
  2. config.yaml syntax is valid
  3. File permissions allow reading config.yaml
Debug:
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