Linux性能测试 vmstat命令

简介: vmstat命令是最常见的Linux/Unix监控工具,可以展现给定时间间隔的服务器的状态值,包括服务器的CPU使用率,内存使用,虚拟内存交换情况,IO读写情况。这个命令是我查看Linux/Unix最喜爱的命令,一个是Linux/Unix都支持,二是相比top,我可以看到整个机器的CPU,内存,IO的使用情况,而不是单单看到各个进程的CPU使用率和内存使用率(使用场景不一样)。

vmstat命令是最常见的Linux/Unix监控工具,可以展现给定时间间隔的服务器的状态值,包括服务器的CPU使用率,内存使用,虚拟内存交换情况,IO读写情况。这个命令是我查看Linux/Unix最喜爱的命令,一个是Linux/Unix都支持,二是相比top,我可以看到整个机器的CPU,内存,IO的使用情况,而不是单单看到各个进程的CPU使用率和内存使用率(使用场景不一样)。

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]
   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 -m 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 -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.

 

一般vmstat工具的使用是通过两个数字参数来完成的,第一个参数是采样的时间间隔数,单位是秒,第二个参数是采样的次数,如:

[root@C44 ~]#  vmstat 2 3
procs -----------memory---------- ---swap-- -----io---- --system-- ----cpu----
 r  b   swpd   free   buff  cache   si   so    bi    bo   in    cs us sy id wa
 0  0      0 142020  66240 225220    0    0     1    10  222    22  0  0 100  0
 0  0      0 142020  66240 225220    0    0     0     0 1162    45  0  0 100  0
 0  0      0 141892  66240 225220    0    0     0     0 1096    62  0  0 100  0
[root@C44 ~]#  

2表示每个两秒采集一次服务器状态,3表示采集三次。

 

实际上,在应用过程中,我们会在一段时间内一直监控,不想监控直接结束ctrl+c就行了,例如:

[root@C44 ~]#  vmstat 2 
procs -----------memory---------- ---swap-- -----io---- --system-- ----cpu----
 r  b   swpd   free   buff  cache   si   so    bi    bo   in    cs us sy id wa
 0  0      0 141972  66224 225236    0    0     1    10  221    22  0  0 100  0
 0  0      0 141972  66224 225236    0    0     0    74 1064    34  0  0 100  0
 0  0      0 141972  66224 225236    0    0     0     0 1064    32  0  0 100  0
 0  0      0 141972  66224 225236    0    0     0     0 1054    34  0  0 100  0
 0  0      0 141772  66224 225236    0    0     0     0 1058    62  0  0 100  0


 vmstat命令输出分成六个部分:
  (1)进程procs:
  r:在运行队列中等待的进程数 。
  b:在等待io的进程数 。
  (2)内存memoy:
  swpd:现时可用的交换内存(单位KB)。
  free:空闲的内存(单位KB)。
  buff: 缓冲去中的内存数(单位:KB)。
  cache:被用来做为高速缓存的内存数(单位:KB)。
  (3) swap交换页面
  si: 从磁盘交换到内存的交换页数量,单位:KB/秒。
  so: 从内存交换到磁盘的交换页数量,单位:KB/秒。
  (4) io块设备:
  bi: 发送到块设备的块数,单位:块/秒。
  bo: 从块设备接收到的块数,单位:块/秒。
  (5)system系统:
  in: 每秒的中断数,包括时钟中断。
  cs: 每秒的环境(上下文)切换次数。
  (6)cpu中央处理器:
  cs:用户进程使用的时间 。以百分比表示。
  sy:系统进程使用的时间。 以百分比表示。
  id:中央处理器的空闲时间 。以百分比表示。
     wa:等待IO CPU时间。


 

目录
相关文章
|
6月前
|
Linux 应用服务中间件 Shell
二、Linux文本处理与文件操作核心命令
熟悉了Linux的基本“行走”后,就该拿起真正的“工具”干活了。用grep这个“放大镜”在文件里搜索内容,用find这个“探测器”在系统中寻找文件,再用tar把东西打包带走。最关键的是要学会使用管道符|,它像一条流水线,能把这些命令串联起来,让简单工具组合出强大的功能,比如 ps -ef | grep 'nginx' 就能快速找出nginx进程。
775 1
二、Linux文本处理与文件操作核心命令
|
6月前
|
Linux
linux命令—stat
`stat` 是 Linux 系统中用于查看文件或文件系统详细状态信息的命令。相比 `ls -l`,它提供更全面的信息,包括文件大小、权限、所有者、时间戳(最后访问、修改、状态变更时间)、inode 号、设备信息等。其常用选项包括 `-f` 查看文件系统状态、`-t` 以简洁格式输出、`-L` 跟踪符号链接,以及 `-c` 或 `--format` 自定义输出格式。通过这些选项,用户可以灵活获取所需信息,适用于系统调试、权限检查、磁盘管理等场景。
455 137
|
6月前
|
安全 Ubuntu Unix
一、初识 Linux 与基本命令
玩转Linux命令行,就像探索一座新城市。首先要熟悉它的“地图”,也就是/根目录下/etc(放配置)、/home(住家)这些核心区域。然后掌握几个“生存口令”:用ls看周围,cd去别处,mkdir建新房,cp/mv搬东西,再用cat或tail看文件内容。最后,别忘了随时按Tab键,它能帮你自动补全命令和路径,是提高效率的第一神器。
1213 58
|
5月前
|
SQL 安全 Linux
Metasploit Pro 4.22.8-20251014 (Linux, Windows) - 专业渗透测试框架
Metasploit Pro 4.22.8-20251014 (Linux, Windows) - 专业渗透测试框架
305 1
Metasploit Pro 4.22.8-20251014 (Linux, Windows) - 专业渗透测试框架
|
5月前
|
Linux 网络安全 iOS开发
Metasploit Framework 6.4.95 (macOS, Linux, Windows) - 开源渗透测试框架
Metasploit Framework 6.4.95 (macOS, Linux, Windows) - 开源渗透测试框架
522 1
Metasploit Framework 6.4.95 (macOS, Linux, Windows) - 开源渗透测试框架
|
6月前
|
安全 Linux 网络安全
Metasploit Pro 4.22.8-2025091701 (Linux, Windows) - 专业渗透测试框架
Metasploit Pro 4.22.8-2025091701 (Linux, Windows) - 专业渗透测试框架
440 2
Metasploit Pro 4.22.8-2025091701 (Linux, Windows) - 专业渗透测试框架
|
6月前
|
Linux 网络安全 iOS开发
Metasploit Framework 6.4.90 (macOS, Linux, Windows) - 开源渗透测试框架
Metasploit Framework 6.4.90 (macOS, Linux, Windows) - 开源渗透测试框架
502 1
Metasploit Framework 6.4.90 (macOS, Linux, Windows) - 开源渗透测试框架
|
5月前
|
存储 安全 Linux
Linux卡在emergency mode怎么办?xfs_repair 命令轻松解决
Linux虚拟机遇紧急模式?别慌!多因磁盘挂载失败。本文教你通过日志定位问题,用`xfs_repair`等工具修复文件系统,三步快速恢复。掌握查日志、修磁盘、验重启,轻松应对紧急模式,保障系统稳定运行。
1072 2
|
6月前
|
缓存 监控 Linux
Linux内存问题排查命令详解
Linux服务器卡顿?可能是内存问题。掌握free、vmstat、sar三大命令,快速排查内存使用情况。free查看实时内存,vmstat诊断系统整体性能瓶颈,sar实现长期监控,三者结合,高效定位并解决内存问题。
612 0
Linux内存问题排查命令详解
|
6月前
|
Unix Linux 程序员
Linux文本搜索工具grep命令使用指南
以上就是对Linux环境下强大工具 `grep` 的基础到进阶功能介绍。它不仅能够执行简单文字查询任务还能够处理复杂文字处理任务,并且支持强大而灵活地正则表达规范来增加查询精度与效率。无论您是程序员、数据分析师还是系统管理员,在日常工作中熟练运用该命令都将极大提升您处理和分析数据效率。
562 16