Health Checking

The lyrebird-diagnostics.sh script provides three diagnostic modes with increasing depth:

ModeCommandUse CaseDuration
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 CodeMeaningAction Required
0All checks passedNone
1Warnings detected — system functionalReview warnings, plan maintenance
2Failures detected — system degradedInvestigate and fix immediately
127Prerequisites missingInstall missing dependencies

Orchestrator Integration

Diagnostics are accessible from the Orchestrator menu without remembering commands:

What Gets Checked

CategoryWhat'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
ℹ️
Auto-Installed Cron Job

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

  1. Start the metrics server on port 9100
  2. Add a Prometheus scrape job pointing to your server
  3. Import a dashboard in Grafana using the lyrebird_* metrics

Key metrics to dashboard:

Webhook Alerting

Setup

# Interactive webhook setup
./lyrebird-alerts.sh setup

# Test your webhook
./lyrebird-alerts.sh test

What Events Trigger Alerts

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

CodecEfficiencyLatencyBest For
OpusBest quality/bitrate ratioVery lowAll use cases (recommended)
AACGoodModerateWide client compatibility
PCMLossless (highest bandwidth)LowestPost-processing pipelines

Sample Rate Selection

Sample RateCPU ImpactBandwidthUse Case
16,000 HzLowestLowestSpeech, monitoring
44,100 HzLowLowCD quality, general
48,000 HzNormalModerateProfessional standard (default)
96,000 HzHighHighHigh-res audio

Bitrate Tuning

BitrateBandwidth per Stream per ClientQuality
64 kbps~8 KB/sAcceptable for speech
96 kbps~12 KB/sGood for speech
128 kbps~16 KB/sGood for speech & music (default)
192 kbps~24 KB/sHigh quality
256 kbps~32 KB/sVery high quality

Resource Usage Estimates

ComponentBase RAMPer 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

⚠️
USB Bandwidth Limitations

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