CPU Monitoring
Bash
top -d 1
htop
uptime # check load average (overload if higher than core count)
nproc
lscpu | grep "CPU(s):"
ps aux --sort=-%cpu | head -10Memory Monitoring
Bash
free -h
watch -n 1 free -h
ps aux --sort=-%mem | head -10
cat /proc/meminfo | grep -E "MemTotal|MemFree|MemAvailable|Cached"
swapon --showDisk Monitoring
Bash
df -h
df -h /var
du -sh /var/* | sort -rh | head -10
du -sh /* | sort -rh | head -10
df -i # inode usage
iostat -xz 1
iotop -aoNetwork Monitoring
Bash
ss -tunlp
ss -s
iftop -i eth0
nload eth0
# check connection counts (DDoS detection)
ss -tn | awk 'NR>1 {print $5}' | cut -d: -f1 | sort | uniq -c | sort -rn | headvmstat / sar
Bash
vmstat 1 10
sudo apt install sysstat
sar -u 1 5 # CPU
sar -r 1 5 # memory
sar -d 1 5 # diskCPU Alert Script
Bash
#!/bin/bash
THRESHOLD=90
CPU=$(top -bn1 | grep "Cpu(s)" | awk '{print $2}' | cut -d'%' -f1 | cut -d',' -f1)
CPU=${CPU%.*}
if [[ $CPU -gt $THRESHOLD ]]; then
echo "[ALERT] CPU ${CPU}%" | mail -s "CPU Alert" admin@example.com
fiEditorial note
AI tools may assist drafting. Check the evidence in each guide for whether commands were run and which environment was used. Confirm the current docs for your version before applying instructions, and email us about errors. email us
Topic-related official docs (auto-linked · not per-claim sources)Linux man pages ↗
Questions & answers
Ask a question about this guide. We'll review and reply.