View system load in CentOS

Source: Internet
Author: User

View system load in CentOS
Recently, a server system has been built, and various system loads need to be queried. Previously, we only used top to view basic information such as cpu and memory. I am not familiar with other information. So the system learns.

1. CPU usage:

1.1: first, let's take a look at the CPU usage details during the Process operation:

As described in Linux Kernel, there are three states of Process:

Is being processed by the CPU, can be processed by the CPU, blocked status.

Being Processed by CPU: as the name suggests, process is occupying CPU.

Can be processed by the CPU: runnable State, which means that it will wait for CPU time for processes in the same runnable state as other runnable states. The schedule Program selects which runnable state process to call to the CPU. (The Queue of these runnable processes is called Run Queue)

Blocked status: the process may be waiting for data obtained by an I/O operation, or the result of a system call.

The number of runnable processes and the number of blocked processes can indicate whether the CPU is busy.

In addition, many system tools display a value: load average. It refers to the sum of running and runnable process.

The three numbers displayed by load average are 1 minute, 5 minutes, and 15 minutes respectively.

1.2: CPU context switch:

Linux Kernel has a schedule () function. It is used to select a process from the runnable queue to enter the CPU and complete Context Switch ).

When the system performs Context Switch, the CPU saves the context information of all old processes and obtains all context information of new processes. context information includes a large number of linux processes, especially some resources: the processes are being executed, the memory allocated, the files opened, and so on. switching Context triggers a large amount of information movement, which is a relatively high overhead. keep context switches as small as possible.

Kernel schedule () triggers context switches. to ensure that each process shares the CPU time equally, the kernel periodically interrupts the running process to see if context switches is required. if necessary, the kernel scheduler starts another process instead of continuing the current process. Every periodic or scheduled interruption may trigger the context switch. the number of scheduled interruptions per second varies depending on different architectures and different kernel versions (HZ ?, The value in the Kernel is usually set to 1000 ).

$ Cat. config | grep CONFIG_HZ

You can see how much this value is set. (Usually 1000 ). That is, the clock is interrupted 1000 times per second.

How to view the clock interruption in user mode? used by Sam before:

# Cat/proc/interrupts

0 indicates the number of clock interruptions. You can use the difference of 10 seconds to calculate the number of clock interruptions per second. However, it does not seem to be applicable to multiple cores.

1.3: CPU status information:

Us--User CPU time
The time the CPU has spent running users 'processes that are not niced.

The percentage of user programs that are not nice.

Sy--System CPU time
The time the CPU has spent running the kernel and its processes.

The percentage of kernel and system call.

Ni--Nice CPU time
The time the CPU has spent running users 'proccess that have been niced.

Percentage of nice user programs.

Wa--Iowait
Amount of time the CPU has been waiting for I/O to complete.

Percentage of I/O operations waiting.

Hi--Hardware IRQ
The amount of time the CPU has been servicing hardware interrupts.

Percentage used to handle hardware interruptions.

Si--Software Interrupts
The amount of time the CPU has been servicing software interrupts.

Percentage of software interruptions processed.

St--Steal Time
The amount of CPU 'stolen' from this virtual machine by the hypervisor for other tasks (such as runningAnotherVir environment?
Tual machine ).

NICE and modify process Priority: See appendix 1.

1.4: use top to view CPU status:

$ Top-d 1-c

Top has powerful functions. It not only displays the time of the current CPU status. You can also display multiple CPU cores (by 1 ). And the core on which a process runs. (By f, j)

If you find that the CPU system occupies too much space, you can use the OProfile tool.

If iowait is very high, you need to check the IO part, such as hard disk and nic.

1.5: Use vmstat to view CPU status:

When you use top to view the cpu status, you can see the status in which the CPU usage is large. And which processes occupy a large amount of CPU.

You can use vmstat to view other information about CPU usage.

$ Vmstat 1// Output results every 1 s

Procs ----------- memory ---------- --- swap -- ----- io ---- system -- ----- cpu -----
RBSwpdFreeBuffCacheSiSoBiBoInCs us sy id wa st

In the CPU project, the us sy id wa st is similar to that in the top project.

Under procs, there are several new ideas:

R: inRunQueue

B: blockedForResourcesI/O,PagingEtc

If the r value continues to be large and exceeds the number of CPU cores continuously, it indicates that CPU resources are seriously insufficient. Many processes are waiting for the CPU, and the CPU computing capability has become a bottleneck.

2. view other IO loads:

When top or vmstat is used to discover a large amount of CPU wa time. In vmstat, if Column B remains relatively large (exceeding the CPU Core ). IO performance is poor.

IO performance. You can view the storage devices and network devices.

Partition viewing type:
Most of the time, Sam uses fdisk-l when looking at the USB flash drive format. View the partition list and format in the USB flash drive. However, this method is not accurate. Because the value obtained by fdisk is only the value modified at-t.

For example, an ext3 partition is created, but the value of-t is not modified to 82. Then, fdisk is displayedWin95 FAT32.

So you can useBlkid.

Process Priority and modification:

When the top command is used. There are two columns that are related to the priority of process:

PR: Priority.

NI: nice.

The smaller the PR value, the higher the priority of the process.

PR (new) = PR (old) + NI

Specify and modify the porcess priority. You can use the nice and renice commands.

$ Sudo nice-n-10 top-d 1

The top NI =-10 is displayed.

Linux nice command details

Function Description: sets priority.

Syntax: nice [-n <priority level>] [-- help] [-- version] [Execute Command]

Note: nice commands can change the priority level of program execution.

Parameter quantity:-n <priority level> or-<priority level> or -- adjustment = <priority level> sets the priority level of the command to be executed. The range of the level is-20-19, of which-20 is the highest and 19 is the lowest. Only the system administrator can set a negative level.

Renice:

Renice-10-P6200

Set process NI of pid = 6100 to-10

In addition, you can modify the priority of porcess by using top.

# Top-d 1

"R" --> enter the process PID --> enter the nice Value

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.