Linux CPU metrics

Source: Internet
Author: User
Tags superuser permission

Linux CPU metrics

Linux provides a wealth of commands to monitor CPU-related data, such as top and vmstat. Top is a dynamic display process, that is, you can press the key to continuously refresh the current status. If you execute this command on the foreground, it will exclusively occupy the foreground until the user terminates the program. More accurately, the top command provides real-time monitoring of the status of the system processor, it displays the list of CPU-most "sensitive" tasks in the system. This command can sort tasks by CPU usage, memory usage, and execution time. Many features of this command can be set through interactive commands or in a custom file.

The top command provides the following parameters: top [-] [d delay] [p pid] [q] [c] [C] [S] [s] [I] [n iter] [B]
Option name Description
D delay Specify the interval between two screen information refreshes (delay is the specific interval value in seconds). You can use the s interactive command to change the interval.
P pid You can specify a monitoring process ID (pid) to only monitor the status of a specific process.
Q This option will refresh top without any delay. If the caller has the superuser permission, top runs with the highest possible priority.
C Display the entire command line, not just the command name.
C This parameter is only valid for SMP systems.
S Specify the accumulative mode.
S Run the top Command in safe mode. This removes the potential danger of interactive commands.
I So that the top node does not display any idle or dead processes.
N iter Specifies the number of iterations of the top command output. iter is the specific number of iterations.
B Run top in Batch mode. In this mode, all input from the terminal will be ignored (except ctrl + c ), this parameter can be used together with the parameter "n" to run the specified number of iterations to exit or the process is killed. This is the default running mode for running top output to a dumb terminal or to a non-terminal.
For example, enter "top" in the console and press enter as follows: the top command output contains two parts: The first part is the statistical information, including the five-line data information; the second part is the detailed information, displays detailed information about each process. It is necessary to understand the meaning of the output information in the Statistical Information Section:
Output Information Description
19:47:24 Current Time
Up 15 min System running time
2 users Number of currently logged-on users. Here are jzhou and root.
Load average: 0.02, 0.14, 0.21 System load, that is, the average length of the task queue. The three values are the average values from 1 minute, 5 minutes, and 15 minutes ago to the present, that is, 0.02, 0.14, and 0.21.
Task: 122 total, 1 running, 120 sleeping, 0 stopped, 1 zombie 122 processes (tasks), 2 of which are in the running state, 120 are in the sleep state, no stopped processes, and 1 botnet Process
Cpus: 0.7% us, 0.7% sy, 0.0% ni, 97.6% id, 0.0% wa, 0.7% hi, 0.3% si, 0.0% st Cpu running status. The user process occupies 0.7% of the CPU, the system process occupies 0.7% of the CPU, and the user process has not changed the priority. Therefore, the user nice value is 0.0%, 97.6% of the CPU is in the idle state (idle) and there is no waiting input and output, so the iowait value is also 0.0%, and the hardware request terminal time (hardware interrupt) accounts for 0.7% of the CPU, soft terminal requests accounted for 0.3% of the CPU, and st represents steal time. The specific role is not very clear. It is reserved for other CPUs on the Internet, but not clear.
Mem: 1035244 k total, 537528 k used, 497716 k free, 25816 k buffers The total memory is 1035244 kb, the total used memory is 537528 kb, the total 497716k is the total idle memory, and the total memory KB is used as the kernel cache. (This is a virtual machine. The physical machine seems to have other parameters)
Swap: 0 k total, 0 k used, 0 k free, 351392 k cached The total number of swap partitions is 0 k, the total number of swap partitions used is 0 k, the total number of free swap partitions is 0 k, and 351392k is the total number of buffer swap areas (cached) the content in the memory is taken to the swap area, and then switched to the memory, but the used swap area has not been overwritten. This value is the size of the swap area where the content already exists. When the corresponding memory is swapped out again, you do not have to write data to the swap zone.
Then let's take a look at the details of the output information:
Output Information Description
PID Process identifier
USER Process owner Username
PR/PRI Priority of Process Execution
NI NICE value, negative value indicates high priority, positive value indicates low priority
VIRT Total virtual memory used by the process, in kb. VIRT = SWAP + RES
RES Physical memory used by the process, not swapped out, in kb. RES = CODE + DATA
SHR Size of shared memory, in kb
S/STAT Process status
D: uninterrupted sleep
R: A running process or a process in the queue
S: Sleep
T: Stop or be tracked
Z: Zombie Process
W: Switch to memory
X: Dead Process

% CPU CPU usage from the last update to the present
% MEN Percentage of physical memory used by the Process
TIME + Total CPU time used by the process, in 1/100 s
COMMAND Name of the Command executed by the Process
Example 2: The vmstat command allows you to view the system memory and CPU usage in the same line. Generally, you can use this command to view the CPU utilization and saturation. First connect two concepts: CPU utilization can be calculated by using vmstat from 100 minus the sum of id or us and sy CPU usage CPU saturation: the CPU saturation can be calculated using the "procs: as a measure, because it is the total value of all cpu running queues, the value obtained by dividing procs: r by the number of CPUs can be compared with other servers. Any non-zero value that remains unchanged will cause performance degradation, but the performance decline is gradual. The vmstat command parameters are as follows: vmstat [-n] [delay [count] It is also necessary to understand the meaning of the vmstat command parameters:
Parameter Name Description
N With this switch parameter, if it is enabled, only the header information is displayed once.
Delay Interval between two screen information refreshes. Unit: s
Count When used with the delay parameter, if a specified value is specified, the system exits after running the specified number of times. Otherwise, the system runs infinitely.
Enter "vmstat-n 1" in the console. After you press enter to execute the command, only the header information is displayed, display the vmstat monitoring information once every 1 second and understand the meaning of each part of the output information. Example 3 can also use the "uptime" command to obtain the average CPU load. The calculation of the average load is generally described as the average number of running and running threads. For example, if one running thread on a single CPU server occupies the CPU, three running processes are in the scheduler queue, the average load is 1 + 3 = 4. For a 16-CPU server with 16 running threads and 24 running processes in the scheduler queue, the average load is 40. If the average load is always higher than the number of CPUs, the application performance may decline. It must be noted that the average load is only applicable to the initial estimation of CPU load. for in-depth analysis, we also need to use other tools. After having a preliminary understanding of the average CPU load, let's take a look at how the command is used, and its output content contains the content. Because the "uptime" command only provides an optional parameter item "V", that is, it displays the version information of the command, so you do not need to describe it. Enter "uptime" in the console and press enter to run the command. The running result is as follows: "load average: 0.53, 0.65, 0.34" indicates that the average CPU load corresponds to the system in 1st minutes, average load for 5 minutes and 15 minutes. They also represent CPU utilization and saturation. If the number of CPUs is equal to the average load value, it usually indicates the CPU usage of 100%. If the number is smaller than the number of CPUs, it indicates that the utilization is less than 100%. If the number is greater than the number of CPUs, it must be measured by the saturation.

This article permanently updates the link address:

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.