Server Monitoring Setup Guide: Keep Your Server Healthy

*Photo by Atlantic Ambience on Pexels*
Your server can fail silently. A process crashes, disk space fills up, memory leaks, or traffic spikes overwhelm resources. Without monitoring, you only discover problems when users complain. A proper monitoring setup alerts you before users notice anything wrong. This guide shows you how to set up server monitoring in under 30 minutes.
## What to Monitor
### Essential Metrics
| Metric | Warning Threshold | Critical Threshold | Why It Matters |
|---|---|---|---|
| CPU usage | > 70% | > 90% | High CPU means slow responses |
| Memory usage | > 75% | > 90% | Low memory = OOM kills |
| Disk usage | > 80% | > 90% | Full disk = application crashes |
| Disk I/O | > 1000 IOPS | > 2000 IOPS | Slow disk = slow database |
| Network traffic | > 100 Mbps | > 500 Mbps | Bandwidth saturation |
| Load average | > # of CPU cores | > 2x # of CPU cores | System is overloaded |
### Application Metrics
- HTTP response times (p50, p95, p99)
- Error rate (5xx responses)
- Request rate (RPS)
- Active connections
- Database query performance
## Free Monitoring Stack Setup
### Option 1: Prometheus + Grafana (Recommended)
The most popular open-source monitoring stack.
“`bash
# Install Prometheus
wget https://github.com/prometheus/prometheus/releases/latest/download/prometheus-*.linux-amd64.tar.gz
tar xvf prometheus-*.tar.gz
sudo mv prometheus-*/prometheus /usr/local/bin/
# Install Node Exporter (system metrics)
wget https://github.com/prometheus/node_exporter/releases/latest/download/node_exporter-*.linux-amd64.tar.gz
tar xvf node_exporter-*.tar.gz
sudo mv node_exporter-*/node_exporter /usr/local/bin/
# Install Grafana
sudo apt-get install -y software-properties-common
sudo add-apt-repository “deb https://packages.grafana.com/oss/deb stable main”
sudo apt-get update
sudo apt-get install grafana
“`
### Option 2: Netdata (One-Command Setup)
Netdata provides a beautiful real-time dashboard with zero configuration.
“`bash
bash <(curl -Ss https://my-netdata.io/kickstart.sh)
“`
Access your dashboard at `http://your-server:19999`.
### Option 3: Lightweight Scripts
If you prefer simplicity over visual dashboards:
“`bash
#!/bin/bash
# health-check.sh — Run via cron every 5 minutes
THRESHOLD_CPU=80
THRESHOLD_DISK=90
ALERT_EMAIL=”[email protected]”
check_cpu() {
CPU=$(top -bn1 | grep “Cpu(s)” | awk ‘{print $2}’ | cut -d. -f1)
if [ “$CPU” -gt “$THRESHOLD_CPU” ]; then
echo “CPU at ${CPU}% — exceeds threshold” | mail -s “CPU Alert” $ALERT_EMAIL
fi
}
check_disk() {
DISK=$(df -h / | awk ‘NR==2 {print $5}’ | cut -d% -f1)
if [ “$DISK” -gt “$THRESHOLD_DISK” ]; then
echo “Disk at ${DISK}% — action required” | mail -s “Disk Alert” $ALERT_EMAIL
fi
}
check_cpu
check_disk
“`
## Setting Up Alerts
### Grafana Alert Rules
1. Go to Alerting → Alert rules → New alert
2. Set a condition (e.g., `cpu_usage > 80`)
3. Choose evaluation interval (every 1m for 5m)
4. Configure notification channel (email, Slack, Telegram)
### Slack Integration Example
“`bash
#!/bin/bash
WEBHOOK_URL=”https://hooks.slack.com/services/YOUR/WEBHOOK/URL”
send_slack_alert() {
local message=$1
curl -X POST -H ‘Content-type: application/json’ \
–data “{\”text\”:\”:warning: Server Alert: $message\”}” \
$WEBHOOK_URL
}
send_slack_alert “Disk usage at 90% on production server”
“`
## Monitoring Nginx with GoAccess
GoAccess provides real-time web server analytics:
“`bash
# Install GoAccess
sudo apt-get install goaccess
# Generate real-time HTML report
goaccess /var/log/nginx/access.log -o /var/www/html/report.html –log-format=COMBINED
# For real-time monitoring
goaccess /var/log/nginx/access.log –log-format=COMBINED
“`
## Automated Response Actions
When certain thresholds are exceeded, you can automate responses:
### Auto-Cleanup Script
“`bash
#!/bin/bash
# Run when disk > 85%
# Clean Docker
docker system prune -af
# Rotate and compress old logs
find /var/log -name “*.log” -mtime +7 -exec gzip {} \;
# Remove old backups (keep last 3)
ls -t /backups/*.sql.gz | tail -n +4 | xargs rm -f
# Clear systemd journal (keep last 500MB)
journalctl –vacuum-size=500M
“`
## Monitoring Checklist
### Initial Setup
CPU usage monitoring with alert at 80%
Memory usage monitoring with alert at 90%
Disk usage monitoring with alert at 85%
Network traffic monitoring
HTTP response time tracking (p95 < 500ms)
Error rate alerting (> 1% 5xx responses)
SSL certificate expiry monitoring (alert 30 days before)
### Weekly
Review monitoring dashboards
Check for any missed alerts
Verify alert delivery (email, Slack, etc.)
Review resource trends
### Monthly
Tune alert thresholds based on patterns
Check monitoring tool updates
Review and archive old metrics
## Conclusion
Server monitoring does not need to be complex or expensive. Start with a simple health check script and basic CPU/disk alerts. Add a dashboard tool like Netdata or Grafana when you need deeper visibility. The key is having alerts that reach you before users notice problems.
For more deployment scripts, monitoring tools, and automation resources, visit freeresource.store.
*For more developer tools and resources, visit freeresource.store.*