The top command under linux can be used to monitor the health status of the server in real time. This command can obtain a lot of information, and it is one of the best helpers for server operation and maintenance engineers. We know that the ps command can monitor the running status of each process on the server at a certain moment. Compared with ps, the top command can continuously monitor.
top [options]
Common options are as follows:
-
-d screen refresh interval, the default is 5 seconds
-
-n total screen refresh times
-
-u specifies the user name
-
-p specifies the process ID
Next, let’s look at the top command The generated information
-
top – 14:55:21 indicates the current time of the system
-
up 12 days, 1:28 indicates the time the server has been running since the last startup
-
1 user How many current systems are there users have logged in
-
load average: 0.17, 0.09, 0.13 indicates the workload of the system in the past 1 minute, 5 minutes, and 15 minutes. Load means that the system is running several programs at the same time. For a single-core CPU, it is normal if the load is less than 1. If there are 4 CPUs with two cores, it is normal for the load to be less than 8.
Continue to look at the second line, the second line is to give the overall information of all processes in the system, how many 191 processes are there in total, 1 process is running, 190 processes in sleep.
The third line shows the cpu usage information
-
us indicates the cpu percentage occupied by the user process, if It is multi-core, this represents the average value, you can press 1 to display the usage of each cpu.
-
sy indicates the percentage of cpu occupied by kernel space
-
id indicates the percentage of idle time in cpu
-
wa means I/0 wait, that is, the percentage of cpu time waiting for input and output
The fourth and fifth lines respectively display the memory Usage and swap space usage.
For the top command, we not only need to know the meaning of several options, but also need to know some interactive commands. These interactive commands allow us to query the desired information very conveniently. The two commonly used interactive commands are as follows:
-
P: Sort according to the percentage of CPU usage;
-
M: Sort according to resident memory size
-
c: Switch to display command name and complete command line
After introducing the top command, here is a very useful small method in daily operation and maintenance. When we know that a certain process consumes more resources, we may need to monitor this process for a period of time. If it continues to consume resources, we need to take corresponding measures. For example, we know that the mysql process consumes more resources and its pid is 1992, so we use top to monitor the process for a while.
top -p 1992
The above is a comprehensive explanation of the top command under linux – the detailed content of real-time monitoring server status, more Please pay attention to other related articles on 1024programmer.com!