Skip to main content

Monitoring Linux CPU, Memory, Disk and Network

Diagnose CPU, memory, disk I/O and network bottlenecks on production Linux servers with vmstat, iostat, free, iotop, ss and PSI.

30 Terms

Overview and What You Will Learn

Linux resource monitoring is the habit of checking four resources in a fixed order (CPU, memory, disk I/O, network) and reading utilization, saturation and errors for each one. Done in order, it lets you name the bottleneck of a slow server in about five minutes instead of guessing.

By the end of this lab you will be able to:

  • Read load average per CPU core and explain why it can be high while the CPUs are idle
  • Use free -h and trust the available column instead of free
  • Spot swapping, OOM kills and memory pressure
  • Diagnose disk bottlenecks with iostat -x, pidstat -d and iotop
  • Find the processes and connections behind network load with ss, nethogs and iftop
  • Run a repeatable 5-minute triage script and use PSI (pressure stall information) as a tie-breaker

Why This Matters in Production

A slow server almost always has one dominant bottleneck, and each bottleneck has a different fix. Adding CPU cores to a machine that is waiting on a saturated disk changes nothing. Imagine an on-call engineer at a streaming platform like Hotstar during a live match: latency climbs, dashboards show high load, and the instinct is to scale out. If the real cause is a log volume stuck at 100% disk utilization, every new node inherits the same problem. Engineers who diagnose correctly are the ones who have rehearsed these tools until the order of checks is automatic.

Core Principles

The most reliable framework is the USE method: for every resource, check Utilization (how busy it is), Saturation (how much work is queued) and Errors. The decision tree below applies it in the order that finds most problems fastest.

flowchart TD A([Server is slow]) --> B{Load above
core count?} B -->|Yes| C{vmstat wa
above 10?} B -->|No| D{Available memory
low?} C -->|Yes| E[(Disk I/O bottleneck)] C -->|No| F[CPU saturation] D -->|Yes| G[Memory pressure] D -->|No| H[Check network
and the app] classDef start fill:#326CE5,color:#FFFFFF classDef check fill:#F1F5F9,color:#1E293B classDef bad fill:#EF4444,color:#FFFFFF class A start class B,C,D check class E,F,G,H bad

Two details make this tree accurate. First, on Linux the load average counts tasks that are running, runnable and also tasks in uninterruptible sleep (state D), which is usually waiting on disk. A high load with idle CPUs therefore points at I/O, not at CPU. Second, wa and st in vmstat tell you what the CPU is waiting on: wa is time spent waiting for I/O, and st is time stolen by the hypervisor on a cloud VM.

The memory fields are the most misread output in Linux monitoring:

Field Meaning
total Physical RAM installed
used Memory held by processes and the kernel
free Memory that is completely unused
buff/cache Disk cache the kernel can reclaim when needed
available Realistic estimate of memory for new work (free plus reclaimable)
Bash
$ free -h
total used free shared buff/cache available
Mem: 15Gi 4.2Gi 1.1Gi 312Mi 9.8Gi 10Gi
Swap: 2.0Gi 128Mi 1.9Gi

A server with 1.1 GiB free but 10 GiB available is healthy. Memory is only a problem when available approaches zero or the system starts swapping heavily.

Detailed Step-by-Step Practical Lab

How to Read Load Average Per CPU Core

Load average is the number of tasks wanting a CPU or waiting on I/O, averaged over 1, 5 and 15 minutes. Compare it with the number of cores: a load equal to the core count means the machine is fully used, and sustained load above it means work is queuing.

Bash
uptime
# 10:23:45 up 15 days, load average: 1.23, 0.87, 0.65
# Core count to compare against
nproc
# On a 4 core server: 1.00 = 25% busy, 4.00 = fully busy, 8.00 = 2x oversubscribed
# Per-core CPU breakdown (sysstat package)
mpstat -P ALL 1 3
# CPU and memory pressure at a glance, 5 one-second samples
vmstat 1 5
# procs -----------memory---------- ---swap-- -----io---- -system-- -------cpu-------
# r b swpd free buff cache si so bi bo in cs us sy id wa st
# 2 0 0 1153000 83200 10280000 0 0 0 124 892 1823 12 3 84 1 0

How to read the columns:

  • r is the run queue (tasks waiting for CPU). A value above the core count for several samples means CPU saturation.
  • b is tasks blocked in uninterruptible sleep, normally waiting on I/O.
  • si and so are memory swapped in and out per second. Anything consistently above zero means swapping.
  • us and sy are user and kernel CPU time. id below roughly 5 means the CPU is saturated.
  • wa consistently above roughly 10 points to a disk (or network filesystem) bottleneck.
  • st above zero on a cloud VM means the hypervisor is taking CPU away from you.

Kernels from 4.20 onward also expose Pressure Stall Information, which reports how much time tasks actually stalled. It is the best tie-breaker when the numbers above disagree.

Bash
# "some" = at least one task stalled, "full" = all tasks stalled
cat /proc/pressure/cpu
cat /proc/pressure/memory
cat /proc/pressure/io
# some avg10=0.00 avg60=0.00 avg300=0.00 total=0
How to Check Memory Usage and Swap Pressure on Linux

Check available memory first, then swap activity, then the kernel log for OOM kills. Memory is only under pressure when available is low, swap is being used actively (si and so above zero in vmstat), or the OOM killer has fired.

Bash
# Human readable summary
free -h
# Refresh every 2 seconds
watch -n2 free -h
# Key kernel counters (MemAvailable is the one that matters)
grep -E 'MemTotal|MemFree|MemAvailable|Buffers|^Cached|SwapTotal|SwapFree' /proc/meminfo
# Has the OOM killer fired? (needs root when dmesg_restrict is on)
sudo dmesg -T | grep -i -E 'out of memory|killed process' | tail -10
# Out of memory: Killed process 2341 (node) total-vm:1048576kB, anon-rss:512000kB
# Same question via the journal (kernel messages, persisted across reboots if journald stores them)
journalctl -k -g 'out of memory' --no-pager | tail -10
# Top memory consumers (RSS in KiB)
ps -eo pid,user,rss,comm --sort=-rss | head -10
# Resident memory of every node process
ps -o pid,rss,args -C node
Remember

RSS counts shared pages in every process that maps them, so adding up RSS across processes overstates real usage. Use free for the system total and RSS only to rank suspects.

How to Find Which Process Is Using Disk I/O

Start with iostat -x to find the busy device, then pidstat -d or iotop to find the process. The key signals are await (how long each request takes) and the queue depth, with %util as a supporting signal.

Bash
# Install the tools on Debian or Ubuntu
sudo apt install sysstat iotop
# Extended device statistics, 5 one-second samples (the first sample is the average since boot)
iostat -x 1 5
# Device r/s w/s rkB/s wkB/s r_await w_await aqu-sz %util
# xvda 2.34 15.67 18.70 45.20 1.10 4.23 0.07 12.5
# xvdb 0.12 124.56 0.90 456.20 0.90 45.67 5.69 98.1 <- problem

How to read it (the numbers above are illustrative):

  • r_await and w_await are average request latency in milliseconds. Rising latency under steady load means the device is saturated or failing.
  • aqu-sz is the average queue length. A growing queue means requests arrive faster than the device serves them.
  • %util near 100 means the device was busy almost all the time. It is a reliable saturation signal for a single spinning disk, but NVMe and cloud volumes serve many requests in parallel, so check latency and queue depth as well.
  • Older sysstat versions print a single await column instead of r_await and w_await.
Bash
# Per-process disk throughput, one line per process, 5 samples
pidstat -d 1 5
# Interactive view of only the processes doing I/O right now (needs root)
sudo iotop -oP
# Non-interactive: accumulate I/O for 3 samples, 2 seconds apart
sudo iotop -oPab -n 3 -d 2
# Disk space and inode exhaustion are separate from I/O load
df -h
df -i
# Where did the space go? (-x stays on one filesystem)
sudo du -xh --max-depth=1 /var | sort -rh | head -10
How to Monitor Network Usage and Connections

Check connection counts and socket state first, then interface errors, then bandwidth per interface, process and connection. Most network slowness on a server is connection exhaustion, retransmits or a saturated link, and each has its own command.

Bash
# Listening sockets and the process that owns each one
sudo ss -tulpn
# One-line summary of all sockets
ss -s
# Count TCP connections by state (skip the header line)
ss -tan | awk 'NR>1 {print $1}' | sort | uniq -c | sort -rn
# Established connections to PostgreSQL
ss -t state established '( dport = :5432 or sport = :5432 )'
# Interface counters: look for errors, drops and overruns
ip -s link show eth0
# TCP retransmits since boot (a rising number means loss or congestion)
nstat -az TcpRetransSegs
# Bandwidth per interface, per process and per connection
sudo apt install nload nethogs iftop
nload eth0
sudo nethogs eth0
sudo iftop -i eth0
How to Use dstat or dool for All-in-One Monitoring

dstat prints CPU, disk, network, paging and system stats in one scrolling line per second, so you can see which resource spikes together. Many current distributions have replaced it with dool, a maintained fork that accepts the same flags, or ship it through the pcp package.

Bash
# Install whichever your distribution provides
sudo apt install dstat
# Time, CPU, disk, network, paging, system and memory every second
dstat -tcdngym 1
# Same view with the maintained fork
dool -tcdngym 1
# Example during an I/O spike
# ----system---- ----total-cpu-usage---- -dsk/total- -net/total- ---paging--
# time |usr sys idl wai stl| read writ| recv send| in out
# 14-10 10:41:07| 12 3 20 65 0| 450M 120M|8.2k 123k| 0 0
# ^ 65% wait = severe I/O bottleneck

For history instead of live data, enable the sysstat collector and read it back with sar:

Bash
# CPU, memory and disk history from today
sar -u
sar -r
sar -d -p
How to Run a 5-Minute Production Diagnosis

Put the whole triage in one script so the first minute of every incident is the same command. The script below reports every resource in USE order and skips tools that are not installed.

Bash
#!/usr/bin/env bash
# diagnose: first-pass triage for a slow Linux server
set -u
section() { printf '\n=== %s ===\n' "$1"; }
have() { command -v "$1" >/dev/null 2>&1; }
section "Time and load ($(hostname))"
date
uptime
echo "cores: $(nproc)"
section "CPU, run queue and swap (vmstat)"
vmstat 1 3
section "Pressure stall info"
for r in cpu memory io; do
echo "-- $r"
cat /proc/pressure/$r 2>/dev/null || echo "PSI not available"
done
section "Memory"
free -h
section "Top CPU processes"
ps -eo pid,user,pcpu,pmem,comm --sort=-pcpu | head -6
section "Top memory processes"
ps -eo pid,user,pcpu,pmem,rss,comm --sort=-rss | head -6
section "Disk I/O"
if have iostat; then iostat -x 1 2 | tail -n +4; else echo "iostat missing (apt install sysstat)"; fi
section "Disk space and inodes"
df -hT -x tmpfs -x devtmpfs
df -i -x tmpfs -x devtmpfs
section "TCP connections by state"
ss -tan | awk 'NR>1 {print $1}' | sort | uniq -c | sort -rn
section "Recent OOM events"
dmesg -T 2>/dev/null | grep -i -E 'out of memory|killed process' | tail -5
section "Failed services"
systemctl list-units --state=failed --no-legend
Bash
# Install it system-wide and run it
sudo install -m 0755 diagnose.sh /usr/local/bin/diagnose
sudo diagnose

Production Best Practices & Common Pitfalls

  • Monitor available, not free. Low free memory with a large cache is normal and healthy.
  • Record a baseline. Capture sar or your metrics system on a quiet day, because "load 6" means nothing without knowing what normal looks like.
  • Alert on saturation, not only utilization. Run queue length, I/O latency and PSI catch problems that a CPU percentage hides.
  • Check disk space and inodes together. A full filesystem and an exhausted inode table both show up as "cannot write", but only df -i reveals the second.
  • Remember vmstat and iostat first lines. The first sample is an average since boot, so ignore it when diagnosing a current problem.
  • Collect evidence before restarting. Save the diagnose output first, because a restart often erases the symptom you are chasing.
Common Mistake

Treating a high load average as a CPU problem. Load includes tasks stuck waiting on disk, so confirm with vmstat (wa, b) and iostat -x before adding CPU.

Tip

Compare cat /proc/pressure/io before and after a change. If some avg10 drops, you fixed the real bottleneck, whatever the utilization graphs said.

Symptom First check What to look for
Slow, load high, CPU busy vmstat 1 5 High us or sy, r above core count
Slow, load high, CPU idle vmstat 1 5 High wa and b, then iostat -x
Out of memory errors free -h available near zero, OOM entries in dmesg
Sudden slowness on a VM vmstat 1 5 Non-zero st (noisy neighbour)
App cannot write files df -h Filesystem at 100%
App cannot create files df -i Inodes at 100%
Many timeouts ss -s Huge counts in SYN-RECV, TIME-WAIT or CLOSE-WAIT

Quick Reference & Troubleshooting Commands

Task Command
Load average uptime
CPU breakdown vmstat 1 5
Per-core CPU mpstat -P ALL 1 3
Memory summary free -h
Pressure stall info cat /proc/pressure/io
Disk device stats iostat -x 1 3
Per-process disk I/O pidstat -d 1 5
Live I/O by process sudo iotop -oP
Disk space and inodes df -h and df -i
Open ports and owners sudo ss -tulpn
Socket summary ss -s
Interface errors ip -s link show eth0
All-in-one live view dstat -tcdngym 1
OOM history journalctl -k -g 'out of memory'

Resources

Explore More in Linux Process and System Management

All 6 Topics

Frequently Asked Questions

Is Monitoring Linux CPU, Memory, Disk and Network free to learn on DevOps Network?

Yes - this topic, like everything on DevOps Network, is 100% free with no paywall or sign-up gate.

What does the Monitoring Linux CPU, Memory, Disk and Network topic cover?

Diagnose CPU, memory, disk I/O and network bottlenecks on production Linux servers with vmstat, iostat, free, iotop, ss and PSI.

Found a mistake, an outdated step or a broken link?