How to monitor CPU, memory and disk usage on a Linux server

Check CPU, memory and disk on Linux with top, free and df, learn which numbers actually matter, pick sensible alert limits, and get alerted before a server runs out.

· 8 min read · By the Spot Downtime team

Most server outages don't start with a crash. They start with a disk quietly filling with logs, memory slowly leaking until the kernel starts killing processes, or CPU pinned by a runaway job until every request times out. All three are visible minutes, hours or days in advance, if you're watching. This guide covers how to read each one on Linux, which numbers are misleading, and how to get alerted automatically.

CPU: what top and uptime tell you

Two commands give you the picture in seconds:

$ uptime
 14:02:11 up 41 days,  3:12,  1 user,  load average: 7.62, 6.90, 4.11

$ top -bn1 | head -3
top - 14:02:12 up 41 days,  3:12,  1 user,  load average: 7.62, 6.90, 4.11
Tasks: 213 total,   9 running, 204 sleeping,   0 stopped,   0 zombie
%Cpu(s): 88.1 us,  5.2 sy,  0.0 ni,  5.9 id,  0.6 wa,  0.0 hi,  0.2 si,  0.0 st
FieldMeansWorry when
us / syTime running your programs / the kernelTogether near 100% for minutes at a time
idIdleNear 0 for long stretches
waWaiting on disk (iowait)Above about 10%: the disk is the bottleneck, not the CPU
stStolen by the hypervisor (cloud VMs)Above a few %: you're sharing a busy host
load averageProcesses running or waiting, over 1, 5 and 15 minutesAbove the number of cores (nproc) and rising

Load average only makes sense next to the core count. A load of 7.62 is fine on a 16-core machine and a queue on a 4-core one. Check yours with nproc. The three numbers also show direction: 7.62, 6.90, 4.11 means it's been climbing for the last quarter of an hour.

Spikes are normal; sustained highs aren't

A web server that spikes to 100% for a few seconds during a deploy is doing its job. The same server at 95% for ten minutes is out of headroom, and the next traffic bump will make it slow. That's why a CPU alert should look at an average over several minutes, not a single reading:

A two-minute spike doesn't wake anyone. Ten minutes over the limit does.

Memory: read available, not free

$ free -h
               total        used        free      shared  buff/cache   available
Mem:            15Gi       9.8Gi       412Mi       210Mi       5.2Gi       5.1Gi
Swap:          2.0Gi       1.1Gi       905Mi

The free column scares people: 412 MB out of 15 GB looks nearly full. It isn't. Linux uses spare memory as a disk cache (buff/cache) and hands it back the moment a program needs it. The number that matters is available: memory programs can get without swapping. Here that's 5.1 GB, so the server is about 68% used and fine.

  • Watch the trend. Available memory that drops a little every day, and never recovers, is usually a leak. Restarting the service hides it until next week.
  • Swap use isn't automatically bad. A little swap that stays put is idle pages moved aside. Swap that keeps growing while available memory shrinks means the server is out of memory and getting slow.
  • Check for the OOM killer. When memory runs out, the kernel kills a process, often the database. Look for it with dmesg -T | grep -i "killed process" or journalctl -k | grep -i oom.

Disk: space, and the inodes nobody checks

$ df -h -x tmpfs -x devtmpfs -x squashfs
Filesystem      Size  Used Avail Use% Mounted on
/dev/nvme0n1p1   50G   19G   29G  40% /
/dev/nvme1n1    200G  162G   38G  81% /var
/dev/nvme2n1     20G   19G  1.4G  93% /var/log

The -x flags hide temporary and snap filesystems, which are always “full” and never matter. Two things catch people out:

  • Each mount fills on its own. The root disk can be at 40% while /var/log is at 93%. Watch every real disk, not just /.
  • Inodes can run out first. Millions of tiny files (sessions, cache entries, mail queues) can use up a filesystem's inodes while df -h still shows space. Check with df -i; the symptom is “No space left on device” on a disk that isn't full.

When a disk is filling, find what's growing:

# The biggest directories on one filesystem, largest last
sudo du -xh /var --max-depth=2 2>/dev/null | sort -h | tail -15

# Deleted files still held open by a process (space that only comes back on restart)
sudo lsof +L1 2>/dev/null | head

The usual culprits are logs without rotation, old Docker images (docker system df), database write-ahead logs and forgotten backups. Unlike CPU, a full disk breaks things at once, so a disk alert shouldn't wait for an average:

Disks alert as soon as one is over the limit, and the alert names it.

Picking alert limits

Good limits leave enough room to act before users notice, without paging you for normal load. Start here and adjust:

ResourceAlert whenWhy
CPUAverage over 90% for 5 to 10 minutesShort spikes are normal; sustained highs mean no headroom
MemoryAverage over 90% for 5 minutesUses available memory, so cache doesn't count against you
DiskAny disk over 85 to 90%Leaves time to clean up; small disks fill faster, so alert earlier
Reports stopNo data for 3 minutesThe server crashed, froze, or lost its network

Alert on symptoms too

Resource alerts warn you early, but they're not the whole story. Keep an uptime check on what users actually reach, so you're also alerted when the site is down for a reason no counter shows.

Watching it all automatically

Running top, free and df is fine for a look. To catch problems at 3 a.m., something has to run them for you and tell you. You can script it (a cron job that checks df and pings a heartbeat only while the disk is healthy), but that gives you a yes or no with no history.

Spot Downtime's server agent does it all once a minute:

  1. Click Add monitor, choose Server, and set the limits from the table above.
  2. Copy the install command from the server's page and run it on the server:
curl -fsSL https://spotdowntime.com/install-agent.sh | sudo sh -s -- --token YOUR-TOKEN

The agent reads the same kernel counters as these commands: CPU from /proc/stat (counting iowait as idle, like top's id plus wa), memory from MemAvailable, and every real disk the way df does. It sends them out over HTTPS, with no ports to open. Within a minute you get charts for each, every disk listed with its limit marked, and alerts on the channels you already use.

Each server gets its own page: live tiles, charts over 1 hour to 30 days, and every disk with your limit marked.

One server is included on the Free plan. Read more in the launch post or on the server monitoring page.

Get new guides by email

Practical posts on monitoring, outages, error fixes and on-call, when they're published. No spam.

Unsubscribe from any email with one click. See our privacy policy.

Keep reading