
{{ $('Map tags to IDs').item.json.title }}
How to Monitor System Performance with htop and iostat
Monitoring system performance is essential for ensuring that servers and applications run smoothly. This tutorial will guide you through using two powerful command-line tools, htop and iostat, to monitor system performance in Linux.
Prerequisites
- A Linux-based system with terminal access.
- Root or sudo privileges to install packages if necessary.
1. Installing htop
htop is an interactive process viewer for Unix systems. To install it, open your terminal and run:
- For Ubuntu/Debian:
sudo apt update sudo apt install htop -y
- For CentOS/RHEL:
sudo yum install htop -y
- For Fedora:
sudo dnf install htop -y
2. Running htop
To run htop, simply type:
htop
You will see a dynamic real-time view of your system’s processes, CPU, memory utilization, and more. Use the function keys for options like sorting processes or killing tasks.
3. Understanding htop Output
In htop, you’ll see multiple key metrics:
- CPU Usage: Shown in a bar graph format representing CPU load for each core.
- Memory and Swap Usage: Indicated in percentage and actual usage.
- Processes: List of currently running processes with details such as user, PID, CPU, and memory usage.
4. Installing iostat
iostat is part of the sysstat package. To install it:
- For Ubuntu/Debian:
sudo apt install sysstat -y
- For CentOS/RHEL:
sudo yum install sysstat -y
- For Fedora:
sudo dnf install sysstat -y
5. Running iostat
To start monitoring I/O statistics, run:
iostat
This will display CPU usage and I/O statistics for all devices.
6. Using iostat with Options
You can specify options to customize the output. For example, to display statistics every 2 seconds for 10 iterations, use:
iostat -x 2 10
Here, -x
shows extended statistics, while 2
is the interval in seconds, and 10
is the number of times to report.
7. Understanding iostat Output
Key metrics from the iostat output include:
- %iowait: The percentage of time that the CPU is idle while waiting for I/O operations to complete.
- tps: Transactions per second, indicating the number of transfers to the disk.
- kB_read/s: The number of kilobytes read from the disk per second.
- kB_wrtn/s: The number of kilobytes written to the disk per second.
8. Combining htop and iostat
For comprehensive monitoring, use both tools simultaneously. While htop provides a live view of processes and resource consumption, iostat helps you analyze I/O performance. Open two terminal windows—one for each tool.
9. Conclusion
Monitoring system performance is crucial for maintaining optimal server health. By using tools like htop and iostat, you can effectively assess both resource utilization and I/O statistics. Incorporate these practices into your system administration routine for better insights and proactive management.