iotop is a Linux utility that helps monitor disk I/O usage by processes in real-time, making it easier to identify and troubleshoot disk-heavy processes. This article covers how to install iotop on an Ubuntu VPS and demonstrates how to use it effectively to monitor I/O performance.
12 min
Edited:12-10-2024
Disk I/O (Input/Output) is a crucial factor in server performance, particularly for applications that involve significant disk read/write operations, such as databases or file servers. High I/O usage can slow down the entire server, leading to bottlenecks in performance. This is where iotop comes in handy. iotop is a Linux command-line utility that displays real-time disk I/O usage by processes on your system. It's similar to the top command, but instead of showing CPU and memory usage, it focuses on disk I/O operations. This makes it a valuable tool for diagnosing disk-related performance issues and tracking down which processes are causing excessive disk I/O.
1 - Real-Time Disk I/O Monitoring: Provides real-time information about processes performing disk reads and writes.
2 - Process-Specific Data: Shows per-process disk I/O usage, helping to isolate which processes are causing high I/O loads.
3 - Sorting and Filtering: Allows you to filter or sort processes based on their I/O usage.
4 - Threshold Control: Displays processes that exceed a minimum disk I/O threshold to avoid cluttering the screen with idle processes.
5 - Similar to top: Offers an intuitive and familiar interface for users accustomed to system monitoring tools like top or htop.
Installing iotop on Ubuntu is straightforward. It is available in the default package repositories, so you can install it using the apt package manager. Here's how you can install it on your Ubuntu VPS.
Before installing any new software, ensure your system is up to date:
1. sudo apt update
2. sudo apt upgrade
Install iotop using the following command:
1. sudo apt install iotop
This will download and install iotop along with its dependencies.
After installation, you can verify that iotop was installed successfully by checking its version:
1. iotop --version
You should see the installed version number, indicating that iotop is ready for use.
Now that you have iotop installed, let’s go through how to use it to monitor disk I/O on your VPS.
To start monitoring disk I/O, simply run the iotop command:
1. sudo iotop
You’ll need to run iotop with sudo because monitoring disk I/O requires elevated privileges. Once launched, you’ll see a real-time list of processes with their corresponding disk I/O usage. The main columns to focus on are:
PID: Process ID.
USER: The user that owns the process.
DISK READ: Amount of data read from disk by the process.
DISK WRITE: Amount of data written to disk by the process.
SWAPIN: Swap usage as a percentage of time spent on swapping pages in memory.
IO: Percentage of time the process has spent waiting on I/O (disk-related).
COMMAND: The command or program that started the process.
iotop, like top, allows you to sort processes based on disk I/O usage. By default, processes are sorted by the total disk I/O (IO column), but you can change the sort order using interactive commands:
Arrow Keys: Use the arrow keys to navigate the list of processes.
r: Press r to toggle sorting by I/O rates (disk read/write).
p: Press p to toggle the display between processes and threads.
If you want to monitor disk I/O activity for specific processes, use the following option:
1. sudo iotop -p [PID]
Replace [PID] with the actual process ID you want to monitor. For example, if you want to track the disk I/O usage of a MySQL process with PID 1234, the command would be:
1. sudo iotop -p 1234
This limits the display to only the specified process, which can help you focus on problematic applications or services.
By default, iotop displays all processes, even those not performing any disk I/O. If you want to see only processes actively using disk resources, run iotop with the -o option:
1. sudo iotop -o
This ensures that only processes with ongoing disk read/write activity are displayed, making it easier to identify which processes are affecting disk performance.
You can also track the total disk I/O usage for each process over time. To view cumulative I/O statistics, use the -a option:
1. sudo iotop -a
This mode shows the total disk I/O accumulated by each process since iotop started, giving you a better idea of long-running processes that may be consuming disk bandwidth.
Let’s say your server is experiencing slow performance, and you suspect that excessive disk I/O is the cause. Here’s how you can use iotop to diagnose the issue:
1. Launch iotop in active mode to see only processes performing I/O:
1. sudo iotop -o
2. Monitor the output for a few minutes and look for processes with high disk read or write rates in the DISK READ and DISK WRITE columns.
3. Once you identify a process with unusually high disk I/O, note its PID and user. You can either kill the process (if it’s unnecessary) or adjust its I/O priority using the ionice command to prevent it from affecting the overall system performance.
For example, if a backup process is consuming too much disk bandwidth, you can change its I/O priority with:
1. sudo ionice -c3 -p [PID]
This will lower the priority of the process, allowing other processes to access disk resources more easily.
iotop provides several options for customizing its output. Here are a few useful commands:
- Batch Mode (-b): To run iotop in non-interactive batch mode (useful for logging), use:
1. sudo iotop -b > /path/to/logfile
This will continuously write the output to a log file.
. Interval (-d): To change the refresh interval, use the -d option. For example, to update every 5 seconds:
1. sudo iotop -d 5
- Number of Iterations (-n): To limit the number of iterations (how many times it refreshes), use -n. For example, to run iotop 10 times:
1. sudo iotop -n 10
This can be useful for capturing short-term I/O spikes without continuously running the tool.
iotop is an invaluable tool for monitoring and troubleshooting disk I/O performance on your Ubuntu VPS. It provides real-time insights into which processes are consuming disk resources, helping system administrators quickly identify and resolve disk I/O bottlenecks. With its simple installation process and powerful monitoring features, iotop is essential for maintaining the health of your server. By following this guide, you’ve learned how to install and use iotop, explored its key features, and seen examples of how it can help improve your server's performance by identifying disk I/O issues.
14-10-2024
This article offers a detailed guide on installing and configuring IPTables on an Ubuntu VPS. IPTables is a powerful firewall tool that helps secure your server by controlling inbound and outbound traffic. Learn how to set up rules for traffic filtering, configure basic security policies, and apply custom rules to protect your VPS.
IPtables
security
12 min
This article offers a comprehensive guide on installing and configuring ModSecurity, a powerful web application firewall (WAF), on an Ubuntu VPS. Learn how to secure your server by filtering and monitoring HTTP requests, set up ModSecurity with Nginx or Apache, and apply rules to protect against common web attacks.
Modsecurity
security
10 min
14-10-2024
This article provides a comprehensive guide on installing and configuring PHP-FPM (FastCGI Process Manager) on an Ubuntu VPS. Learn how to optimize PHP performance for your web applications by configuring PHP-FPM with Nginx or Apache, managing pools, and fine-tuning settings for efficient processing of PHP scripts.
PHP-FPM
speed
optimise
12 min