Back to Blog
LinuxJuly 6, 20265 min read

Linux Performance Monitoring: A Practical Guide to htop & iostat

Linux performance monitoring doesn't have to be complex. Learn how to use htop and iostat to track CPU, memory, and disk usage on your servers today.

linuxperformancesysadminhtopiostatmonitoringcli

When your server starts lagging, the first thing you need is a clear picture of what’s happening under the hood. I’ve spent countless hours in an SSH session trying to figure out why a database query is hanging or why a process is eating up all the RAM, and I've learned that top just isn't enough.

For effective linux performance monitoring, you need tools that give you immediate, readable feedback. That’s where htop and iostat come in. They are the bread and butter of daily server resource tracking, allowing you to spot anomalies before they turn into full-blown outages.

Getting Started with htop

If you are still using the default top utility, do yourself a favor and install htop. It’s an interactive, color-coded process viewer that makes reading system state significantly easier.

On Debian or Ubuntu systems, just run: sudo apt install htop

Once it’s running, you’ll see the CPU cores, memory usage, and load average at the top. The real power of this htop tutorial lies in the interactive keys. You don't have to guess; you can act:

  • F3 (Search): Quickly find a specific process by name.
  • F4 (Filter): Hide everything except the processes matching your string.
  • F6 (Sort): Change the sort order by CPU usage, memory, or PID.
  • F9 (Kill): Send a signal to a process without having to remember the kill -9 syntax.

I usually sort by memory (M) when I suspect a memory leak. It’s saved me from several OOM (Out of Memory) kills in production environments.

Analyzing Disk Bottlenecks with iostat

While htop gives you the big picture, it often misses the silent killer: I/O wait. If your CPU is idling but your system feels sluggish, your disk is likely the culprit. This is where iostat disk usage monitoring becomes critical.

iostat is part of the sysstat package. Install it with: sudo apt install sysstat

To get a real-time view of disk activity, run iostat -xz 1. The -x flag gives you extended statistics, and the 1 tells it to refresh every second.

MetricWhat it tells you
r/s & w/sReads and writes per second.
awaitAverage time for I/O requests to be served.
%utilThe percentage of time the disk was busy.

If %util is consistently near 100% and await is high, your disk is saturated. I’ve seen cases where a poorly indexed database query caused await times to spike to over 500ms, effectively freezing the entire application. If you're building out custom monitoring solutions to visualize this data, React & Next.js Dashboard / Admin UI Development can help you turn these raw metrics into actionable graphs.

Combining Metrics for Better Insights

You shouldn't look at these tools in isolation. Linux system metrics are interconnected. A high load average in htop might be caused by high CPU usage, or it might be caused by "D" state processes (uninterruptible sleep) waiting on disk I/O.

When I’m debugging a slow server, my workflow looks like this:

  1. Run htop to check overall CPU/RAM.
  2. Check the "Load Average" at the top right. If it's higher than the number of CPU cores, the system is over-provisioned.
  3. Switch to iostat -xz 1 to see if the disk is struggling to keep up with the queue.

If you are dealing with more complex bottlenecks, remember that modern observability often requires more than just local tools. For instance, if you're tracking network-level latency, looking into eBPF-based socket monitoring: Tracking latency in Docker containers can provide deeper insights than standard system utilities.

A Quick Note on "Wrong Turns"

Early in my career, I spent an entire afternoon trying to debug a "slow" server by manually parsing dmesg logs. I was looking for hardware errors, but the actual issue was a rogue backup script running at the wrong time. Since then, I’ve learned to always look at the process list in htop first. Don't overcomplicate your troubleshooting before checking the obvious, high-level metrics.

Also, keep in mind that iostat is a snapshot. If you have intermittent spikes, you might miss them. For long-term trends, you eventually need to move from manual tools to automated logging.

FAQ: Linux Performance Monitoring

Q: Is htop accurate for memory tracking? A: htop shows "used" memory, but remember that Linux uses free RAM as a cache. If you see high memory usage, check the "buff/cache" columns; it's usually not a problem unless the application itself is leaking.

Q: How do I know if my disk is dying? A: Check iostat for extremely high await times that persist even when the system load is low. Also, use smartctl (from the smartmontools package) to check the health status of your physical drives.

Q: Can I use these tools in a Docker container? A: Usually, no. Most containers don't have the necessary permissions to access host-level hardware stats. For containerized environments, you’re better off using specialized tools like Linux Docker Inotify Auditing: Real-Time File Monitoring with Systemd or native container metrics.

I’m still refining my own stack for monitoring, and honestly, the best tool is the one you actually remember to open when things go sideways. Don't worry about setting up a massive Prometheus/Grafana stack on day one; start by getting comfortable with htop and iostat on the command line. You'll catch 90% of your production issues just by watching these two tools.

Similar Posts