N天学习一个linux命令之vmstat

用途

查看系统资源整体使用情况,包括进程数量,CPU,内存,IO,swap等资源统计信息

用法

vmstat [options] [delay [ count]]

常用选项

-a
显示active/inactive内存

-f
显示forks的数量

-t
显示时间

-m
显示slab信息

-n
信息头部只输出一次,默认会周期性的输出

-s
表格形式显示事件计数器和内存的统计信息

-d
报告硬盘统计信息

-w
增加字段的宽度,显示更加易于查看

-p partition name
显示指定分区的统计信息

-S
内存显示单位(The -S followed by k or K or m or M switches outputs between 1000, 1024, 1000000, or 1048576 bytes)

-V
显示程序版本信息

实践

1 每个2秒报告一次系统情况

[root@vm ~]# vmstat 2
procs -----------memory---------- ---swap-- -----io---- --system-- -----cpu-----
 r  b   swpd   free   buff  cache   si   so    bi    bo   in   cs us sy id wa st
 0  0 1022280 189004  13016 177984    8   21    46   107  313  419  2  1 96  1  0   
 1  0 1022280 188740  13024 178004    0    0    10    76  525  611  1  0 98  1  0   
 0  0 1022280 188856  13032 177996    0    0    10    12  367  402  0  1 98  1  0   
 0  0 1022280 188716  13032 178024    0    0     0     0  465  428  0  0 99  0  0   
 ......

2 显示硬盘统计信息

[root@vm ~]# vmstat -d
disk- ------------reads------------ ------------writes----------- -----IO------
       total merged sectors      ms  total merged sectors      ms    cur    sec
ram0       0      0       0       0      0      0       0       0      0      0
ram1       0      0       0       0      0      0       0       0      0      0
ram2       0      0       0       0      0      0       0       0      0      0
ram3       0      0       0       0      0      0       0       0      0      0
ram4       0      0       0       0      0      0       0       0      0      0
ram5       0      0       0       0      0      0       0       0      0      0
ram6       0      0       0       0      0      0       0       0      0      0
ram7       0      0       0       0      0      0       0       0      0      0
ram8       0      0       0       0      0      0       0       0      0      0
ram9       0      0       0       0      0      0       0       0      0      0
ram10      0      0       0       0      0      0       0       0      0      0
ram11      0      0       0       0      0      0       0       0      0      0
ram12      0      0       0       0      0      0       0       0      0      0
ram13      0      0       0       0      0      0       0       0      0      0
ram14      0      0       0       0      0      0       0       0      0      0
ram15      0      0       0       0      0      0       0       0      0      0
loop0      0      0       0       0      0      0       0       0      0      0
loop1      0      0       0       0      0      0       0       0      0      0
loop2      0      0       0       0      0      0       0       0      0      0
loop3      0      0       0       0      0      0       0       0      0      0
loop4      0      0       0       0      0      0       0       0      0      0
loop5      0      0       0       0      0      0       0       0      0      0
loop6      0      0       0       0      0      0       0       0      0      0
loop7      0      0       0       0      0      0       0       0      0      0
sda   167694 114908 4595756 1453122 146213 1199662 10667146 3261091      0    583
disk- ------------reads------------ ------------writes----------- -----IO------
       total merged sectors      ms  total merged sectors      ms    cur    sec
dm-0  179304      0 3766554 1811878 1068455      0 8528160 18130295      0    542
dm-1  102612      0  820896  428945 267367      0 2138936 207822027      0     77

3 表格形式显示内存统计信息

[root@vm ~]# vmstat -s
      3088360  total memory
      2889484  used memory
      2100284  active memory
       629288  inactive memory
       198876  free memory
        10792  buffer memory
       170184  swap cache
      1675260  total swap
      1028168  used swap
       647092  free swap
       124475 non-nice user cpu ticks
           21 nice user cpu ticks
        26541 system cpu ticks
      4815453 idle cpu ticks
        57706 IO-wait cpu ticks
         5211 IRQ cpu ticks
         1100 softirq cpu ticks
            0 stolen cpu ticks
      2300650 pages paged in
      5367081 pages paged out
       102312 pages swapped in
       267367 pages swapped out
     15726774 interrupts
     21089251 CPU context switches
   1521510912 boot time
        76080 forks

输出字段说明

懒得翻译了,这里直接做个备份,日后查看使用

FIELD DESCRIPTION FOR VM MODE
   Procs
       r: The number of processes waiting for run time.
       b: The number of processes in uninterruptible sleep.

   Memory
       swpd: the amount of virtual memory used.
       free: the amount of idle memory.
       buff: the amount of memory used as buffers.
       cache: the amount of memory used as cache.
       inact: the amount of inactive memory. (-a option)
       active: the amount of active memory. (-a option)

   Swap
       si: Amount of memory swapped in from disk (/s).
       so: Amount of memory swapped to disk (/s).

   IO
       bi: Blocks received from a block device (blocks/s).
       bo: Blocks sent to a block device (blocks/s).

   System
       in: The number of interrupts per second, including the clock.
       cs: The number of context switches per second.

   CPU
       These are percentages of total CPU time.
       us: Time spent running non-kernel code. (user time, including nice time)
       sy: Time spent running kernel code. (system time)
       id: Time spent idle. Prior to Linux 2.5.41, this includes IO-wait time.
       wa: Time spent waiting for IO. Prior to Linux 2.5.41, included in idle.
       st: Time stolen from a virtual machine. Prior to Linux 2.6.11, unknown.

FIELD DESCRIPTION FOR DISK MODE
   Reads
       total: Total reads completed successfully
       merged: grouped reads (resulting in one I/O)
       sectors: Sectors read successfully
       ms: milliseconds spent reading

   Writes
       total: Total writes completed successfully
       merged: grouped writes (resulting in one I/O)
       sectors: Sectors written successfully
       ms: milliseconds spent writing

   IO
       cur: I/O in progress
       s: seconds spent for I/O

FIELD DESCRIPTION FOR DISK PARTITION MODE
       reads: Total number of reads issued to this partition
       read sectors: Total read sectors for partition
       writes : Total number of writes issued to this partition
       requested writes: Total number of write requests made for partition

FIELD DESCRIPTION FOR SLAB MODE
       cache: Cache name
       num: Number of currently active objects
       total: Total number of available objects
       size: Size of each object
       pages: Number of pages with at least one active object
       totpages: Total number of allocated pages
       pslab: Number of pages per slab

参考资料

【1】man vmstat
【2】Linux vmstat命令实战详解
http://www.cnblogs.com/ggjucheng/archive/2012/01/05/2312625.html
【3】vmstat命令
http://man.linuxde.net/vmstat
【4】Linux inactive memory
https://unix.stackexchange.com/questions/305606/linux-inactive-memory
【5】What is active memory and inactive memory?
https://stackoverflow.com/questions/18529723/what-is-active-memory-and-inactive-memory

原文地址:https://www.cnblogs.com/wadeyu/p/8611802.html