iotop Command: Tutorial & Examples

Analyzing disk I/O

The iotop command is a powerful tool for monitoring and analyzing disk I/O (Input/Output) activity on a Linux server. It provides real-time information about the processes that are reading from or writing to the disk, allowing you to identify which processes are causing high disk usage and potentially impacting system performance.

Why is it important?

Disk I/O is a critical aspect of server performance, as it directly affects the speed and responsiveness of applications and services. By using iotop, you can gain insights into the disk usage patterns of different processes, helping you identify bottlenecks, troubleshoot performance issues, and optimize your system's disk utilization.

Typical Use Cases

  • Identifying processes that are causing high disk I/O and potentially impacting system performance.
  • Monitoring disk activity in real-time to detect any abnormal behavior or unexpected spikes in disk usage.
  • Troubleshooting slow disk performance or identifying processes that are causing excessive disk thrashing.
  • Optimizing disk utilization by identifying processes that are reading or writing large amounts of data.

Installation

Before using iotop, you need to ensure that it is installed on your system. On most Linux distributions, you can install it using the package manager. For example, on Ubuntu or Debian, you can use the following command:

sudo apt-get install iotop

Basic Usage

To start using iotop, open a terminal and run the following command:

sudo iotop

By default, iotop displays a live view of the processes that are currently performing disk I/O, sorted by the amount of I/O they are generating. The output includes information such as the process ID (PID), the user running the process, the amount of disk read and write in kilobytes per second (kB/s), and the total I/O percentage.

Here is an example of the output:

Total DISK READ: 0.00 B/s | Total DISK WRITE: 0.00 B/s
TID PRIO USER DISK READ DISK WRITE SWAPIN IO>    COMMAND
123 be/4 root 0.00 B/s 0.00 B/s 0.00 % 0.00 % systemd
456 be/4 user 0.00 B/s 0.00 B/s 0.00 % 0.00 % apache2
789 be/4 user 0.00 B/s 0.00 B/s 0.00 % 0.00 % mysqld

The output is updated in real-time, allowing you to monitor the disk I/O activity as it happens.

Sorting the Output

By default, iotop sorts the processes based on the amount of I/O they generate. However, you can change the sorting order by pressing the following keys:

  • o: Sort by disk read (descending order)
  • p: Sort by disk write (descending order)
  • a: Sort by accumulated I/O (descending order)
  • u: Sort by process ID (ascending order)
  • P: Sort by process name (ascending order)

For example, to sort the output by disk write in descending order, press p.

Filtering the Output

If you want to focus on specific processes or users, you can use the -u and -p options to filter the output.

To display only the processes owned by a specific user, use the -u option followed by the username. For example, to show only the processes owned by the user "john":

sudo iotop -u john

To display only the processes with a specific process ID, use the -p option followed by the process ID. For example, to show only the process with ID 123:

sudo iotop -p 123

Additional Options

iotop provides several additional options that allow you to customize its behavior:

  • -o: Only show processes that are doing I/O.
  • -b: Batch mode. Print the output once and exit.
  • -n: Number of iterations before exiting.
  • -d: Delay between iterations in seconds.
  • -k: Display the I/O in kilobytes per second (kB/s) instead of bytes per second (B/s).
  • -q: Quiet mode. Suppress header and summary lines.

For example, to run iotop in batch mode, displaying the output once and then exiting, you can use the following command:

sudo iotop -b

Conclusion

The iotop command is a valuable tool for monitoring and analyzing disk I/O activity on a Linux server. By using iotop, you can gain insights into the processes that are reading from or writing to the disk, helping you identify performance bottlenecks, troubleshoot issues, and optimize your system's disk utilization.

With its real-time monitoring capabilities and customizable options, iotop is an essential command for any Linux server administrator or system troubleshooter.

The text above is licensed under CC BY-SA 4.0 CC BY SA