Remember to maintain security and privacy. Do not share sensitive information. Procedimento.com.br may make mistakes. Verify important information. Termo de Responsabilidade
Monitoring CPU usage is crucial for maintaining the performance and stability of a Linux system. By keeping an eye on CPU metrics, system administrators can identify resource bottlenecks, optimize processes, and ensure efficient operation. This article will guide you through various tools and methods to monitor CPU usage in a Linux environment.
Examples:
Using top
Command:
The top
command provides a dynamic real-time view of the system's CPU usage. It displays a list of processes and their CPU consumption.
top
Once you run the command, you'll see an interface displaying the tasks, CPU states, memory usage, and a list of processes. The %CPU
column shows the CPU usage for each process.
Using htop
Command:
htop
is an interactive process viewer for Unix systems. It is a more user-friendly alternative to top
.
sudo apt-get install htop
htop
Similar to top
, htop
provides a real-time view of the system's CPU usage, but with a more intuitive interface.
Using mpstat
Command:
The mpstat
command is part of the sysstat
package and provides detailed CPU usage statistics.
sudo apt-get install sysstat
mpstat
To monitor CPU usage at regular intervals, you can use:
mpstat 1
This command will display CPU usage every second.
Using sar
Command:
The sar
command, also part of the sysstat
package, collects, reports, and saves system activity information.
sudo apt-get install sysstat
sar -u 1 3
This command will report CPU usage every second for three intervals.
Using iostat
Command:
The iostat
command is used for monitoring system input/output device loading by observing the time the devices are active in relation to their average transfer rates.
sudo apt-get install sysstat
iostat -c 1
This command will display CPU statistics every second.
Using vmstat
Command:
The vmstat
command reports information about processes, memory, paging, block IO, traps, and CPU activity.
vmstat 1
This command will display a summary of system performance every second.
Using nmon
Command:
nmon
(Nigel's Monitor) is a system administrator's tool for performance monitoring.
sudo apt-get install nmon
nmon
After running nmon
, press c
to display CPU usage.