BLOG POSTS
    MangoHost Blog / Track Disk I/O in Linux with iotop โ€“ Step-by-Step Guide
Track Disk I/O in Linux with iotop โ€“ Step-by-Step Guide

Track Disk I/O in Linux with iotop โ€“ Step-by-Step Guide

Why Should You Care About Disk I/O on Your Linux Server?

Ever had your shiny new VPS or dedicated server suddenly slow to a crawl? Maybe your Docker containers are lagging, or your cloud-hosted app is timing out for no obvious reason. Nine times out of ten, if your CPU and RAM look fine, the culprit is disk I/O (Input/Output). In plain English: something is hammering your disk, and you need to find out what, fast.

Whether youโ€™re running a personal blog, a busy e-commerce site, or a cluster of containers, disk I/O bottlenecks can turn your server into a potato. Thatโ€™s why tracking disk I/O is not just for sysadminsโ€”itโ€™s for anyone who wants their hosting to run smoothly, whether itโ€™s on a VPS, dedicated server, or even a Raspberry Pi.

Whatโ€™s the Problem? Why Is Disk I/O So Tricky?

  • Disk I/O is often the silent killer of performance. Itโ€™s not obvious like high CPU or RAM usage.
  • Traditional tools (like top or htop) donโ€™t show you which process is hogging the disk.
  • Cloud, Docker, and VPS environments add layers of abstraction, making it even harder to spot the real troublemaker.

So, how do you actually see which process is causing all the disk thrashing? Enter iotop.

What Is iotop and How Does It Work?

is like top, but for disk I/O. It shows you, in real time, which processes are reading from or writing to your disks, and how much. Itโ€™s a must-have for anyone running Linux servers, especially in hosting environments.

Under the hood, iotop uses the Linux kernelโ€™s taskstats and cgroups interfaces to pull per-process I/O stats. Itโ€™s lightweight, doesnโ€™t require a reboot, and works on almost any modern Linux distro.

Three Main Questions About iotop

  1. How does iotop actually track disk I/O?
  2. How do I set it up quickly and start using it?
  3. How does it compare to other tools, and what are the gotchas?

How Does iotop Track Disk I/O?

Letโ€™s geek out for a sec. iotop taps into the /proc filesystem, specifically /proc/[pid]/io, to read I/O stats for each process. It also uses taskstats via netlink sockets to get real-time updates. This means:

  • It shows actual disk I/O (not just cache or memory activity).
  • It can show both read and write rates, per process or per thread.
  • It works even if youโ€™re running in a container (with some caveats).

The UI is ncurses-based, so it runs in any terminal. You get columns for PID, user, disk read/write rates, swap in/out, and the command line of the process.

How to Install and Run iotop (Quick and Dirty)

Step 1: Install iotop

On most distros, itโ€™s a one-liner:

  • Debian/Ubuntu:
sudo apt update
sudo apt install iotop
  • CentOS/RHEL/Fedora:
sudo yum install iotop
# or
sudo dnf install iotop
  • Arch Linux:
sudo pacman -S iotop

If youโ€™re in a minimal Docker container, you might need to install Python and ncurses first, since iotop is a Python script.

Step 2: Run iotop

Youโ€™ll need root privileges to see all processes:

sudo iotop

Youโ€™ll see a live, updating table of disk I/O by process. By default, it updates every second.

Step 3: Useful iotop Options

  • -o: Only show processes actually doing I/O (super useful!)
  • -a: Accumulate I/O over time (good for catching intermittent spikes)
  • -d 2: Change the update interval to 2 seconds
  • -b: Batch mode (for scripting/logging, outputs plain text)

Example:

sudo iotop -o -d 2

Practical Examples and Real-World Cases

Positive Case: Finding a Rogue Backup Script

You notice your site is slow every night at 2am. You run sudo iotop -o and see a tar process writing hundreds of MB/s. Turns out, your backup script is running too aggressively. Solution: throttle it with ionice or run it at a quieter time.

Negative Case: Docker Container Hides the Culprit

Youโ€™re running a bunch of containers, and iotop shows dockerd or containerd as the top I/O user. But which container? Youโ€™ll need to dig deeper with docker stats or use cgroup-aware tools. iotop is great, but it canโ€™t always see inside containers.

Comparison Table: iotop vs. Other Disk I/O Tools

Tool Shows Per-Process I/O? Real-Time? Easy to Use? Works in Docker? Best For
iotop Yes Yes Yes Partial* Quick diagnosis
iostat No Yes Yes Yes Device-level stats
dstat No Yes Yes Yes Overview/all resources
glances Yes (summary) Yes Yes Yes All-in-one monitoring
atop Yes Yes Medium Partial* Detailed logging

*Docker support depends on how you run the tool and kernel version. For deep container stats, consider cAdvisor or Prometheus/Grafana.

Beginner Mistakes and Common Myths

  • Myth: “If iotop shows 0 I/O, my disk is fine.”
    Reality: The problem may be bursty, or in a process youโ€™re not seeing. Try -a to accumulate stats.
  • Mistake: Running iotop without sudo and missing most processes.
  • Myth: “High disk I/O always means a problem.”
    Reality: Some apps (like databases, video processing) are naturally I/O-heavy. Look for unexpected I/O.
  • Mistake: Not checking iotop when troubleshooting slowdowns. Always check disk I/O before blaming the network or CPU!

Similar Tools and When to Use Them

  • iostat: For device-level stats (e.g., which disk is busy, not which process).
  • dstat: For a quick overview of all system resources.
  • atop: For logging and historical analysis (but more complex).
  • glances: For a dashboard of everything (CPU, RAM, disk, network).
  • pidstat -d: For per-process I/O in a scriptable format.

Official links:

Interesting Facts and Non-Standard Usage

  • Scriptable Monitoring: Use iotop -b -n 10 -o to log top I/O users every second for 10 seconds. Great for cron jobs or automated alerts.
  • Combine with ionice: Once you find the I/O hog, you can lower its priority with ionice -c3 -p <PID>.
  • Docker Entrypoint: Run iotop inside a container to see I/O from that containerโ€™s perspective.
  • Cloud Automation: Use iotop in cloud-init scripts to baseline disk usage after provisioning a new server.

Automation and Scripting: New Opportunities

Once you know how to use iotop, you can:

  • Automate detection of I/O spikes and send alerts (integrate with mail or Slack bots).
  • Log I/O usage over time for capacity planning (e.g., iotop -b -n 60 -d 1 > io.log).
  • Trigger scripts to throttle or kill runaway processes automatically.
  • Integrate with monitoring stacks (Prometheus, Zabbix, etc.) for full-stack visibility.

Conclusion: Why iotop Is a Must-Have for Anyone Running Linux Hosting

If youโ€™re running any kind of Linux hostingโ€”cloud, VPS, Docker, or bare metalโ€”disk I/O is the silent performance killer you canโ€™t afford to ignore. iotop gives you instant, actionable insight into which processes are hammering your disks, so you can fix problems before your users even notice.

  • Itโ€™s fast, lightweight, and easy to use.
  • It works on almost any Linux system.
  • It saves you hours of guesswork when troubleshooting slowdowns.

So, next time your server feels sluggish, donโ€™t just stare at topโ€”fire up iotop and see whatโ€™s really going on under the hood. Your future self (and your users) will thank you!

Need a playground to try this out? Grab a VPS or dedicated server and start experimenting. Happy hacking!



This article incorporates information and material from various online sources. We acknowledge and appreciate the work of all original authors, publishers, and websites. While every effort has been made to appropriately credit the source material, any unintentional oversight or omission does not constitute a copyright infringement. All trademarks, logos, and images mentioned are the property of their respective owners. If you believe that any content used in this article infringes upon your copyright, please contact us immediately for review and prompt action.

This article is intended for informational and educational purposes only and does not infringe on the rights of the copyright owners. If any copyrighted material has been used without proper credit or in violation of copyright laws, it is unintentional and we will rectify it promptly upon notification. Please note that the republishing, redistribution, or reproduction of part or all of the contents in any form is prohibited without express written permission from the author and website owner. For permissions or further inquiries, please contact us.

Leave a reply

Your email address will not be published. Required fields are marked