Why You Need Server Monitoring Alerts
Server downtime costs businesses an average of $5,600 per minute according to Gartner. Even for small teams and indie projects, an unreachable server means lost revenue, frustrated users, and damaged credibility. The difference between a 5-minute outage and a 2-hour outage often comes down to one thing: how quickly you find out about it.
Professional monitoring tools like Datadog or New Relic are powerful, but they cost hundreds of dollars per month and take significant time to configure. For many projects, a simple script that checks your server health and sends you a Telegram message or Slack notification is all you need. This guide shows you how to build exactly that with One-Ping.
What you will build: A server monitoring system that checks uptime, CPU, memory, and disk metrics every minute, and sends instant multi-channel alerts when thresholds are exceeded. Total setup time: about 30 minutes.
Step-by-Step Setup
Define What to Monitor
Start by identifying the metrics that matter most for your application. The five essential server metrics are: Uptime/Availability (is the server responding?), CPU usage (is it overloaded?), Memory usage (is it running out of RAM?), Disk space (is storage filling up?), and Response time (is it slow?). For each metric, define a threshold that triggers an alert. Common defaults are: CPU above 90%, memory above 85%, disk above 80%, and response time above 2 seconds.
Create a Health Check Script
Write a simple script that checks your metrics and calls the One-Ping API when a threshold is breached. You can use a bash script on the server itself, a Node.js or Python script running elsewhere, or an n8n workflow. The examples below cover all three approaches. The script should check each metric, compare it to your threshold, and only send an alert if the threshold is exceeded. This prevents alert fatigue from constant OK notifications.
Configure One-Ping Alert Channels
Log in to your One-Ping dashboard and configure the channels you want to receive server alerts on. For server monitoring, the recommended setup is: Slack for team visibility (everyone on the ops team sees it), Telegram for personal mobile notifications (you get pinged directly on your phone), and SMS for critical-only alerts (when the server is completely down). See our multi-channel notification guide for how to configure each channel.
Schedule Monitoring with Cron
Use cron (Linux/macOS) or Task Scheduler (Windows) to run your health check script at regular intervals. For most servers, checking every 1 to 5 minutes strikes a good balance between quick detection and resource usage. Add the cron entry as described in the examples below. Make sure your cron job logs its output so you can troubleshoot if the monitoring script itself fails.
Build an n8n Monitoring Workflow (Optional)
For more advanced monitoring without writing code, use n8n to create a visual monitoring workflow. n8n can ping multiple endpoints, check response codes, parse health check JSON responses, apply conditional logic, and trigger One-Ping notifications. This is especially useful if you want to monitor multiple servers or services from a single workflow with different alert rules for each.
Bash Health Check Script
This script runs directly on your server and checks CPU, memory, and disk usage. Drop it in /usr/local/bin/health-check.sh and make it executable.
#!/bin/bash # Server health check with One-Ping alerts API_KEY="YOUR_API_KEY" SERVER_NAME="prod-web-01" ALERT_CHANNELS='["telegram","slack"]' # Thresholds CPU_THRESHOLD=90 MEM_THRESHOLD=85 DISK_THRESHOLD=80 # Get current metrics CPU_USAGE=$(top -bn1 | grep "Cpu(s)" | awk '{print $2}' | cut -d. -f1) MEM_USAGE=$(free | grep Mem | awk '{printf "%.0f", $3/$2 * 100}') DISK_USAGE=$(df / | tail -1 | awk '{print $5}' | tr -d '%') # Check CPU if [ "$CPU_USAGE" -gt "$CPU_THRESHOLD" ]; then curl -s -X POST https://api.one-ping.com/send \ -H "Authorization: Bearer $API_KEY" \ -H "Content-Type: application/json" \ -d "{ \"message\": \"CPU Alert on $SERVER_NAME: ${CPU_USAGE}% (threshold: ${CPU_THRESHOLD}%)\", \"channels\": $ALERT_CHANNELS }" fi # Check Memory if [ "$MEM_USAGE" -gt "$MEM_THRESHOLD" ]; then curl -s -X POST https://api.one-ping.com/send \ -H "Authorization: Bearer $API_KEY" \ -H "Content-Type: application/json" \ -d "{ \"message\": \"Memory Alert on $SERVER_NAME: ${MEM_USAGE}% (threshold: ${MEM_THRESHOLD}%)\", \"channels\": $ALERT_CHANNELS }" fi # Check Disk if [ "$DISK_USAGE" -gt "$DISK_THRESHOLD" ]; then curl -s -X POST https://api.one-ping.com/send \ -H "Authorization: Bearer $API_KEY" \ -H "Content-Type: application/json" \ -d "{ \"message\": \"Disk Alert on $SERVER_NAME: ${DISK_USAGE}% (threshold: ${DISK_THRESHOLD}%)\", \"channels\": $ALERT_CHANNELS }" fi
Add it to cron to run every minute:
# Edit crontab crontab -e # Add this line to check every minute * * * * * /usr/local/bin/health-check.sh >> /var/log/health-check.log 2>&1
Node.js HTTP Health Check
This script runs externally and monitors your server's HTTP availability and response time. It is ideal for checking if your website or API is reachable from the outside.
const https = require('https'); const checkServer = (url) => { return new Promise((resolve) => { const start = Date.now(); const req = https.get(url, (res) => { resolve({ status: res.statusCode, responseTime: Date.now() - start, ok: res.statusCode >= 200 && res.statusCode < 400 }); }); req.on('error', () => { resolve({ status: 0, responseTime: 0, ok: false }); }); req.setTimeout(10000, () => { req.destroy(); resolve({ status: 0, responseTime: 10000, ok: false }); }); }); }; const monitor = async () => { const result = await checkServer('https://yourapp.com/health'); if (!result.ok || result.responseTime > 2000) { await fetch('https://api.one-ping.com/send', { method: 'POST', headers: { 'Authorization': 'Bearer YOUR_API_KEY', 'Content-Type': 'application/json' }, body: JSON.stringify({ message: `Server Alert: yourapp.com is ${result.ok ? 'slow' : 'DOWN'}! Status: ${result.status}, Response: ${result.responseTime}ms`, channels: ['telegram', 'slack', 'sms'] }) }); } }; monitor();
n8n Monitoring Workflow
For a no-code approach, create an n8n workflow that monitors multiple endpoints. The workflow structure is:
- Schedule Trigger -- runs every 5 minutes.
- HTTP Request node -- pings your server's health endpoint.
- IF node -- checks if the response status is not 200 or if the response time exceeds your threshold.
- HTTP Request node -- calls One-Ping API to send an alert if the condition is met.
You can duplicate the HTTP Request and IF nodes to monitor multiple servers or endpoints in the same workflow. n8n's visual interface makes it easy to add new servers or adjust thresholds without writing code.
n8n template available: We have a ready-to-import n8n template for server monitoring that includes multi-server support, configurable thresholds, and One-Ping integration. Import it into your n8n instance and customize the URLs and thresholds.
Alert Severity Levels
Not every alert deserves the same response. Implement severity levels to reduce alert fatigue and ensure critical issues get immediate attention:
Warning (Slack only)
CPU 80-90%, Memory 75-85%, or response time 1-2 seconds. Send to your Slack monitoring channel. No phone notifications.
Critical (Slack + Telegram)
CPU above 90%, Memory above 85%, disk above 80%. Send to Slack and Telegram for immediate mobile notification.
Down (All channels + SMS)
Server unreachable or HTTP 5xx errors. Blast to Slack, Telegram, Email, and SMS. Wake someone up if needed.
Best Practices
- Avoid alert storms: Add a cooldown period to your monitoring script. If an alert was sent in the last 15 minutes for the same issue, skip the duplicate. A simple flag file or Redis key works for this.
- Include recovery notifications: When a metric returns to normal after an alert, send a "recovered" notification so your team knows the issue resolved.
- Monitor from outside: Running a health check on the server itself cannot detect network issues or DNS failures. Always have at least one external check.
- Test your alerts: Periodically trigger a test alert to make sure the entire pipeline works, from health check to One-Ping to your phone notification.
- Log everything: Keep a log of all health checks and alerts for post-incident analysis and to identify trends before they become critical.