Monitoring system resources is an essential part of managing a server environment. It helps identify potential issues and bottlenecks, allowing for proactive troubleshooting and performance optimization. This guide introduces how to use various tools such as htop
, vmstat
, and iostat
to monitor CPU, memory, disk I/O, and network usage on Ubuntu 20.04.
Step 1: Installing Required Packages
-
Update the package lists for upgrades and new package installations:
sudo apt update
-
Install
htop
,sysstat
(which containsvmstat
andiostat
), andnet-tools
:sudo apt install htop sysstat net-tools
Step 2: Monitoring CPU and Memory with htop
-
Run
htop
in your terminal:htop
htop
provides a real-time, color-coded overview of system usage. The top line displays CPU usage, the middle line shows memory usage, and the bottom line represents swap usage.
Step 3: Monitoring System Activity with vmstat
-
Run
vmstat
in your terminal:vmstat
vmstat
reports information about processes, memory, paging, block I/O, traps, and CPU activity.
To continuously monitor system activity, specify the time interval (in seconds) as an argument:
vmstat 5
Step 4: Monitoring Disk I/O with iostat
-
Run
iostat
in your terminal:iostat
iostat
reports CPU usage and I/O statistics for devices, partitions, and network filesystems.
Step 5: Monitoring Network Usage
To view network statistics, use the netstat
command:
netstat -i
This command displays the status of the network interfaces on your system.
Conclusion:
Regular monitoring is vital in maintaining a healthy server and optimizing performance. By utilizing htop
, vmstat
, iostat
, and netstat
, you can ensure that you have an overview of your system resources at all times and can act quickly when issues arise.
Remember, these tools should form part of a broader monitoring strategy, which could include more comprehensive solutions for large-scale or mission-critical environments.