Monitoring & Diagnostics
Health checks, metrics, alerting, performance tuning, and long-term monitoring best practices.
Health Checking
The lyrebird-diagnostics.sh script provides three diagnostic modes with increasing depth:
| Mode | Command | Use Case | Duration |
|---|---|---|---|
| Quick | sudo ./lyrebird-diagnostics.sh quick |
Daily automated checks, pre-operation verification | ~10 seconds |
| Full | sudo ./lyrebird-diagnostics.sh full |
Weekly review, after configuration changes | ~30 seconds |
| Debug | sudo ./lyrebird-diagnostics.sh debug |
Troubleshooting failures, maximum verbosity | ~60 seconds |
Diagnostic Exit Codes
| Exit Code | Meaning | Action Required |
|---|---|---|
| 0 | All checks passed | None |
| 1 | Warnings detected — system functional | Review warnings, plan maintenance |
| 2 | Failures detected — system degraded | Investigate and fix immediately |
| 127 | Prerequisites missing | Install missing dependencies |
Orchestrator Integration
Diagnostics are accessible from the Orchestrator menu without remembering commands:
- Main Menu → 5 → 1: Quick health check
- Main Menu → 5 → 2: Full diagnostic
- Main Menu → 5 → 3: Debug diagnostic
What Gets Checked
| Category | What's Verified |
|---|---|
| System | OS type, kernel version, uptime, load average, memory & CPU utilization |
| Dependencies | ffmpeg, arecord, jq, curl, lsusb, udevadm |
| USB Audio Devices | Detection, ALSA card availability, mapping status, port path validation, busy state |
| MediaMTX Service | Binary installation, config file validity, service status, API accessibility, port 8554 & 9997 |
| Stream Status | Active stream count, FFmpeg process validation, stream health & uptime, per-stream resource usage |
| RTSP Connectivity | Port 8554 listening, protocol validation, test connection |
| System Resources | File descriptor usage, CPU per process, memory availability, disk space |
| Log Analysis | Error detection in recent logs, warnings, access patterns |
| Time Sync | NTP / Chrony service status, time drift detection |
Monitoring Best Practices
Recommended Schedule
# Add to /etc/cron.d/lyrebird-monitoring
# Quick check every 5 minutes (via stream manager's install command)
*/5 * * * * root /path/to/lyrebird-stream-manager.sh monitor
# Full diagnostic daily at 6 AM
0 6 * * * root /path/to/lyrebird-diagnostics.sh full >> /var/log/lyrebird-daily-check.log 2>&1
# Storage cleanup daily at 3 AM
0 3 * * * root /path/to/lyrebird-storage.sh cleanup --quiet
When you run sudo ./lyrebird-stream-manager.sh install, a cron job is automatically created at /etc/cron.d/mediamtx-monitor that runs health checks every 5 minutes. You don't need to set this up manually.
Log Rotation
Install the provided logrotate configuration to prevent log files from filling the disk:
# Install log rotation
sudo cp config/lyrebird-logrotate.conf /etc/logrotate.d/lyrebird
# Test configuration
sudo logrotate -d /etc/logrotate.d/lyrebird
# Force rotation (for testing)
sudo logrotate -f /etc/logrotate.d/lyrebird
Prometheus Metrics
Export metrics for Grafana dashboards and alerting:
# Start HTTP metrics server
./lyrebird-metrics.sh serve --port 9100
# Or use as a textfile collector for node_exporter
./lyrebird-metrics.sh > /var/lib/node_exporter/textfile_collector/lyrebird.prom
Grafana Dashboard Setup
- Start the metrics server on port 9100
- Add a Prometheus scrape job pointing to your server
- Import a dashboard in Grafana using the
lyrebird_*metrics
Key metrics to dashboard:
lyrebird_stream_active— Alert when 0lyrebird_mediamtx_up— Alert when 0lyrebird_disk_usage_percent— Alert when > 80%lyrebird_cpu_usage_percent— Alert when > 80%lyrebird_usb_device_connected— Alert when 0
Webhook Alerting
Setup
# Interactive webhook setup
./lyrebird-alerts.sh setup
# Test your webhook
./lyrebird-alerts.sh test
What Events Trigger Alerts
- Stream goes down or comes back up
- USB device disconnects or reconnects
- Disk usage exceeds warning/critical thresholds
- MediaMTX service goes down or recovers
- Network connectivity lost or restored
Rate Limiting
Alerts are rate-limited by default to prevent spam. Duplicate alerts within the configured window
(default: 300 seconds) are suppressed. Adjust in /etc/lyrebird/alerts.conf:
LYREBIRD_ALERT_RATE_LIMIT=300 # Seconds between duplicate alerts
Performance & Optimization
Codec Selection
| Codec | Efficiency | Latency | Best For |
|---|---|---|---|
| Opus | Best quality/bitrate ratio | Very low | All use cases (recommended) |
| AAC | Good | Moderate | Wide client compatibility |
| PCM | Lossless (highest bandwidth) | Lowest | Post-processing pipelines |
Sample Rate Selection
| Sample Rate | CPU Impact | Bandwidth | Use Case |
|---|---|---|---|
| 16,000 Hz | Lowest | Lowest | Speech, monitoring |
| 44,100 Hz | Low | Low | CD quality, general |
| 48,000 Hz | Normal | Moderate | Professional standard (default) |
| 96,000 Hz | High | High | High-res audio |
Bitrate Tuning
| Bitrate | Bandwidth per Stream per Client | Quality |
|---|---|---|
| 64 kbps | ~8 KB/s | Acceptable for speech |
| 96 kbps | ~12 KB/s | Good for speech |
| 128 kbps | ~16 KB/s | Good for speech & music (default) |
| 192 kbps | ~24 KB/s | High quality |
| 256 kbps | ~32 KB/s | Very high quality |
Resource Usage Estimates
| Component | Base RAM | Per Stream |
|---|---|---|
| MediaMTX | ~50–100 MB | ~10 MB per active path |
| FFmpeg | — | ~50–100 MB per stream |
Thread Queue Tuning
For high stream counts (4+), increase the thread queue size to reduce buffer underruns:
# In /etc/mediamtx/audio-devices.conf
DEFAULT_THREAD_QUEUE=16384 # Default is 8192
System Tuning
File Descriptor Limits
# Check current limits
ulimit -n
# Increase limits (add to /etc/security/limits.conf)
echo "* soft nofile 8192" | sudo tee -a /etc/security/limits.conf
echo "* hard nofile 16384" | sudo tee -a /etc/security/limits.conf
echo "mediamtx soft nofile 4096" | sudo tee -a /etc/security/limits.conf
echo "mediamtx hard nofile 8192" | sudo tee -a /etc/security/limits.conf
# Apply (requires reboot)
sudo reboot
Network Buffer Sizes
# Increase UDP buffer sizes for streaming
sudo sysctl -w net.core.rmem_max=26214400
sudo sysctl -w net.core.wmem_max=26214400
# Make permanent
echo "net.core.rmem_max=26214400" | sudo tee -a /etc/sysctl.conf
echo "net.core.wmem_max=26214400" | sudo tee -a /etc/sysctl.conf
sudo sysctl -p
USB Power Management
# Disable USB auto-suspend (prevents devices going to sleep)
echo -1 | sudo tee /sys/bus/usb/devices/*/power/autosuspend
# Make permanent via udev rule
echo 'ACTION=="add", SUBSYSTEM=="usb", ATTR{idVendor}=="YOUR_VID", ATTR{power/autosuspend}="-1"' \
| sudo tee /etc/udev/rules.d/50-usb-power.rules
Raspberry Pi Optimization
Raspberry Pi shares USB bandwidth across all ports. This limits reliable operation to 1–2 USB microphones. For 4+ microphones, use an Intel N100 or similar mini PC ($100–150) with proper USB controller topology.
# Use low-quality settings for Raspberry Pi
sudo ./lyrebird-mic-check.sh -g --quality=low
# Consider mono recording to halve bandwidth
DEFAULT_CHANNELS=1
# Reduce stream count to 1-2 maximum
Raspberry Pi Recommended Settings
# /etc/mediamtx/audio-devices.conf (Raspberry Pi)
DEFAULT_SAMPLE_RATE=16000 # or 44100 at most
DEFAULT_CHANNELS=1 # Mono to reduce CPU
DEFAULT_BITRATE=64k # Low bitrate
DEFAULT_CODEC=opus
DEFAULT_THREAD_QUEUE=4096 # Smaller queue to reduce memory