每天一个命令(17)vmstat - Report virtual memory statistics

来源:互联网 发布:临沂淘宝代运营 编辑:程序博客网 时间:2024/06/13 21:23

vmstat - Report virtual memory statistics 虚拟内存统计报告

man vmstat 查看命令文档

使用情况
vmstat [-a] [-n] [-t] [-S unit] [delay [ count]]
vmstat [-s] [-n] [-S unit]
vmstat [-m] [-n] [delay [ count]]
vmstat [-d] [-n] [delay [ count]]
vmstat [-p disk partition] [-n] [delay [ count]]
vmstat [-f]
vmstat [-V]

文档描述

DESCRIPTION       vmstat reports information about processes, memory, paging, block IO, traps, and cpu activity.       The  first  report  produced  gives  averages  since the last reboot.  Additional reports give information on a sampling       period of length delay.  The process and memory reports are instantaneous in either case.   Options       The -a switch displays active/inactive memory, given a 2.5.41 kernel or better.       The -f switch displays the number of forks since boot.  This includes the fork, vfork, and clone system  calls,  and  is       equivalent  to  the total number of tasks created. Each process is represented by one or more tasks, depending on thread       usage.  This display does not repeat.       The -t switch adds timestamp to the output.       The -m switch displays slabinfo.       The -n switch causes the header to be displayed only once rather than periodically.       The -s switch displays a table of various event counters and memory statistics. This display does not repeat.       delay is the delay between updates in seconds.  If no delay is specified, only one report is printed  with  the  average       values since boot.       count is the number of updates.  If no count is specified and delay is defined, count defaults to infinity.       The -d reports disk statistics (2.5.70 or above required)       The -w enlarges field width for big memory sizes       The -p followed by some partition name for detailed statistics (2.5.70 or above required)       The -S followed by k or K or m or M switches outputs between 1000, 1024, 1000000, or 1048576 bytes       The -V switch results in displaying version information.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/OFIELD 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 partitionFIELD 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 slabNOTES       vmstat does not require special permissions.       These  reports  are  intended to help identify system bottlenecks.  Linux vmstat does not count itself as a running pro-       cess.       All linux blocks are currently 1024 bytes. Old kernels may report blocks as 512 bytes, 2048 bytes, or 4096 bytes.       Since procps 3.1.9, vmstat lets you choose units (k, K, m, M) default is K (1024 bytes) in the default mode       vmstat uses slabinfo 1.1    FIXMEFILES       /proc/meminfo       /proc/stat       /proc/*/stat

vmstat options参数说明

-a:显示活跃和非活跃内存-f:显示从系统启动至今的fork数量 。-m:显示slabinfo-n:只在开始时显示一次各字段名称。-s:显示内存相关统计信息及多种系统活动数量。delay:刷新时间间隔。如果不指定,只显示一条结果。count:刷新次数。如果不指定刷新次数,但指定了刷新时间间隔,这时刷新次数为无穷。-d:显示磁盘相关统计信息。-p:显示指定磁盘分区统计信息-S:使用指定单位显示。参数有 k 、K 、m 、M ,分别代表1000102410000001048576字节(byte)。默认单位为K1024 bytes)-V:显示vmstat版本信息。

默认不带参数

root@nginx02  ~# vmstatprocs -----------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 230688  75464  58496    0    0     2     1   20   26  0  0 100  0  0   

vmstat 多少秒 执行次数 如果没有执行次数,一直执行

root@nginx02  ~# vmstat 2 1procs -----------memory---------- ---swap-- -----io---- --system-- -----cpu----- r  b   swpd   free   buff  cache   si   so    bi    bo   in   cs us sy id wa st 0  0      0 230680  75464  58496    0    0     2     1   20   26  0  0 100  0  0   root@nginx02  ~# vmstat 2 3procs -----------memory---------- ---swap-- -----io---- --system-- -----cpu----- r  b   swpd   free   buff  cache   si   so    bi    bo   in   cs us sy id wa st 0  0      0 230680  75464  58496    0    0     2     1   20   26  0  0 100  0  0    0  0      0 230664  75464  58496    0    0     0     0   15   10  0  1 99  0  0     0  0      0 230664  75464  58496    0    0     0     0   13    9  0  0 100  0  0   root@nginx02  ~# 

显示内容中文字段说明

r 表示运行队列(就是说多少个进程真的分配到CPU),我测试的服务器目前CPU比较空闲,没什么程序在跑,当这个值超过了CPU数目,就会出现CPU瓶颈了。这个也和top的负载有关系,一般负载超过了3就比较高,超过了5就高,超过了10就不正常了,服务器的状态很危险。top的负载类似每秒的运行队列。如果运行队列过大,表示你的CPU很繁忙,一般会造成CPU使用率很高。b 表示阻塞的进程,这个不多说,进程阻塞,大家懂的。swpd 虚拟内存已使用的大小,如果大于0,表示你的机器物理内存不足了,如果不是程序内存泄露的原因,那么你该升级内存了或者把耗内存的任务迁移到其他机器。free   空闲的物理内存的大小,我的机器内存总共8G,剩余3415M。buff   Linux/Unix系统是用来存储,目录里面有什么内容,权限等的缓存,我本机大概占用300多Mcache cache直接用来记忆我们打开的文件,给文件做缓冲,我本机大概占用300多M(这里是Linux/Unix的聪明之处,把空闲的物理内存的一部分拿来做文件和目录的缓存,是为了提高 程序执行的性能,当程序使用内存时,buffer/cached会很快地被使用。)si  每秒从磁盘读入虚拟内存的大小,如果这个值大于0,表示物理内存不够用或者内存泄露了,要查找耗内存进程解决掉。我的机器内存充裕,一切正常。so  每秒虚拟内存写入磁盘的大小,如果这个值大于0,同上。bi  块设备每秒接收的块数量,这里的块设备是指系统上所有的磁盘和其他块设备,默认块大小是1024byte,我本机上没什么IO操作,所以一直是0,但是我曾在处理拷贝大量数据(2-3T)的机器上看过可以达到140000/s,磁盘写入速度差不多140M每秒bo 块设备每秒发送的块数量,例如我们读取文件,bo就要大于0。bi和bo一般都要接近0,不然就是IO过于频繁,需要调整。in 每秒CPU的中断次数,包括时间中断cs 每秒上下文切换次数,例如我们调用系统函数,就要进行上下文切换,线程的切换,也要进程上下文切换,这个值要越小越好,太大了,要考虑调低线程或者进程的数目,例如在apache和nginx这种web服务器中,我们一般做性能测试时会进行几千并发甚至几万并发的测试,选择web服务器的进程可以由进程或者线程的峰值一直下调,压测,直到cs到一个比较小的值,这个进程和线程数就是比较合适的值了。系统调用也是,每次调用系统函数,我们的代码就会进入内核空间,导致上下文切换,这个是很耗资源,也要尽量避免频繁调用系统函数。上下文切换次数过多表示你的CPU大部分浪费在上下文切换,导致CPU干正经事的时间少了,CPU没有充分利用,是不可取的。us 用户CPU时间,我曾经在一个做加密解密很频繁的服务器上,可以看到us接近100,r运行队列达到80(机器在做压力测试,性能表现不佳)。sy 系统CPU时间,如果太高,表示系统调用时间长,例如是IO操作频繁。id  空闲 CPU时间,一般来说,id + us + sy = 100,一般我认为id是空闲CPU使用率,us是用户CPU使用率,sy是系统CPU使用率。wt 等待IO CPU时间一般 r < 5 , b = 0## 如 r 经常大于3或4,且id经常少于50,则表示cpu负载过大## 如 si、so长期不等于0,表示内存不足## disk 经常不等于0,且在b中的队列大于2或3,表示io的性能不好
0 0
原创粉丝点击