Linux system tuning - the overall operating system state investigation and (vii) a day linux command: vmstat

(1).vmstat

  vmstat command is the most common Linux / Unix monitoring tool that can show the value of the overall state of the server at a given time interval, including the server's CPU usage, MEM memory usage, VMSwap virtual memory swap case, IO read and write conditions.

[root@youxi1 ~]# vmstat
procs -----------memory---------- ---swap-- -----io---- -system-- ------cpu------
 r  b   swpd   free   buff  cache   si   so    bi    bo   in   cs us sy  id wa st
 1  0      0 3709568   2108 156248   0    0     1     0   20   18  0  0 100  0  0

Description:

 procs (processes):

  r shows the number of running processes and waiting to run, and when the value exceeds the number of CPU, there will be a CPU bottleneck.

  b in several non-disruptive sleep process. That is, waiting for the number of IO process.

 memory (RAM):

  swpd used virtual memory size. If you use more virtual memory, physical memory system may be relatively tight, we need to take the appropriate way to reduce the use of physical memory. swpd is not 0, does not mean that the physical memory is tight , Si, value so long as 0, and this is not a problem.

  Free free physical memory size

  buff used to make the amount of memory buffer (cache, main cache block devices), unit: KB

  cache as cache memory size. If a large value when the cache, indicating that the file cache at a few more, if frequent access to the file can be at the cache, then the disk read IO bi will be very small. Unit: KB

 swap (swap partition):

  si  written from the disk to the amount of virtual memory swap swap page, unit: KB / sec. If this value is greater than 0, it represents the physical memory is not enough memory or leaked. 

  so from the read-out data within virtual swap. I.e., the number of page write data exchange swap to disk, unit: KB / s, if this value is greater than 0, represents the physical memory is not enough memory or leaked.

  Note: Memory enough time, these two values are 0, if these two long-term value greater than 0, the system performance will be affected, disk IO and CPU resources will be consumed. When you see the free memory (free) little or close to zero, it is considered not enough memory, this is not true. Not just look at it, but also with si and so. Few if free, but the si and so is 0, then do not worry, then the system performance will not be affected.

 IO (referred to herein as out of memory data):

  bi received from the second apparatus to the block of the block number, unit: block / sec is read block device. bi usually read data disk

  bo to the number of blocks per block transmission apparatus, unit: block / sec is written block device. bo usually write data disk

 system (system):

  in the number of interrupts per second, including the clock interrupts.

  cs per second environment (context) switching times. For example, we call the system function, it is necessary context switching, and excessive context switching will waste more cpu resources, this value should be as small as possible.

 cpu (percentage of cpu time used, maximum 100%):

  us user CPU time (non-kernel processes take up time ) (in percent).  When the value of us is relatively high, indicating that the user process consumes CPU time and more

  sy used by the system CPU time (in percent). sy high value, indicating system kernel consumes more CPU resources, this is not a benign manifestation, we should examine the reasons.

  id idle CPU time (percentage ) in before Linux 2.5.41, this section contains IO wait time.

  wa waiting IO of the CPU time, the value of 0. This indicator means CPU is waiting for disk input time, expressed as a percentage. The larger the machine wait io worse performance. Description IO wait more serious, as it may be due to a large number of random disk access caused, there may be a disk bottleneck (block operation).

  st virtual machine occupancy percentage of cpu time. If you run the system on centos kvm virtual machines, and the virtual kvm has run several virtual machines, then this value will show the number of running virtual machines from physical machines to steal the percentage of CPU time.

1) CPU utilization prorated

  us-- user mode --65% to 70%

  sy-- kernel mode --30% to 35%

  id-- idle --0% to 5%

  cs - Context Switches: the number of context switches is directly related to the CPU usage, CPU usage if held in the equilibrium state, a large number of context switches is normal. ( Context switch refers to the writing and reading. Each process when using cpu, need to put their data in the register prior written cpu cpu data buffer (register), and then cpu to the data cache to calculate.)

2) specify the refresh interval, continuous output

[root @ youxi1 ~] # vmstat 1 10 // 1 second interval, the output 10 straight sets 
procs ----------- memory ---------- --- swap- - IO ---- ----- ------ -system-- the CPU ----- 
 rb swpd as Free Cache Si SO BUFF BI BO in the above mentioned id cs US SY WA ST 
 1 0 0 1,778,088 0 125 992 2108 0. 5 0 73 is 76 0 0 100 0 0 
 0 0 0 1778088 2108 1,260,240,000,277,277 0 0 100 0 0 
 0 0 0 1778088 2108 1,260,240,000,279,281 0 0 100 0 0 
 0 0,017,780,882,108,126,024 . 4 327 331 0 0 0 0 0 0 0 100 
 0 0,017,780,882,108,126,024 275 283 0 0 0 0 0 0 0 0 100 
 0 0 0,177,808,821,081,260,240 0,002,702,770,010,000 
 0 0 0,177,808,821,081,260,240 0,002,682,730,010,000
 0  0      0 1778088   2108 126024   0    0     0     0  275  287  0  0 100  0  0
 0  0      0 1778088   2108 126024   0    0     0     1  251  268  0  0 100  0  0
 0  0      0 1778088   2108 126028   0    0     0     0  274  295  0  0 100  0  0

  See for continuously operating state of the overall system, may be noted the main view r, free, si, so, bi, bo, us, id, wa (wa necessary to view more than 40% bi, bo the case).

(2) .sar

  sar command to install sysstat kit. sysstat kit can save the check information to down, the presence of the / var / log / sa directory. sar default display state once every 10 minutes statistical information (from the loading start sysstat package).

[root@youxi1 ~]# yum -y install sysstat

1) Command Format

  SAR [Option] [<interval> [<number>]]

  If you have time intervals and the number of the current situation will be displayed, if not all of today's situation is displayed.

2) Options

  Common options

-A: the sum of all reports, is equivalent to the -I SUM xall the -I option -m -bBdFHqrRSuvwWy ALL -n -P ALL ALL ALL -u 
-d: display disk usage 
-f [filename]: View from the -o [ filename] file is created, the default file name parameter is the current daily data file / var / log / SA / Sadd 
-n <keyword>: Shows the network, keywords can be DEV, EDEV, NFS, NFSD, the SOCK, IP, EIP, ICMP, EICMP, TCP, ETCP, UDP, SOCK6, IP6, EIP6, ICMP6, EICMP6, of IPv6 UDP packets 
-o [filename]: save in binary form is read to obtain the data, the file name is the current default parameters daily data file / var / log / SA / Sadd 
-u [ALL]: display CPU, if you specify ALL, all parameters displayed.

  There are likely to use options

-b: Buffer usage 
-c: creating process number per 
-v: Process, node, and the file table locking 
-r: Memory Usage (detail) 
-R & lt: Memory usage 
-y: the terminal device activity case 
-W: swap (swap memory) situation 
-P [ALL | cPU ID]: Displays the cpu usage 
-w: job creation and system switching case

3) Examples

  Each sample 2 seconds, continuous sampling five times to observe the CPU usage, and the sampling results stored in binary form file in the current directory cpu.sar in.

[root @ youxi1 ~] # sar -u 2 5 -o cpu.sar 
Linux 3.10.0-957.el7.x86_64 (youxi1) 2019 Nian 08 Yue 04 Ri _x86_64_ (the CPU 4) 

01 30 minutes 28 seconds CPU% user% nice% system% iowait% steal% idle 
01 30 minutes and 30 seconds All 0.00 0.00 0.25 0.00 0.00 99.75 
01 30 minutes and 32 seconds All 0.00 0.00 0.00 0.00 0.00 the 100.00 
01 30 minutes and 34 seconds all 0.00 0.00 0.12 0.00 0.00 99.88 
01 30 minutes 36 seconds all 0.00 0.00 0.00 0.00 0.00 100.00 
01 30 min 38 s all 0.00 0.00 0.00 0.00 0.00 100.00 
average time: all 0.00 0.00 0.08 0.00 0.00 99.92

Description:

Output items Detailed description
CPU all the statistics indicate the average of all CPU.
%user Display using a percentage of total CPU time at the user level (application) running.
%nice Displayed at the user level, a nice operation, the percentage of the total time occupied by CPU.
%system At the kernel level (kernel) the percentage of the total running time of CPU usage.
%iowait Displaying a percentage of waiting I / O operation takes a total time of the CPU.
%steal Management program (hypervisor) to provide services to another virtual process while waiting for the percentage of virtual CPU.
%idle Show CPU idle time occupancy percentage of the total time of CPU.

  In all indications, we should mainly pay attention to % wio the value and% idle,% wio too high to indicate the presence of a hard disk I / O bottlenecks ,% idle value is high, said more CPU is idle, if the% idle value is high but the system response slow when there may be waiting for allocation of CPU memory, it should increase the memory capacity. % idle Sustained value if less than 10, then the relatively low CPU processing capacity of the system, indicating that the system resources need to be resolved is the most CPU.

  Check back to the saved file

[root @ youxi1 ~] # sar -u -f cpu.sar 
Linux 3.10.0-957.el7.x86_64 (youxi1) 2019 Nian 08 Yue 04 Ri _x86_64_ (the CPU 4) 

01 30 minutes 28 seconds CPU% user% nice% system% iowait% steal% idle 
01 30 minutes and 30 seconds All 0.00 0.00 0.25 0.00 0.00 99.75 
01 30 minutes and 32 seconds All 0.00 0.00 0.00 0.00 0.00 the 100.00 
01 30 minutes and 34 seconds All 0.00 0.00 0.12 0.00 0.00 99.88 
01 when 30 minutes 36 seconds all 0.00 0.00 0.00 0.00 0.00 100.00 
01 30 minutes 38 seconds when all 0.00 0.00 0.00 0.00 0.00 100.00 
average time: all 0.00 0.00 0.08 0.00 0.00 99.92

4) Check the sar scheduled tasks, and read log

  View the scheduled tasks sar

[root@youxi1 ~]# cat /etc/cron.d/sysstat
# Run system activity accounting tool every 10 minutes
*/10 * * * * root /usr/lib64/sa/sa1 1 1  //每10分钟生成一次
# 0 * * * * root /usr/lib64/sa/sa1 600 6 &
# Generate a daily summary of process accounting at 23:53
53 23 * * * root /usr/lib64/sa/sa2 -A

  Reads the log

[root @ youxi1 ~] # ls / var / log / sa // view the log file 
SA03 SA04 sar03 
[root @ youxi1 ~] # sar -n DEV -f / var / log / SA / SA04 // read the specified log file DEV case of 
Linux 3.10.0-957.el7.x86_64 (youxi1) 2019 Nian 08 Yue 04 Ri _x86_64_ (the CPU 4) 

00 hours 00 minutes 01 seconds IFACE rxpck / s txpck / s rxkB / s txkB / s rxcmp / s TxCMP / S rxmcst / S 
10 minutes 01 seconds lo 9.89 9.89 4.17 4.17 0.00 0.00 0.00 00 during 
10 minutes 01 seconds ens33 0.04 2.02 0.01 0.12 0.00 0.00 0.00 00 during 
00 20 minutes 01 seconds LO 9.88 9.88 4.16 4.16 0.00 0.00 0.00 
00 20 minutes 01 seconds ens33 0.06 2.03 0.01 0.14 0.00 0.00 0.00 
00 30 minutes 01 seconds lo 9.90 9.90 4.16 4.16 0.00 0.00 0.00
00 30 minutes 01 seconds ens33 0.12 2.09 0.01 0.19 0.00 0.00 0.00 
40 minutes 01 seconds lo 9.86 9.86 4.16 4.16 0.00 0.00 0.00 00 during 
00 40 minutes 01 seconds ens33 0.02 2.01 0.00 0.12 0.00 0.00 0.00 
00 hours 50 minutes 01 seconds lo 9.88 9.88 4.16 4.16 0.00 0.00 0.00 
00 hours 50 minutes 01 seconds ens33 0.02 2.01 0.00 0.12 0.00 0.00 0.00 
01 hours 00 minutes 01 seconds LO 9.91 9.91 4.16 4.16 0.00 0.00 0.00  
01 time 00 minutes 01 seconds ens33 0.02 2.01 0.00 0.12 0.00 0.00 0.00
01 hours 10 minutes 01 seconds LO 9.91 9.91 4.17 4.17 0.00 0.00 0.00 
01 when 10 minutes 01 seconds ens33 0.02 2.01 0.00 0.12 0.00 0.00 0.00 
01 20 minutes 01 seconds LO 9.91 9.91 4.16 4.16 0.00 0.00 0.00 
01 20 minutes 01 seconds ens33 0.01 2.01 0.00 0.12 0.00 0.00 0.00 
01 30 minutes 01 seconds lo 9.83 9.83 4.19 4.19 0.00 0.00 0.00 
01 30 minutes 01 seconds ens33 0.02 2.01 0.00 0.12 0.00 0.00 0.00 
40 minutes 01 seconds lo 9.94 9.94 4.17 4.17 0.00 0.00 0.00 01 during 
01 40 minutes 01 seconds ens33 0.08 2.06 0.01 0.12 0.00 0.00 0.00 
01 50 minutes 01 seconds lo 9.88 9.88 4.15 4.15 0.00 0.00 0.00
01 50 minutes 01 seconds ens33 0.01 2.01 0.00 0.12 0.00 0.00 0.00  
02 00 minutes 01 seconds lo 9.86 9.86 4.16 4.16 0.00 0.00 0.00
02 00 minutes 01 seconds ens33 0.02 2.01 0.00 0.12 0.00 0.00 0.00 
Average Time: lo 9.89 9.89 4.16 4.16 0.00 0.00 0.00 
Average Time: ens33 0.04 2.02 0.00 0.13 0.00 0.00 0.00 

11:52:01 LINUX the RESTART 

12 is when 00 of 5 01 seconds IFACE rxpck / S txpck / S rxkB / S txkB / S rxcmp / S TxCMP / S rxmcst / S 
12 is when 10 of 5 01 seconds lo 9.88 9.88 4.16 4.16 0.00 0.00 0.00 
12:10:01 0.21 2.20 0.02 0.16 0.00 ens33 0.00 0.00 
12 is 01 when 20 is of 5 seconds lo 9.91 9.91 4.16 4.16 0.00 0.00 0.00
12:20:01 ens33 0.38 2.31 0.03 0.28 0.00 0.00 0.00  
12 is 30 when 01 seconds of 5 lo 9.88 9.88 4.16 4.16 0.00 0.00 0.00
12 is when 30 of 5 01 seconds ens33 0.07 2.06 0.01 0.15 0.00 0.00 0.00 
12 is when 40 of 5 01 seconds LO 9.92 9.92 4.16 4.16 0.00 0.00 0.00 
12 is when 40 of 5 01 seconds ens33 0.97 2.88 0.09 0.57 0.00 0.00 0.00 
12:50:01 LO 9.91 9.91 4.16 4.16 0.00 0.00 0.00 
12:50:01 ens33 0.31 2.27 0.02 0.33 0.00 0.00 0.00 
13 is when 00 of 5 01 seconds LO 9.94 9.94 4.17 4.17 0.00 0.00 0.00 
13 is when 00 minutes 01 seconds ens33 0.03 2.02 0.00 0.12 0.00 0.00 0.00 
13 is when 10 of 5 01 seconds LO 9.92 9.92 4.16 4.16 0.00 0.00 0.00 
13 is when 10 minutes 01 seconds ens33 0.02 2.01 0.00 0.12 0.00 0.00 0.00 
13 is when 20 is of 5 01 seconds lo 9.92 9.92 4.16 4.16 0.00 0.00 0.00 
13 is when 20 is of 5 01 seconds ens33 0.02 2.01 0.00 0.12 0.00 0.00 0.00 
13 is when 30 of 5 01 seconds lo 9.92 9.92 4.16 4.16 0.00 0.00 0.00 
13:30 ens33 0.13 2.09 0.01 0.13 0.00 0.00 0.00 01 seconds 
40 minutes 01 seconds lo 9.92 9.92 4.16 4.16 0.00 0.00 0.00 13 when 
13:40:01 ens33 0.06 2.04 0.00 0.12 0.00 0.00 0.00 
13 is when 50 minutes 01 seconds lo 9.89 9.89 4.16 4.16 0.00 0.00 0.00 
50 minutes 01 seconds ens33 0.02 2.01 0.00 0.12 0.00 0.00 0.00 13 when 
14 is 00 minutes 01 seconds lo 9.90 9.90 4.16 4.16 0.00 0.00 0.00 
14 when 00 of 5 01 seconds ens33 0.02 2.02 0.00 0.12 0.00 0.00 0.00 
14 when 10 of 5 01 seconds LO 9.88 9.88 4.16 4.16 0.00 0.00 0.00 
14 when 10 of 5 01 seconds ens33 0.02 2.01 0.00 0.12 0.00 0.00 0.00 
average time: lo 9.91 9.91 4.16 4.16 0.00 0.00 0.00 
average time: ens33 0.17 2.15 0.02 0.19 0.00 0.00 0.00

  sar biggest feature is able to monitor the status of all, you can see the touch operation time periods

[root @ youxi1 ~] # sar -s 12:00:00 12:20:00 -e -f / var / log / SA / SA04 
Linux 3.10.0-957.el7.x86_64 (youxi1) August 4, 2019 day _x86_64_ (the CPU. 4) 

12 is 00 when 01 seconds of 5% User% Nice% the CPU System iowait%%% Steal IDLE 
12 is of 5 10 01 seconds when all 0.01 0.00 0.05 0.01 0.00 99.94 
average time: all 0.01 0.00 0.05 0.01 0.00 99.94 
[ youxi1 ~ @ root] # sar -s 12:00:00 12:20:00 -e -f / var / log / SA / SA04 -n DEV 
Linux 3.10.0-957.el7.x86_64 (youxi1) 2019 Nian 08 04 July _x86_64_ (the CPU. 4) 

12 is 00 when 01 seconds of 5 rxpck IFACE / txpck S / S rxkB / txkB S / S rxcmp / S TxCMP / rxmcst S / S 
12 Shi Fen 10 01 Miao lo 9.88 9.88 4.16 4.16 0.00 0.00 0.00
12:10:01 ens33 0.21 2.20 0.02 0.16 0.00 0.00 0.00 
Average Time: lo 9.88 9.88 4.16 4.16 0.00 0.00 0.00 
Average Time: ens33 0.21 2.20 0.02 0.16 0.00 0.00 0.00

  

 

 

 

Reference: every day a linux command: vmstat

  https://blog.csdn.net/volitationlong/article/details/81741754

Guess you like

Origin www.cnblogs.com/diantong/p/11289689.html