A monitoring script for Midnight validator node that checks node synchronization status and reports health metrics to Healthchecks.io.
- 🔍 Block Monitoring: Tracks latest and finalized block numbers
- 📊 Sync Status: Calculates synchronization percentage and block lag
- 🚨 Health Alerts: Sends success/failure pings to Healthchecks.io
- 📝 Logging: Timestamp-based logging with status indicators
- ⚡ Error Handling: Robust error handling and validation
- 🔧 Configurable: Easy configuration via environment variables
Install required dependencies on Ubuntu/Debian:
sudo apt update
sudo apt install curl jq gawkIMPORTANT: You must update the health check URL before using this script.
Edit the script and replace the PING_BASE URL on line 9:
readonly PING_BASE="https://hc-ping.com/YOUR-UNIQUE-HEALTHCHECK-ID"Replace YOUR-UNIQUE-HEALTHCHECK-ID with your Healthchecks.io check ID.
| Variable | Default | Description |
|---|---|---|
RPC_URL |
http://127.0.0.1:9944 |
Node RPC endpoint |
MAX_ALLOWED_GAP |
25 |
Maximum allowed block gap before marking unhealthy |
NODE_ID |
midnight-validator-1 |
Unique identifier for your node |
TIMEOUT |
10 |
HTTP request timeout in seconds |
LOG_FILE |
./healthchecks.log |
Path to log file |
- Download the script:
wget https://raw.githubusercontent.com/Midnight-Scripts/Midnight-Node-Health-Check-Script/refs/heads/main/midnight-healthcheck.sh
chmod +x midnight-healthcheck.sh-
Update the health check URL (see Configuration section above)
-
Test the script:
./midnight-healthcheck.shTo run the health check every minute, set up a cron job:
crontab -e* * * * * /path/to/midnight-healthcheck.sh# Check if cron service is running
sudo systemctl status cron
# View cron logs
sudo tail -f /var/log/syslog | grep CRON./midnight-healthcheck.shNote: The script automatically creates a log file (healthchecks.log) in the same directory where the script is located. This log file contains timestamps and status indicators (✅ for success, ❌ for failure, 💥 for errors).
Healthy Node:
✅ Node is healthy
Node: midnight-validator-1
Timestamp: 2024-01-15 10:30:45 UTC
Latest Block: 12345
Finalized Block: 12320
Sync Percentage: 99.80%
Block Lag: 25 blocks
Status: HEALTHY
Unhealthy Node:
❌ Node lag too high!
Node: midnight-validator-1
Timestamp: 2024-01-15 10:30:45 UTC
Latest Block: 12345
Finalized Block: 12280
Sync Percentage: 99.47%
Block Lag: 65 blocks
Status: UNHEALTHY
- Create account at healthchecks.io
- Create a new check with these settings:
- Period: 5 minutes
- Grace Time: 1 minute
- Copy the ping URL
- Update the
PING_BASEvariable in the script
The script sends different HTTP requests for success/failure:
- Success:
POSTto$PING_BASE - Failure:
POSTto$PING_BASE/fail
1. Permission Denied:
chmod +x midnight-healthcheck.sh2. Dependencies Missing:
which curl jq awk3. RPC Connection Failed:
- Verify your node is running
- Check the RPC URL is correct
- Ensure firewall allows connections
4. Cron Job Not Running:
sudo systemctl status cron
sudo journalctl -u cronView recent health check logs:
tail -f healthchecks.logCheck for errors:
grep ERROR healthchecks.log