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时间。


 

相关实践学习
通过性能测试PTS对云服务器ECS进行规格选择与性能压测
本文为您介绍如何利用性能测试PTS对云服务器ECS进行规格选择与性能压测。
相关文章
|
15天前
|
Web App开发 Linux 网络安全
工作中常用到的Linux命令
工作中常用到的Linux命令
|
15天前
|
Web App开发 Java Linux
Linux之Shell基本命令篇
Linux之Shell基本命令篇
Linux之Shell基本命令篇
|
3天前
|
机器学习/深度学习 缓存 监控
linux查看CPU、内存、网络、磁盘IO命令
`Linux`系统中,使用`top`命令查看CPU状态,要查看CPU详细信息,可利用`cat /proc/cpuinfo`相关命令。`free`命令用于查看内存使用情况。网络相关命令包括`ifconfig`(查看网卡状态)、`ifdown/ifup`(禁用/启用网卡)、`netstat`(列出网络连接,如`-tuln`组合)以及`nslookup`、`ping`、`telnet`、`traceroute`等。磁盘IO方面,`iostat`(如`-k -p ALL`)显示磁盘IO统计,`iotop`(如`-o -d 1`)则用于查看磁盘IO瓶颈。
|
12天前
|
NoSQL Linux Shell
常用的 Linux 命令
常用的 Linux 命令
35 9
|
1天前
|
Linux 数据安全/隐私保护
Linux常用命令实例带注释
Linux常用命令实例带注释
13 0
|
1天前
|
Linux 开发工具 数据安全/隐私保护
Linux(19)常用解压命令记录
Linux(19)常用解压命令记录
6 0
|
3天前
|
Linux Perl
Linux系统替换字符串常用命令
请注意,`sed`命令可以非常强大,可以根据不同的需求使用不同的选项和正则表达式来进行更复杂的字符串替换操作。
16 0
|
5天前
|
安全 Linux 开发工具
Linux中可引起文件时间戳改变的相关命令
【4月更文挑战第12天】Linux中可引起文件时间戳改变的相关命令
12 0
|
7天前
|
域名解析 网络协议 Linux
Linux 中的 Nslookup 命令怎么使用?
【4月更文挑战第12天】
25 6
Linux 中的 Nslookup 命令怎么使用?
|
7天前
|
运维 网络协议 Unix
18.系统知识-Linux常用命令
18.系统知识-Linux常用命令