vmstat super detailed

1. vmstatIntroduction

vmstat(Virtual Meomory Statistics(虚拟内存统计))It can CPUmonitor the virtual memory, processes and activities of the operating system . To make statistics on the overall situation of the system, the disadvantage is that it is impossible to conduct in-depth analysis of a certain process .

语法格式: 
vmstat [-V] [-n] [-S unit] [delay [count]]         
	-V prints version.  
  
	-n causes the headers not to be reprinted regularly.
     
	-a print inactive/active page stats. 
        
	-d prints disk statistics   
      
	-D prints disk table  
     
	-p prints disk partition statistics  
       
	-s prints vm table  
      
	-m prints slabinfo  
       
	-t add timestamp to output  
       
	-S unit size  
      
	delay is the delay between updates in seconds. 
        
	unit size k:1000 K:1024 m:1000000 M:1048576 (default is K)          

	count is the number of updates.

Parameter explanation:

- -V:显示vmstat版本信息

- -n:只在开始时显示一次各字段名称

- -a:显示活跃和非活跃内存

- -d:显示各个磁盘相关统计信息

- -D:显示磁盘总体信息

- -p:显示指定磁盘分区统计信息

- -s:显示内存相关统计信息及多种系统活动数量

- -m:显示slabinfo

- -t:在输出信息的时候也将时间一并输出出来

- -S:使用指定单位显示。参数有k、K、m、M,分别代表1000、1024、1000000、1048576字节(byte)。默认单位为K(1024bytes)

- delay:刷新时间间隔。如果不指定,只显示一条结果

- count:刷新次数。如果不指定刷新次数,但指定了刷新时间间隔,这时刷新次数为无穷

2. vmstatDescription of each field

[root@pcs08 ~]# vmstat 2 5
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 70922544     52 59824200    0    0     0     0    0    2 43  0 57  0  0
 0  0      0 70922144     52 59824200    0    0     0     0  269  154  0  0 100  0  0
 0  0      0 70922016     52 59824200    0    0     0     0  250  133  0  0 100  0  0
 0  0      0 70921984     52 59824236    0    0     0     0  340  189  0  0 100  0  0
 0  0      0 70921984     52 59824236    0    0     0     0  286  149  0  0 100  0  0

CPU Info


[root@pcs08 ~]# cat /proc/cpuinfo | grep name | cut -f2 -d: | uniq -c
     32  AMD Ryzen Threadripper 2950X 16-Core Processor
[root@pcs08 ~]# cat /proc/cpuinfo| grep "physical id"| sort| uniq| wc -l
1
[root@pcs08 ~]# cat /proc/cpuinfo| grep "cpu cores"| uniq
cpu cores	: 16
[root@pcs08 ~]# cat /proc/cpuinfo| grep "processor"| wc -l
32
比对运行实例:
- r (1/0/0,cpu_num(逻辑数)=32)表示运行队列(就是说多少个进程真的分配到CPU),我测试的服务器目前CPU比较空闲,没什么程序在跑,当这个值超过了CPU数目,就会出现CPU瓶颈了。这个也和top的负载有关系,一般负载超过了3就比较高,超过了5就高,超过了10就不正常了,服务器的状态很危险。top的负载类似每秒的运行队列。如果运行队列过大,表示你的CPU很繁忙,一般会造成CPU使用率很高。

- b(0/0/0) 表示阻塞的进程,这个不多说,进程阻塞。

- swpd(0/0/0) 虚拟内存已使用的大小,如果大于0,表示你的机器物理内存不足了,如果不是程序内存泄露的原因,那么你该升级内存了或者把耗内存的任务迁移到其他机器。

- free(70922048/70922048/70922048)   空闲的物理内存的大小

- buff(52/52/52)   Linux/Unix系统是用来存储,目录里面有什么内容,权限等的缓存,我本机大概占用300多M

- cache(59822788/59822788/59822788) cache直接用来记忆我们打开的文件,给文件做缓冲,把空闲的物理内存的一部分拿来做文件和目录的缓存,是为了提高程序执行的性能。

- si(0/0/0)  每秒从磁盘读入虚拟内存的大小,如果这个值大于0,表示物理内存不够用或者内存泄露了,要查找耗内存进程解决掉。

- so(0/0/0)  每秒虚拟内存写入磁盘的大小,如果这个值大于0,同上。

- bi(0/0/0)  块设备每秒接收的块数量,这里的块设备是指系统上所有的磁盘和其他块设备,默认块大小是1024byte.

- bo(0/0/0) 块设备每秒发送的块数量,例如我们读取文件,bo就要大于0。bi和bo一般都要接近0,不然就是IO过于频繁,需要调整。

- in(0/286/307) 每秒CPU的中断次数,包括时间中断

- cs(2/148/203) 每秒上下文切换次数,例如我们调用系统函数,就要进行上下文切换,线程的切换,也要进程上下文切换,这个值要越小越好,太大了,要考虑调低线程或者进程的数目。

- us(43/0/0) 用户CPU时间。
- sy(0/0/0) 系统CPU时间,如果太高,表示系统调用时间长,例如是IO操作频繁。

- id(56/100/100)  空闲 CPU时间,一般来说,id + us + sy = 100,一般我认为id是空闲CPU使用率,us是用户CPU使用率,sy是系统CPU使用率。

- wt(0/0/0) 等待IO CPU时间。
- st(0/0/0) Time stolen from a virtual machine. Prior to Linux 2.6.11, unknown.

Three, use practice

vmstat

[root@pcs08 ~]# vmstat 
procs -----------memory---------- ---swap-- -----io---- -system-- ------cpu-----
 r  b   swpd   free   buff  cache   si   so    bi    bo   in   cs us sy id wa st
 2  0      0 70556416     52 59851668    0    0     0     0    0    2 43  0 57  0  0
[root@pcs08 ~]# vmstat -a
procs -----------memory---------- ---swap-- -----io---- -system-- ------cpu-----
 r  b   swpd   free  inact active   si   so    bi    bo   in   cs us sy id wa st
 2  0      0 70550888 24455068 34378460    0    0     0     0    0    2 43  0 57  0  0
[root@pcs08 ~]# vmstat -a 1 3
procs -----------memory---------- ---swap-- -----io---- -system-- ------cpu-----
 r  b   swpd   free  inact active   si   so    bi    bo   in   cs us sy id wa st
 2  0      0 70534752 24455068 34394844    0    0     0     0    0    2 43  0 57  0  0
 1  0      0 70530624 24455068 34399252    0    0     0     0 1368  184  3  0 97  0  0
 1  0      0 70530624 24455068 34399252    0    0     0     0 1315  165  3  0 97  0  0

vmstat -w

[root@pcs08 ~]# vmstat -w 2 3
procs -----------------------memory---------------------- ---swap-- -----io---- -system-- --------cpu--------
 r  b         swpd         free         buff        cache   si   so    bi    bo   in   cs  us  sy  id  wa  st
 2  0            0     70044560           52     59853520    0    0     0     0    0    2  43   0  57   0   0
 1  0            0     70042368           52     59853536    0    0     0    59 1438  250   3   0  97   0   0
 1  0            0     70040128           52     59853588    0    0     0     0 1479  285   3   0  97   0   0

关闭非活动内存

free && sync && echo 3 > /proc/sys/vm/drop_caches && echo "" && free

vmstat -p

[root@pcs08 ~]# vmstat -p /dev/nvme0n1p2 1 5
nvme0n1p2     reads   read sectors  writes    requested writes
                 446      55011         10       4137
                 446      55011         10       4137
                 446      55011         10       4137
                 446      55011         10       4137
                 446      55011         10       4137

vmstat -s

[root@pcs08 ~]# vmstat -s
    131806832 K total memory
      1822704 K used memory
     34796660 K active memory
     24455100 K inactive memory
     70132032 K free memory
           52 K buffer memory
     59852052 K swap cache
      4194300 K total swap
            0 K used swap
      4194300 K free swap
    905472869 non-nice user cpu ticks
          473 nice user cpu ticks
      4845440 system cpu ticks
   1191839835 idle cpu ticks
       231248 IO-wait cpu ticks
            0 IRQ cpu ticks
       205444 softirq cpu ticks
            0 stolen cpu ticks
       550506 pages paged in
       876184 pages paged out
            0 pages swapped in
            0 pages swapped out
   1296317449 interrupts
    548789835 CPU context switches
   1607961737 boot time
      4668875 forks

Guess you like

Origin blog.csdn.net/qq_25562325/article/details/111518417