Using htop and iotop on Linux VPS (w/ Examples)

Using htop and iotop on Linux VPS (with Examples)

Using htop and iotop on Linux VPS (with Examples) blog

Sometimes, you may notice your server running slowly, but you can’t determine what’s wrong. Luckily, you can quickly diagnose and manage situations using htop and iotop Linux VPS.

This guide explains how to use these remote monitoring tools to check high CPU usage and disk activity. It also teaches you how to manage system resources for a stable server.

Tools like htop and iotop help you monitor CPU usage and disk activity in real time. The comparison table below highlights VPS hosting providers that deliver consistent performance under load, making monitoring results more meaningful. Explore our recommended VPS hosting options.

Linux VPS Hosting Providers With Stable CPU and Disk I O Performance

ProviderUser RatingRecommended For 
Kamatera Logo4.8ScalabilityVisit Kamatera
4.6AffordabilityVisit Hostinger
4.7DevelopersVisit IONOS

Takeaways
  • htop provides color-coded, interactive CPU and RAM monitoring.
  • iotop provides tracking for processes causing disk I/O bottlenecks.
  • High load average with low CPU usage means disk activity issues.
  • htop and iotop install easily across most Linux distributions.
  • htop’s interactive commands enable quick process management.
  • Combine both to diagnose performance bottlenecks effectively.
  • Regular baseline monitoring detects anomalies before failures.

Understanding Monitoring Tools for Linux VPS

Before using htop and iotop on Linux VPS hosting, it is crucial to understand them. Let’s quickly explain the importance of these tools.

Why htop is Essential for Real-Time Monitoring

htop is a fast and interactive tool for Linux systems. It serves as a higher alternative to the standard top command. htop offers color-coded visuals, vertical/horizontal scrolling, and mouse interaction.

In addition, htop allows you to monitor CPU and RAM usage in real-time. Plus, it gives you visibility for when there are many inbox join medium notifications. htop provides a “right now” view of system health without using complex configuration or setup files.

The Role of iotop in Tracking Disk Activity

iotop specifically identifies processes affecting disk I/O (Input/Output). It reveals hidden performance bottlenecks by displaying read/write rates per process.

iotop identifies heavy logging and backup operations that are causing system latency. Beyond this, iotop needs sudo privileges to access kernel-level disk counters.

Importance for the DevOps Engineer

These tools enable fast debugging. That is, SSH in, run htop/iotop, find the bottleneck, and resolve it.

Unlike parsing log files or waiting for historical data accumulation, iotop’s workflow saves time. DevOps engineers can always detect issues in their early stages.

How to Install htop and iotop on Your Linux System

You can install htop and iotop on most Linux distributions.

1. Installation on Debian and Ubuntu

Installing iotop on Ubuntu.

The apt package manager makes command-line execution simpler.

Run sudo apt-get update && sudo apt-get install htop for htop installation. Run sudo apt-get install iotop for iotop.

Next, type htop or sudo iotop in your terminal to launch. Note that iotop requires root access to display valuable data.

2. Installation on CentOS, AlmaLinux, and Rocky Linux

Use yum or dnf for package management on these distributions. Depending on your version, run sudo yum install htop or sudo dnf install htop for htop.

For iotop, run yum install iotop or dnf install iotop. Enable the EPEL repository with sudo yum install epel-release to find packages.

3. Installation on Fedora and Arch Linux

Fedora users should run sudo dnf install htop and sudo dnf install iotop. Arch Linux users utilize pacman: sudo pacman -S htop and sudo pacman -S iotop.

Note that iotop needs direct kernel access to run in toolbox containers.

4. Permissions and Sudo Requirements

htop needs root access to stop other processes run by other users. iotop requires superuser (sudo) privileges to access kernel-level disk counters. Always verify that you are using the correct instance to run these interactive commands.

Navigating the htop Interface for Maximum Visibility

Let’s show you how to use the htop tool for system monitoring.

Understanding CPU Usage and Color Codes

The htop interface on Ubuntu.

You will see bars for CPU cores in the top section. A multi-core system will have vertical stacks of horizontal bars.

Different colors mean:

  • Green: User processes
  • Red: System processes
  • Blue: Nice priority tasks
  • Yellow/Orange: IOwait

These colors are a quick glance at resource distribution.

Red bars mean heavy interface or high kernel/system usage. Short spikes between 90% and 100% are normal for intensive operations. Consistent high usage indicates saturation.

Monitoring Memory Usage and Swap

Bars show Total versus Used Memory (RAM) and Swap usage. The memory bar shows the amount of RAM used. Continuous growth with high Swap-In/Out rates means RAM shortage. High swap usage often causes sluggishness.

Interpreting Load Averages

Metrics show the 1-, 5-, and 15-minute load averages. These are the average number of processes waiting for CPU time.

You must investigate a 5-minute load average above your vCPU count times 1.0. A high load and low CPU usage are likely due to disk activity (IOwait). Processes are not consuming CPU cycles; they are waiting for disk operations.

Namecheap

Get Your Domain and All You Need to Launch you Online business
Visit Site Coupons6

The Process List and Sorting Columns

The main view shows:

  • PID (process ID)
  • USER
  • CPU%
  • MEM%
  • TIME
  • COMMAND

This comprehensive guide to running processes explains process management.

You can scroll the interface vertically and horizontally to see full commands. The default display affects long commands.

You can also resize columns with the mouse or arrow keys. Use Setup (F2) to add columns like RCHAR (bytes read) and WCHAR (bytes written).

Adding columns on htop.

Using htop Interactive Commands to Manage Processes

Use the following commands to manage processes on htop.

1. Sorting Processes (F6)

Arrange the process list by specific metrics with F6. A menu shows sort options. When diagnosing high CPU usage:

  • CPU% identifies processes that use the most processor power.
  • MEM% identifies memory hogs or leaks.
  • TIME shows processes stuck in an endless loop.

2. Searching and Filtering (F3/F4)

F3 (Search) identifies processes matching a specific name. F4 (Filter) hides all processes that don’t match the filter.

3. Killing or Renicing Processes (F9/F7/F8)

F9 (Kill) signals to stop a selected process. Select SIGTERM (graceful) or SIGKILL (forceful).

F7/F8 (Nice) increases or decreases process priority. Higher priority indicates lower nice values.

Set a heavy backup job as low priority processes to contain more critical tasks.

4. Using Tree View for Parent-Child Relationships (F5)

Press F5 to toggle Tree View like the pstree program. This shows which process created another. This helps to trace the leading cause of a process group issue.

Diagnosing High CPU Usage and Memory Issues with htop Examples

We’ve provided examples to help you diagnose with htop.

Scenario 1: Identifying CPU Bottlenecks (SQL Queries)

htop interface sorted by CPU %.

A sluggish website and htop displays one core at 100%. Sort by CPU%, and mysqld or postgres are the causes.

A single heavy SQL query or a missing database index is often the root cause. A poorly optimized query can take up an entire CPU core.

Check database logs or query cache settings. Use EXPLAIN on suspect queries to find performance bottlenecks.

Scenario 2: Detecting Memory Leaks in PHP-FPM

The swap bar rises, and your system is slow, but the CPU is normal. Use MEM% to sort and check large Resident (RES) footprints for php-fpm.

Possible causes include too many workers, memory leaks in the code, or an inadequate OPcache. Each PHP worker uses RAM, and leaks compound over time.

Modify pm.max_children in your PHP-FPM setup. You can also restart the service to free RAM.

Scenario 3: Investigating High Load Average

You have a 5.0 load average on a 2 vCPU server. Check the “IOwait” color in CPU bars. It often looks gray or red.

Switch to iotop if CPU usage is low, but load is high. The CPU is idle. This happens when importing a database or writing log files heavily.

Analyzing Disk I/O with iotop on Linux VPS

Now, let’s review disk I/O with iotop.

Understanding iotop Columns: Read, Write, and IO%

DISK READ/WRITE displays ongoing network throughput per process in KB/s or MB/s. This shows which program is using the disk.

IO% means the percentage of time spent waiting for disk I/O. The whole VPS often freezes with high IO%.

SWAPIN% shows time spent reading from swap. Your system is thrashing between RAM and disk when the number is high.

iotop's interface.

Using Command Line Flags for Better Insights (-o, -P, -a)

  • -o (Only) declutters the output by showing only processes doing I/O.
  • -P (Processes) shows only processes to prevent multi-threaded programs from creating several entries.
  • -a (Accumulated) shows total data read/written since iotop began.

The command sudo iotop -oPa ensures maximum clarity by combining the three flags.

Accumulating Stats to Find Long-Term Resource Hogs

Accumulate data by running sudo iotop -a. Let it run for an hour to catch the periodically bursting script. Intermittent disk spikes often result from cron jobs or scheduled tasks. This method identifies processes you can’t see with quick checks.

Build Your App Now with Hostinger Horizons
Turn your idea into a powerful app in minutes with Hostinger Horizons. No coding, no hassle, just AI-powered building that brings your vision to life.
Visit Hostinger

Troubleshooting Disk Activity with iotop Examples

Let’s show you examples to fix disk activity using iotop.

Scenario 1: Database Imports Stalling the System

The system is running a large SQL import. iotop displays mysqld with high WRITE speed and 99% IO%.

The web server times out while waiting for the database. Monopolizing imports prevents other processes from accessing the disk. 

Use ionice to throttle the import or upgrade to faster storage, such as NVMe. Also, schedule imports during off-peak hours.

Scenario 2: Heavy Log Writes and Rotation

Disk space fills up quickly, and system performance reduces. iotop displays rsyslogd or a web server app at the top. This happens due to leaving debug mode on or log rotation compressing huge files.

In your application configuration, disable verbose logging. Also, reduce local disk usage by reducing remote log aggregation.

Scenario 3: Backup Processes (Tar/Rsync)

Your server slows down at 2 AM. iotop shows tar or rsync dominating the READ/WRITE columns. The backup job competes with production workloads because it runs with the default priority.

Lower the disk priority of the backup script with ionice. Run it in the idle class by putting ionice -c 3 before your backup command.

Comparison: htop vs. iotop for System Monitoring

The table below compares using htop and iotop Linux VPS:

Aspecthtopiotop
Primary FocusCPU, RAM, Swap, Load AverageDisk I/O (Read/Write/IO%)
InteractivityHigh (Kill, Renice, Sort, Tree)Low (Fixed sort, no kill)
Install Exampleapt install htop (Debian)apt install iotop
Key MetricsCPU%, MEM%, Uptime, TasksDisk Read/Write speeds, IO Wait%
Flags/SetupF2 Setup, F6 Sort-oPa (Active/Accumulated)
Best ForGeneral slowness, stuck processesDatabase lag, backup issues, slow disk

Optimizing Your Digital Presence on a High-Performance VPS

The foundation of your online journey starts with creating a solid website or store. User-friendly website builders like Hostinger and IONOS are top-tier choices to help you. They often have the best web hosting plans to scale your VPS setup.

Hostinger's website homepage_blue

You can also use Fiverr or Upwork to hire a freelance DevOps expert for custom development work. Combine this with reliable web hosting providers to get excellent performance.

In addition, you should migrate to a VPS or dedicated server when you keep hitting resource limits. Know whether a managed or unmanaged VPS suits your skill level and needs.

Finally, you can develop the right strategy to improve performance by understanding the uses of a VPS.

VPS
Cheap VPS
best option

Conclusion

Change your management game by using htop and iotop Linux VPS. These powerful tools provide a real-time view of system performance. You should be able to maintain long-term health by monitoring your Linux server.

Next Steps: What Now?

Follow these steps to use htop and iotop on Linux VPS:

  • Install htop and iotop on your Linux system.
  • Launch and setup permissions for both tools.
  • Monitor CPU and memory usage on htop.
  • Analyze disk activity with iotop.
  • Troubleshoot bottlenecks with the proper commands.

Frequently Asked Questions

What is the difference between top and htop?

The difference between htop and top is in their output. htop offers color-coded output and interactive commands. In comparison, the top command provides simple text output with limited interaction.

Why does iotop require sudo privileges?

iotop requires sudo privileges to access restricted kernel-level disk I/O statistics. This enables the program to read the data from /proc and kernel interfaces for accurate results.

How do I install iotop on Ubuntu?

Install iotop by running sudo apt-get update && sudo apt-get install iotop. Next, launch it with sudo iotop to start monitoring in batch mode or real time view.

What does high IOwait mean in htop?

High IOwait means your CPU is idle. This happens because processes are waiting for disk operations to complete.

Can I use htop to kill processes?

Yes, you can use htop to kill processes once you have root access. Use the arrow keys to choose a process, then press F9 to send kill signals. Select SIGTERM for graceful shutdown or SIGKILL for instant termination.

How do I monitor network usage with these tools?

Use tools like iftop, nethogs, or nload to monitor network usage. These trace network activity per process or interface to support htop and iotop.

What is a good load average for my VPS?

A good load average is below your vCPU count. For a 2-core VPS, sustained load averages above 2.0 mean overload.

Handling Webhook Traffic at Scale in n8n

N8n webhook scaling breaks down faster than you'd expect. When request volumes spike, concurrency pressure builds, and executions start backin...
8 min read
Christi Gorbett
Christi Gorbett
Content Marketing Specialist

Running n8n in Production - Stability Checklist

Getting workflows live is only half the battle. n8n production stability is what keeps your automations running reliably when it actually matt...
8 min read
Christi Gorbett
Christi Gorbett
Content Marketing Specialist

CI/CD Pipelines for Deploying n8n Updates

Manually pushing n8n updates across environments is error-prone and time-consuming. A well-configured n8n CI/CD pipeline changes that. It auto...
8 min read
Christi Gorbett
Christi Gorbett
Content Marketing Specialist

Running n8n with Docker Compose vs Bare-Metal VPS

Choosing between n8n Docker Compose vs bare metal VPS comes down to more than personal preference. It affects how you deploy, scale, and maint...
8 min read
Christi Gorbett
Christi Gorbett
Content Marketing Specialist
Click to go to the top of the page
Go To Top
HostAdvice.com provides professional web hosting reviews fully independent of any other entity. Our reviews are unbiased, honest, and apply the same evaluation standards to all those reviewed. While monetary compensation is received from a few of the companies listed on this site, compensation of services and products have no influence on the direction or conclusions of our reviews. Nor does the compensation influence our rankings for certain host companies. This compensation covers account purchasing costs, testing costs and royalties paid to reviewers.