Files
proxmox/scripts/unifi/setup-monitoring.md
defiQUG fbda1b4beb
Some checks failed
Deploy to Phoenix / deploy (push) Has been cancelled
docs: Ledger Live integration, contract deploy learnings, NEXT_STEPS updates
- ADD_CHAIN138_TO_LEDGER_LIVE: Ledger form done; public code review repo bis-innovations/LedgerLive; init/push commands
- CONTRACT_DEPLOYMENT_RUNBOOK: Chain 138 gas price 1 gwei, 36-addr check, TransactionMirror workaround
- CONTRACT_*: AddressMapper, MirrorManager deployed 2026-02-12; 36-address on-chain check
- NEXT_STEPS_FOR_YOU: Ledger done; steps completable now (no LAN); run-completable-tasks-from-anywhere
- MASTER_INDEX, OPERATOR_OPTIONAL, SMART_CONTRACTS_INVENTORY_SIMPLE: updates
- LEDGER_BLOCKCHAIN_INTEGRATION_COMPLETE: bis-innovations/LedgerLive reference

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-02-12 15:46:57 -08:00

3.3 KiB

UniFi Monitoring Setup Guide

This guide explains how to set up monitoring and alerts for your UniFi Controller.

Available Monitoring Scripts

monitor-health.sh

Basic health monitoring script that:

  • Checks API connectivity
  • Logs health status
  • Sends alerts on failures
  • Writes logs to logs/unifi-health.log

Usage:

# Run once
./scripts/unifi/monitor-health.sh

# Run periodically with cron
# Add to crontab (crontab -e):
# */5 * * * * /path/to/proxmox/scripts/unifi/monitor-health.sh

Setting Up Cron Monitoring

  1. Edit crontab:

    crontab -e
    
  2. Add monitoring job:

    # Check UniFi health every 5 minutes
    */5 * * * * cd /home/intlc/projects/proxmox && ./scripts/unifi/monitor-health.sh >> /tmp/unifi-monitor.log 2>&1
    
  3. For more frequent checks:

    # Every minute (for critical systems)
    * * * * * cd /home/intlc/projects/proxmox && ./scripts/unifi/monitor-health.sh >> /tmp/unifi-monitor.log 2>&1
    

Alert Integration

The monitor-health.sh script includes a placeholder send_alert() function. You can integrate:

Email Alerts

send_alert() {
    local message="$1"
    echo "$message" | mail -s "UniFi Alert" admin@example.com
}

Webhook Alerts (Slack, Discord, etc.)

send_alert() {
    local message="$1"
    curl -X POST https://hooks.slack.com/services/YOUR/WEBHOOK/URL \
        -H 'Content-Type: application/json' \
        -d "{\"text\":\"$message\"}"
}

Custom Webhook

send_alert() {
    local message="$1"
    curl -X POST https://your-alerting-service.com/webhook \
        -H 'Content-Type: application/json' \
        -d "{\"message\":\"$message\",\"timestamp\":\"$(date -Iseconds)\"}"
}

Log Rotation

To prevent log files from growing too large, set up log rotation:

  1. Create logrotate config (/etc/logrotate.d/unifi-monitor):

    /home/intlc/projects/proxmox/logs/unifi-health.log {
        daily
        rotate 7
        compress
        missingok
        notifempty
    }
    
  2. Or use a simple cleanup in cron:

    # Clean old logs (keep last 7 days)
    0 0 * * * find /home/intlc/projects/proxmox/logs -name "unifi-health.log*" -mtime +7 -delete
    

Advanced Monitoring

For more advanced monitoring, consider:

  1. Prometheus + Grafana:

    • Export metrics from monitoring script
    • Create dashboards for visualization
    • Set up alerting rules
  2. Systemd Timer:

    • Create a systemd service and timer
    • More robust than cron
    • Better logging and error handling
  3. Monitoring Services:

    • UptimeRobot
    • Pingdom
    • StatusCake
    • Custom monitoring solution

Testing

Test the monitoring script:

# Test health check
./scripts/unifi/monitor-health.sh

# Check log output
tail -f logs/unifi-health.log

# Test alert function (modify script to test)
./scripts/unifi/monitor-health.sh

Troubleshooting

Script fails silently

  • Check cron logs: grep CRON /var/log/syslog
  • Check script permissions: ls -l scripts/unifi/monitor-health.sh
  • Test manually: bash -x scripts/unifi/monitor-health.sh

Alerts not sending

  • Verify network connectivity
  • Check webhook URL/credentials
  • Test alert function manually

Log file permissions

  • Ensure logs directory is writable
  • Check user permissions
  • Create logs directory if missing: mkdir -p logs