In this chapter, we’ll explore system monitoring tools that help you analyze and optimize your Linux system’s resource usage. You’ll learn how to use tools like htop, btop, vmstat, and iostat to monitor CPU, memory, disk, and network activity. By the end of this chapter, you’ll be able to identify performance bottlenecks and keep your system running smoothly.
Monitoring system performance is essential for: - Identifying resource bottlenecks (e.g., high CPU or memory usage). - Diagnosing slow applications or services. - Optimizing resource allocation for better efficiency.
htophtop is an interactive process viewer that provides a real-time overview of system resource usage.
$ sudo apt install htop # Debian/Ubuntu
$ sudo dnf install htop # Red Hat/Fedorahtop: $ htopF6 to sort processes by CPU, memory, or other criteria.F9 to send a signal (e.g., SIGKILL).Monitor processes and identify resource hogs:
$ htopbtopbtop is a modern, feature-rich system monitor with a sleek interface.
$ sudo apt install btop # Debian/Ubuntu
$ sudo dnf install btop # Red Hat/Fedorabtop: $ btopM to toggle menus and customize the display.Monitor system resources with a modern interface:
$ btopvmstatvmstat (Virtual Memory Statistics) provides a snapshot of system performance, including CPU, memory, and I/O activity.
$ vmstatr: Number of processes waiting for CPU.b: Number of processes in uninterruptible sleep.swpd: Amount of swap memory used.free: Amount of free memory.si/so: Swap in/out (memory paging activity).
Monitor Continuously:$ vmstat 1 # Update every 1 second
Monitor CPU and memory usage in real-time:
$ vmstat 1iostatiostat reports CPU and disk I/O statistics.
$ sudo apt install sysstat # Debian/Ubuntu
$ sudo dnf install sysstat # Red Hat/Fedora$ iostat%user: CPU usage for user processes.%idle: CPU idle time.tps: Transactions per second (disk I/O).kB_read/s: Kilobytes read per second.kB_wrtn/s: Kilobytes written per second.
Monitor Continuously:$ iostat 1 # Update every 1 second
Monitor disk I/O activity:
$ iostat 1nloadnload is a real-time network traffic monitor.
$ sudo apt install nload # Debian/Ubuntu
$ sudo dnf install nload # Red Hat/Fedoranload: $ nloadMonitor network traffic:
$ nloadUse htop to identify processes consuming the most CPU:
$ htopUse iostat to monitor disk activity:
$ iostat 1Use vmstat to check memory and swap usage:
$ vmstat 1Use nload to monitor incoming and outgoing traffic:
$ nloadModern system monitoring extends beyond local commands. Prometheus collects metrics from system endpoints, storing them in a time-series database, while Grafana visualizes these metrics in dynamic dashboards.
For log management, journalctl and logrotate help maintain system logs, rotating them on a schedule to prevent storage issues. By integrating these tools, you gain comprehensive insights into system health, enabling proactive issue resolution and a deeper understanding of professional monitoring workflows.
Let’s put your new skills to the test:
1. Use htop to identify the top CPU-consuming processes.
2. Use vmstat to monitor memory and swap usage in real-time.
3. Use iostat to check disk I/O activity.
4. Use nload to monitor network traffic.
That’s it for Chapter 23! You’ve now learned how to monitor system performance using tools like htop, btop, vmstat, and iostat. In the next chapter, we’ll dive into networking in Linux—how to configure and troubleshoot network settings using tools like ifconfig, ip, and netstat. Until then, practice monitoring your system to become more comfortable with these tools.
Prev: Chapter 22 | Next: Chapter 24