CPU Load View Method:
Using Vmstat to view the CPU load of the system dimension
Using top to view the CPU load of a process dimension
Use Vmstat to view the CPU load at the system latitude:
You can view CPU resource usage from the system dimension by Vmstat.
Usage Instructions:
Format: Vmstat-n-N 1 indicates that the result is refreshed once a second. Sample output:
[Root@wangerxiao ~]# Vmstat- T 1
procs-----------memory-------------Swap-------io-----system-------- CPU----------Timestamp-----
r B swpd free buff cache si so bi bo in CS US sy ID WA St CST
3 0 0 5910832 134096 3931732 0 0 0 1 0 1 0 0 0 0 2016-11-13 19:57:36
0 0 0 5910816 134096 3931732 0 0 0 0 274 511 0 0 0 2016-11-13 19:57:37
0 0 0 5910816 134096 3931732 0 0 0 0 283 506 0 0 0 0 2016-11-13 19:57:38
Echo Description:
Returns the primary data column description in the result: R: A thread that represents the CPU waiting to be processed in the system. Because the CPU can only handle one thread at a time, the larger the number, it usually indicates that the system is running slower. US: The percentage of CPU time consumed by user mode. A higher value indicates that the user process consumes more CPU time, for example, if the value is longer than 50%, you need to optimize the program algorithm or code. SY: The percentage of CPU time consumed by kernel mode. Wa:io the percentage of CPU time that is waiting to be consumed. When this value is high, the IO wait is more severe, which may be caused by a large number of random accesses to the disk, or it may be a bottleneck in disk performance. ID: Percent of CPU time in idle state. If the value persists at 0 and Sy is twice times that of us, it usually indicates that the system is facing a shortage of CPU resources.
Use top to view the CPU load at the latitude of the process:
You can view the usage of resources such as CPU, memory, etc. from the top from the process latitude.
Usage Description: Format: Top sample output
[Root@wangerxiao ~]# top top-20:02:37 up, 23:33, 2 users, load average:0.00, 0.01, 0.05 tasks:296 Total, 1 Running, 295 sleeping, 0 stopped, 0 zombie%cpu (s): 0.1 us, 0.1 sy, 0.0 ni, 99.8 ID, 0.0 wa, 0.0 hi, 0.0 si, 0 .0 St KiB mem:12139008 Total, 5998320 free, 2074896 used, 4065792 buff/cache KiB swap:2098172 Total, 2098172 free, 0 used.
9739056 avail Mem PID USER PR NI virt RES SHR S%cpu%mem time+ COMMAND 1006 Influxdb 0 5001836 332224 11568 S 1.0 2.7 1172: Wuyi influxd 3578 Icinga 20 0 13990
12792 5152 S 0.3 0.1 136:59.57 ICINGA2 30207 Root 0 40800 2120 1328 R 0.3 0.0 0:00.10 Top
1 root 0 196848 11904 2348 S 0.0 0.1 7:32.27 systemd 2 Root 0 0 0 0 S 0.0 0.0 0:02.22 Kthreadd 3 Roo
T 0 0 0 0 S 0.0 0.0 0:00.71 ksoftirqd/0
5 root 0-20 0 0 0 S 0.0 0.0 0:00.00 kworker/0:0h 7 Root RT 0 0 0 0 S 0.0 0.0 0:01.43 migration/0 8 Root 20
0 0 0 0 S 0.0 0.0 0:00.00 RCU_BH 9 ROot 0 0 0 0 S 0.0 0.0 0:00.00 rcuob/0
0 0 0 0 S 0.0 0.0 0:00.00 RCUOB/1 Root 0 0 0 0 S 0.0 0 .0 0:00.00 RCUOB/2 Root 20
0 0 0 0 S 0.0 0.0 0:00.00 RCUOB/3 0 0 0 0 S 0.0 0.0 0:00.00 RCUOB/4
Echo Description:
The third row on the default interface shows the overall usage of the current CPU resources, and the resource consumption of each process is shown below.
You can enter the size of the letter P directly in the interface, so that the monitoring results by CPU usage in reverse order, and then locate the system occupies a higher CPU process. Finally, according to the system log and the relevant log of the program itself, the corresponding process is further analyzed to determine the reasons for the high CPU.
Action column:
Use top to terminate CPU-consuming processes directly
As mentioned earlier, you can view the system's load problems through the top command and locate processes that consume more CPU resources.
You can quickly terminate the corresponding exception process directly in the top run interface. The description is as follows:
1, to terminate a process, just press the lowercase k key.
2, enter the process PID you want to terminate (the first column of the top output result). For example, as shown in the following figure, if you want to terminate the PID 23 process, enter 23 and press ENTER.
3, as shown in the following figure, after successful operation, the interface will appear similar to "Send PID signal [15/sigterm]" prompted the user to confirm the message. Press ENTER to confirm
Low CPU usage but high load
Problem Description:
The Linux system has no business program running, and the top observation, like the following figure, shows that the CPU is idle, but the load average is very high:
Treatment methods:
The load average is an evaluation of the CPU load, the higher the value, the longer the task queue, the more tasks waiting to be performed.
When this happens, it may be caused by a zombie process. You can see whether a D-state process exists through an instruction PS-AXJF.
The D state refers to an uninterrupted sleep state. The process of this state cannot be killed, and it cannot exit itself. Can only be resolved by restoring its dependent resources or restarting the system.
KSWAPD0 process consumes higher CPU
The operating system uses a paging mechanism to manage physical memory, the operating system will be part of the disk as virtual memory, because the speed of memory is much faster than the disk, so the operating system in accordance with some kind of page-changing mechanism to swap unwanted pages to disk, the required pages into memory, due to insufficient memory, This page-changing action continues, KSWAPD0 is the virtual memory management in charge of page change, when the server is not enough memory kswapd0 will perform a page-changing operation, this page-changing operation is very consuming host CPU resources. If the process continues to be in a non sleep state through the top, and run for a long time, you can initially determine the system in a continuous page-changing operation, you can turn the problem to the cause of insufficient memory to troubleshoot.
Problem Description:
The kswapd0 process consumes a large amount of CPU resources on the system.
Treatment methods:
While the Linux system manages memory through the paging mechanism, it delimits part of the disk as virtual memory. KSWAPD0 is the process of changing pages in virtual memory management for Linux systems. When the system is low on memory, the KSWAPD0 will frequently do the paging operation. Because the paging operation consumes CPU resources very much, it will cause the process to continue to occupy higher CPU resources.
If the KSWAPD0 process continues to be in a non-sleep state through monitoring such as top, and is running longer and continues to occupy higher CPU resources, it is usually due to a continuous paging operation on the system. Can be free, PS, and other instructions to further query the system and the memory footprint of the process, do further analysis.