Linux and servers · Intermediate · 16 min
Find why a Linux server is slow with top, vmstat and iostat
By Padding · Updated 18 Nov 2026
Ubuntu 26.04.1 LTS · sysstat 12.7.7 · stress-ng 0.20.01
You will run a five-minute triage routine on Ubuntu 26.04 that tells CPU, memory and disk trouble apart with uptime, top, vmstat, iostat and pidstat, and check that sysstat is recording history for sar the next time someone says the server was slow.
On this page
"The server is slow" is a symptom, not a diagnosis. Almost always one of three things has run out: CPU time, memory, or disk throughput. Each leaves a different signature in a few standard tools, and you can tell them apart in about five minutes before you touch anything.
The routine in this tutorial, in order:
uptimeandnproc: is there more work than CPUs?top: which processes, and what is the CPU waiting on?vmstat 1: queued tasks, blocked tasks, swapping.iostat -xz 1: is a disk saturated?pidstat: per-process figures that confirm the culprit.
You will practise on your own server by creating each kind of load with stress-ng, so you see the signature once while you are calm. Then you check that sysstat collection is running so that sar can answer "what was it like at 3 a.m.?" next time.
Every number in the sample output below varies from server to server. Read the samples as "something like", and compare the shape, not the digits.
Step 1 · Install the triage tools
top, vmstat and uptime come with Ubuntu in the procps package. iostat, pidstat and sar are in sysstat. htop is a friendlier top, and stress-ng creates practice load.
sudo apt update
sudo apt install -y sysstat htop stress-ngstress-ng is a load generator. Only run it on a server you are allowed to slow down, never on a busy production machine, and remove it at the end.
Check it worked
Each tool prints its version:
iostat -V
stress-ng --version
vmstat -VYou see something like sysstat version 12.7.7, stress-ng, version 0.20.01 and vmstat from procps-ng 4.0.4.
Step 2 · Compare the load average with the CPU count
Start with two numbers:
uptime
nprocSomething like:
10:42:07 up 12 days, 3:18, 1 user, load average: 3.92, 2.10, 0.84
2The three load averages cover the last 1, 5 and 15 minutes. On Linux, load counts tasks that are running, waiting for a CPU, or stuck in uninterruptible sleep (usually waiting on a disk or network file system). So:
- Load well below
nprocmost of the time means the CPUs are not the bottleneck. - Load steadily above
nprocmeans work is queueing. It could be CPU or disk; the next tools tell you which. - 1-minute much higher than 15-minute, as in the sample, means the problem started recently. The reverse means it is easing.
On a 2-CPU server, a load of 3.92 means roughly two tasks are waiting at any moment.
Check it worked
You can say, in one sentence, whether your server's load is below, near or above its CPU count, and whether it is rising or falling.
Step 3 · Create CPU load and find it with top and pidstat
In your second SSH session, start two CPU-bound workers for one minute:
stress-ng --cpu 2 --timeout 60sBack in the first session, take one snapshot of top, sorted by CPU:
top -b -n 1 -o %CPU | head -n 15-b is batch mode, which prints once and exits instead of redrawing the screen. The summary line near the top is the part to read:
%Cpu(s): 98.6 us, 1.4 sy, 0.0 ni, 0.0 id, 0.0 wa, 0.0 hi, 0.0 si, 0.0 stusandsy: time in your programs and in the kernel. Highuswith the process list topped by one program means that program is busy.id: idle. Near zero means the CPUs are full.wa: iowait, time a CPU sat idle while a disk request was outstanding. Highwapoints at storage, not CPU.st: steal, time the hypervisor gave your virtual CPU to another guest. You only see it on VMs. A steadystabove a few percent means you are not getting the CPU you pay for; the fix is a larger plan, a dedicated-CPU plan or another host, not tuning your app.
Below the summary, the process list shows two stress-ng-cpu workers near 100% each.
For the interactive view, run top (or htop) on its own. Press P to sort by CPU, M to sort by memory, 1 to show each CPU separately, and q to quit.
htoppidstat gives the same answer as a figure per process per second, which is easier to paste into a ticket. -u reports CPU, -C filters by command name, and 1 5 means five one-second samples:
pidstat -u -C stress-ng 1 5If you work over a slow or metered mobile connection, as many people do on prepaid data, prefer the batch commands (top -b -n 1, pidstat ... 1 5) to htop. Full-screen tools redraw constantly over SSH and use far more data than a few lines of text.
Check it worked
The Average: lines from pidstat show each stress-ng-cpu worker with %CPU near 100, and top showed id near 0 with wa near 0. That pairing, busy CPUs and no iowait, is the CPU-bound signature.
Step 4 · Read vmstat while memory is under pressure
vmstat prints one line per interval for the whole system. Run it with no load first:
vmstat 1 5procs -----------memory---------- ---swap-- -----io---- -system-- -------cpu-------
r b swpd free buff cache si so bi bo in cs us sy id wa st gu
0 0 0 1402312 48220 512004 0 0 12 20 110 190 1 1 98 0 0 0
1 0 0 1402060 48220 512010 0 0 0 0 145 230 0 0 100 0 0 0The first line is an average since boot. Ignore it and read the lines after it. The columns that matter in triage:
r: tasks running or waiting for a CPU. Consistently abovenprocmeans CPU queueing.b: tasks blocked in uninterruptible sleep, nearly always waiting on I/O.free,buff,cache: memory in KiB. Lowfreealone is normal, because Linux uses spare memory as cache.siandso: memory swapped in from and out to disk per second. Any steady non-zerosomeans the server is short of memory and is paying for it in disk I/O.us sy id wa st: the same CPU split as intop.
Now, in your second session, hold 300 MiB of memory for a minute. --vm-keep keeps the memory mapped instead of freeing and remapping it:
stress-ng --vm 1 --vm-bytes 300M --vm-keep --timeout 60sWatch vmstat again, and see which process holds the memory with pidstat -r. Add -p ALL: by default pidstat only lists processes that were active during the interval, and a worker that sits on memory it already touched causes no page faults, so it would be left out:
vmstat 1 5
pidstat -r -p ALL -C stress-ng 1 5free drops by about 300 MiB. In pidstat -r, the RSS column (resident memory in KiB) for the stress-ng-vm worker is around 307,000. On a server with plenty of RAM, that is all you see. On a small VPS where 300 MiB pushes it past its RAM, si/so start moving and wa climbs, because memory pages are being written to and read from swap. That is the memory-bound signature: swap activity plus rising iowait, with no single disk-heavy program to blame.
When a process uses more than the server can give it, the kernel's OOM killer ends it. If swpd is 0 and free -h shows no swap, as on many Ubuntu cloud images, you will not see si/so move; memory exhaustion ends in the OOM killer instead. Reading those messages is covered in Find what is using memory and read OOM killer messages.
Check it worked
You saw free fall in the later vmstat lines while the stress run was going, and a stress-ng-vm line in pidstat -r with an RSS in the hundreds of thousands of KiB.
Step 5 · Find a disk bottleneck with iostat
iostat -x prints extended statistics per disk. -z hides disks with no activity, and 1 3 gives three one-second reports. As with vmstat, the first report is since boot.
iostat -xz 1 3In your second session, start a writer that streams 512 MiB of files to disk for a minute:
stress-ng --hdd 1 --hdd-bytes 512M --temp-path /var/tmp --timeout 60sRead iostat and pidstat -d while it runs:
iostat -xz 1 3
pidstat -d 1 3A busy device line looks something like this (trimmed to the columns that matter):
Device r/s w/s rkB/s wkB/s r_await w_await aqu-sz %util
vda 0.00 412.00 0.00 105472.00 0.00 38.40 15.82 99.60r/s,w/s,rkB/s,wkB/s: reads and writes per second, and how much data.r_await,w_await: average milliseconds per read and per write, including time in the queue. Low single digits is healthy for SSD storage. Tens of milliseconds means requests are waiting.aqu-sz: average number of requests queued on the device.%util: share of time the device had at least one request in flight. On a single spinning disk, near 100% means saturated. SSDs, NVMe drives and most cloud volumes serve many requests in parallel, so treat%utilas a hint and trustawaitandaqu-szmore.
pidstat -d lists the processes doing the I/O, with kB_wr/s per process. During an incident this is where you find the backup job, the log-heavy service or the database doing a full scan.
Put it together with what you saw earlier: high wa in top, a non-zero b column in vmstat, high await and aqu-sz in iostat, and one process at the top of pidstat -d. That is the disk-bound signature. Load average rises too, because blocked tasks count towards it, which is why a high load does not always mean the CPU is busy.
Check it worked
During the run, iostat showed a device with w/s and wkB/s well above zero and a higher w_await than before, and pidstat -d showed a stress-ng-hdd line with a large kB_wr/s.
Step 6 · Check that sysstat is collecting history
The tools so far show the server now. Most complaints arrive after the slow period has passed. sysstat records the same figures every ten minutes, and sar reads them back. On Ubuntu 26.04, collection is on by default once the package is installed, and systemd timers do the sampling. Check both rather than assume:
grep ENABLED /etc/default/sysstatsystemctl list-timers 'sysstat*'You should see ENABLED="true", and a timer list with something like sysstat-collect.timer, due within ten minutes, and sysstat-summary.timer, due shortly after midnight.
If it prints ENABLED="false", someone has turned collection off on this server. Switch it back on with the package's debconf setting, which rewrites /etc/default/sysstat for you, then start the service and timers:
echo 'sysstat sysstat/enable boolean true' | sudo debconf-set-selections
sudo dpkg-reconfigure -f noninteractive sysstat
grep ENABLED /etc/default/sysstatsudo systemctl enable --now sysstat
systemctl list-timers 'sysstat*'After the first two samples have been written (about twenty minutes), read today's CPU and load history:
sar -u
sar -qsar -u prints the CPU split per interval, with %iowait and %steal columns. sar -q prints run queue length and the load averages. sar -r gives memory and sar -b gives I/O rates. To look at yesterday, or a time window, point it at the day's file and give start and end times:
sar -u -f /var/log/sysstat/sa$(date -d yesterday +%d)
sar -q -s 02:00:00 -e 04:00:00The files are small, a few hundred kilobytes a day. How many days are kept is set by HISTORY in /etc/sysstat/sysstat.
Remove the practice tool, and keep sysstat running:
sudo apt remove -y stress-ngCheck it worked
sar -u prints at least one row of figures under a header with %user, %iowait and %steal, ending in an Average: line. If it says it cannot open the file, collection has not run yet; wait ten minutes and try again.
Next steps
- Keep long-term graphs and alerts instead of reading
sarby hand: Monitor a server with Prometheus and Node Exporter. - Deal with the process you found, from a polite stop to a forced kill: Manage processes with ps, kill and signals.
- When memory is the problem: Find what is using memory and read OOM killer messages.
- When the disk is full rather than slow: Find and free up disk space on a Linux server.
Related tutorials
- Write safer Bash scripts with strict mode and trapsYou will build a small Bash release script that stops on the first error, says which line failed, survives file names with spaces and always removes its temporary files.
- Write least-privilege sudo rules with visudoYou will replace blanket sudo access with checked rule files in /etc/sudoers.d that let two operators restart one service and edit one file, give an automation account a password-free command list, and audit what every account can run.
- Upgrade a server from Ubuntu 24.04 LTS to 26.04 LTSYou will take a backed-up Ubuntu 24.04 server through do-release-upgrade to 26.04 LTS over SSH with a fallback login, then confirm services, repositories and language runtimes work on the new release.
Need this done for you?
Padding does this work for growing companies, from the first diagnosis to a system that keeps working.
Get new tutorials