当前位置: 首页
系统平台
Unix vmstat命令详解与系统性能监控指南

Unix vmstat命令详解与系统性能监控指南

热心网友 时间:2026-06-20
转载

在多CPU系统中,vmstat命令会汇总所有CPU的平均数据,并按进程进行统计。如果不加任何参数直接运行,其输出的每一行都代表自系统启动以来虚拟内存活动的累计情况。简而言之,vmstat是系统级性能监控的基础工具,适用于日常巡检与故障排查,是Linux运维人员必备的命令。

要了解vmstat的完整语法和选项,最直接的方式是通过man命令。例如,你可以将帮助文档导出到文件中仔细研读:

# man vmstat|col -b > /u01/tianlesoftware.txt

当然,直接在终端执行man vmstat也能查看完整手册,下面整理了关键内容,供快速参考。

vmstat命令用法详解

VMSTAT(8)                Linux Administrator's Manual                VMSTAT(8)

NAME
       vmstat - Report virtual memory statistics

SYNOPSIS
       vmstat [-a] [-n] [delay [ count]]
       vmstat [-f] [-s] [-m]
       vmstat [-S unit]
       vmstat [-d]
       vmstat [-p disk partition]
       vmstat [-V]

DESCRIPTION
       vmstat reports information about processes, memory, paging, block IO,
       traps, and cpu activity.

       The first report produced gives a verages since the last reboot. Addi-
       tional reports give information on a sampling period of length delay.
       The process and memory reports are instantaneous in either case.

Options
       -a     Displays active/inactive memory (kernel 2.5.41 or better).
       -f     Displays the number of forks since boot. This includes 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.
       -m     Displays slabinfo.
       -n     Causes the header to be displayed only once, rather than periodically.
       -s     Displays a table of various event counters and memory statistics.
              This display does not repeat.
       delay  The delay between updates in seconds. If no delay is specified,
              only one report is printed with the a verage values since boot.
       count  The number of updates. If no count is specified and delay is defined,
              count defaults to infinity.
       -d     Reports disk statistics (kernel 2.5.70 or above required).
       -p     Followed by a partition name for detailed statistics (kernel 2.5.70 or above required).
       -S     Followed by k, K, m, or M to set output unit (1000, 1024, 1000000, or 1048576 bytes).
       -V     Displays 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, shown as zero.

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 a vailable 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

NOTES
       vmstat does not require special permissions.
       These reports are intended to help identify system bottlenecks.
       Linux vmstat does not count itself as a running process.
       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

FILES
       /proc/meminfo
       /proc/stat
       /proc/*/stat

SEE ALSO
       iostat(1), sar(1), mpstat(1), ps(1), top(1), free(1)

BUGS
       Does not tabulate the block io per device or count the number of system calls.

AUTHORS
       Written by Henry Ware .
       Fabian Frédérick  (diskstat, slab, partitions...)
       Throatwobbler Ginkgo Labs                27 July 1994                         VMSTAT(8)

vmstat使用示例

最常见的用法是每隔2秒采样一次,共显示10次:

# vmstat 2 10
procs -----------memory---------------------- -----swap--- -----io---- ---system--- ----cpu------
 r  b   swpd   free   buff  cache   si   so    bi    bo   in   cs  us  sy  id  wa
 1  1   208  28960  38128 268204    0    0   278    40 1050  370   5  46  44   5
 1  0   208  28896  38128 268204    0    0   128     0 1054  310   4  38  58   1
 2  0   208  28896  38136 268196    0    0   257    55 1056  301   4  39  52   5
 2  0   208  24896  38136 268196    0    0   257     1 1042  593   6  87   7   0
 0  0   208  28672  38136 268196    0    0   257    25 1052  372   4  46  45   5
 0  0   208  28824  38140 268192    0    0   129   111 1052  316   3  32  64   1
 1  0   208  28768  38148 268184    0    0   257   109 1050  286   9  70  21   1
 1  0   208  28512  38148 268184    0    0   257     1 1046  327   6  48  43   2
 0  0   208  28832  38148 268184    0    0   257     1 1047  313   5  42  52   1
 0  0   208  28832  38152 268180    0    0   257   109 1050  308   4  33  59   5

每2秒采样一次,共显示10次。输出中各列均有明确含义,后续将详细解读vmstat输出字段。

Solaris (Unix) 平台下的vmstat示例

-bash-3.00$ vmstat 2 10
 kthr      memory            page            disk          faults      cpu
 r b w   swap  free  re  mf pi po fr de sr s0 s1 -- --   in   sy   cs us sy id
 0 0 0 5016344 4200040 126 512 35  0  0  0  0  0  1  0  0  731 1416  723  3  0 97
 0 0 0 2065576 2375112  14  54  0  0  0  0  0  0  0  0  0  870  625  950  3  0 96
 0 0 0 2065512 2375048  11  50  0  0  0  0  0  0  0  0  0  951  529 1066  3  0 97
 0 0 0 2065512 2375048  11  53  0  0  0  0  0  0  0  0  0  852  548  934  3  0 97
 0 0 0 2065512 2375048   4  40  0  0  0  0  0  0  0  0  0  836  483  907  3  0 97
 0 0 0 2065512 2375048  14  46  0  0  0  0  0  0  0  0  0  873  632  958  3  0 97
 0 0 0 2065512 2375048   0   0  0  0  0  0  0  0  0  0  0  812  417  863  3  0 97
 0 0 0 2065512 2375048   4  40  0  0  0  0  0  0  0  0  0  810  481  874  3  0 97
 0 0 0 2065384 2374920   0   0  0  0  0  0  0  0  0  1  0  0  801  406  862  3  0 96
 0 0 0 2065384 2374920  14  46  0  0  0  0  0  0  0  0  0  817  545  898  3  0 97

Solaris下的输出字段略有不同,但核心思路一致——kthr中的rbcpu列的us/sy/id均为关键性能指标。

vmstat关键指标解读与经验法则

关于CPU性能,以下经验法则值得参考:

1) 若进程等待队列(r)持续超过CPU核心数,则表明大量进程排队等待CPU,系统响应变慢。

2) 当r的值超过可用CPU数量的4倍时,基本可判断CPU资源严重匮乏或主频过低,导致多数进程处于等待状态。

3) 若空闲时间(id)长期为0,且系统时间(sy)达到用户时间(us)的两倍,同样表明CPU资源紧张。

简单总结

运行队列(r)和阻塞队列(b)通常不应超过5。若r经常大于4且id经常低于40%,则CPU负载已相当沉重。

用户态与系统态之和(us+sy)不宜超过80%。超过此阈值时,进程将在运行队列中长时间等待,导致响应时间和吞吐量显著下降。

等待I/O(wa)应控制在25以下。若wa超过40,通常表明磁盘I/O存在瓶颈或磁盘操作过于频繁。

实际上,CPU资源不足的根源往往在于应用程序,例如低效的SQL查询或循环中频繁的系统调用,都会耗尽CPU资源。

内存方面,应重点关注交换区的siso,理想状态下它们应接近零。si表示每秒从磁盘换入内存的数据量,so表示每秒换出到磁盘的数据量。若siso长期不为0,则表明系统频繁使用swap,内存容量不足。

通常情况下,若内存占用率很高而CPU占用很低,需排查是否有大量应用占用内存却不释放。需特别说明:Linux的内存管理机制不会主动释放已使用的内存,因此看到内存使用率高属正常现象。判断内存是否紧张,不应仅看free列,而应关注swap的交换频率——只要siso基本为0,内存即处于健康状态。

来源:https://www.jb51.net/os/Unix/34606.html

游乐网为非赢利性网站,所展示的游戏/软件/文章内容均来自于互联网或第三方用户上传分享,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系youleyoucom@outlook.com。

同类文章
更多
Mac隐藏左上角菜单栏苹果图标

Mac隐藏左上角菜单栏苹果图标

先直接告诉你答案:Mac电脑屏幕左上角的那个苹果标志,既无法关闭,也无法隐藏。它是系统级的固定入口,所有macOS版本都会强制显示。苹果既没有提供开关选项,也没有预留终端命令,更不可能在系统偏好设置里让你找到隐藏开关。如果有人声称能用第三方工具或修改系统文件来删除它,千万别相信——结果很可能是系统不

时间:2026-07-02 07:30
Win11切换输入法的几种常用方法和快捷键设置

Win11切换输入法的几种常用方法和快捷键设置

写文档写得正顺,突然要敲几个英文单词,或者打代码时想切回中文拼音——手指条件反射地按下Ctrl+Space,光标却纹丝不动。这种场景你应该不陌生。Windows 11其实准备了五种互不干扰的切换方式,有些连锁屏界面都能响应,关键是你得选对场景来用。下面把这五种路径挨个拆开,看完你就能找到最适合自己的

时间:2026-07-02 07:29
电脑开机黑屏提示未检测到启动盘修复方法

电脑开机黑屏提示未检测到启动盘修复方法

电脑开机直接黑屏,屏幕上孤零零地显示一句“No boot disk has been detected”——别紧张,这并非系统崩溃,也不是常见的蓝屏代码,而是主板在告诉你:“我没有找到硬盘。”换句话说,电脑连BIOS自检阶段都没能通过。 这属于硬件层面的硬中断,与引导损坏、系统文件丢失完全不是一回事

时间:2026-07-02 07:29
Windows 11更改默认音频采样率级别的详细方法

Windows 11更改默认音频采样率级别的详细方法

Windows 11 用户在播放音频时,偶尔会遇到爆音、杂音甚至声音动态被压缩得干瘪的情况。这种问题通常并非硬件损坏,而是系统在音频采样率设定上“擅作主张”了。例如某次系统更新后,默认格式可能被悄然重置为 24 位 192000 Hz——一个不少声卡难以稳定运行的高规格,结果导致 DMA 缓冲溢出、

时间:2026-07-02 07:29
Win11如何查看笔记本实时充电功率

Win11如何查看笔记本实时充电功率

对于笔记本充电功率的实时监测,系统自带的电池图标只能显示“正在充电”或“已充满”,却无法告知具体的瓦数。要获得实时数值,需要绕过默认界面直接读取硬件传感器。这里直接给出结论:最可靠的工具是HWiNFO64,其次是BatteryInfoView,而powercfg只能用于间接验证。无论你遇到插着65W

时间:2026-07-02 07:29
热门专题
更多
刀塔传奇破解版无限钻石下载大全 刀塔传奇破解版无限钻石下载大全
洛克王国正式正版手游下载安装大全 洛克王国正式正版手游下载安装大全
思美人手游下载专区 思美人手游下载专区
好玩的阿拉德之怒游戏下载合集 好玩的阿拉德之怒游戏下载合集
不思议迷宫手游下载合集 不思议迷宫手游下载合集
百宝袋汉化组游戏最新合集 百宝袋汉化组游戏最新合集
jsk游戏合集30款游戏大全 jsk游戏合集30款游戏大全
宾果消消消原版下载大全 宾果消消消原版下载大全
  • 日榜
  • 周榜
  • 月榜