当前位置:首页>微思动态 > >详情
全国热线电话 400-881-4699

在线留言

性能监控之 vmstat 命令

发布作者:微思网络   发布时间:2022-06-14   浏览量:0

说明

vmstat 命令报告虚拟内存(vm,virtual memory)的统计信息; 包括: memory(内存)、paging(分页)、block IO(块I/O)、traps(陷阱,捕获信号量)、disks(磁盘)、CPU
注意: 如果直接执行该命令,该命令所输出的结果是"自上次重启以来系统的平均值",而不是即时信息; 如系统提示未安装该命令,可以使用 yum install sysstat 进行安装



命令示例: 查看CPU、内存、交换空间

直接运行 vmstat, 显示自上一次启动以来的平均值

[root@localhost ~]# vmstat
procs -----------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 1254496 2108 420676 0 0 63 16 53 88 0 1 99 0 0


常用的选项

[root@localhost ~]# vmstat 1 5 -t -SM
procs -----------memory---------- ---swap-- -----io---- -system-- ------cpu----- -----timestamp-----
r b swpd free buff cache si so bi bo in cs us sy id wa st CST
1 0 0 1221 2 414 0 0 48 12 45 74 0 0 99 0 0 2022-06-13 00:00:28
0 0 0 1221 2 414 0 0 0 0 53 59 0 0 100 0 0 2022-06-13 00:00:29
0 0 0 1221 2 414 0 0 0 0 51 63 0 0 100 0 0 2022-06-13 00:00:30
0 0 0 1221 2 414 0 0 0 0 30 47 0 0 100 0 0 2022-06-13 00:00:31
0 0 0 1221 2 414 0 0 0 16 50 67 0 0 100 0 0 2022-06-13 00:00:32
[root@localhost ~]#


命令解析:

  • 1 5 表示每间隔 1 秒钟输出一次,总共输出5次

  • -t 给输出结果加上时间戳

  • -SM 以 MB 格式显示结果, 但注意 si/so 和 bi/bo 字段不会被转换


命令输出字段说明:

procs

r 可运行进程的数量(正在运行或等待运行)

b 正在等待 I/O 完成,被阻塞的进程数

memory

swpd 使用的交换空间大小

free 空闲的内存大小

buff 写缓存的大小

cache 读缓存的大小

inact 使用 -a 选项才能看到; 非活动内存大小

active 使用 -a 选项才能看到; 活动内存大小

swap

si 每秒从磁盘换入的内存大小(内存-->磁盘)

so 每秒从磁盘换出的内存大小(磁盘-->内存)

io

bi 每秒从块设备接收的数据,单位 block

bo 每秒从块设备发送的数据,单位 block

system

in 每秒的中断(interrupts)数,包括CPU时钟

cs 每秒上下文切换的次数

cpu

单位是:

CPU 总时间的百分比

us 运行用户空间代码所花费的时间

sy 运行内核空间代码所花费的时间

id 空闲时间

wa 等待 I/O 所花费的时间

st 被虚拟机管理程序(hypervisor) 偷走/占用的时间



命令示例: 查看磁盘

运行 vmstat -d, 显示磁盘的信息

[root@localhost ~]# vmstat -d
disk- ------------reads------------ ------------writes----------- -----IO------
total merged sectors ms total merged sectors ms cur sec
sda 128219 311783 26540827 522666 112106 684257 62065814 2601710 0 120
sr0 18 0 2056 24 0 0 0 0 0 0
dm-0 37521 0 23293093 512357 106892 0 56519013 2272446 0 103
dm-1 401396 0 3214872 47107 689435 0 5515480 37977580 0 29
[root@localhost ~]#


命令输出字段说明:

reads

total 总读取数

merged 分组读取(产生一个I/O)

sectors 读取的扇区数

ms 读取所花费的毫秒数

writes

total 总写入数

merged 分区写入(产生一个I/O)

sectors 写入的扇区数

ms 写入所花费的毫秒数

IO

cur 正在进行的 I/O 数

sec I/O 所花费的秒数


其他选项: 显示统计信息, 使用 -s 选项

[root@localhost ~]# vmstat -s -SM
       1819 M total memory
        125 M used memory
         12 M active memory
         47 M inactive memory
       1621 M free memory
          0 M buffer memory
         72 M swap cache
       2047 M total swap
         51 M used swap
       1996 M free swap
      20300 non-nice user cpu ticks
          3 nice user cpu ticks
      16830 system cpu ticks
    1389285 idle cpu ticks
       2310 IO-wait cpu ticks
          0 IRQ cpu ticks
        579 softirq cpu ticks
          0 stolen cpu ticks
   13274181 pages paged in
   31033155 pages paged out
     401584 pages swapped in
     689435 pages swapped out
    2156168 interrupts
    2183998 CPU context switches
 1655045882 boot time
      31517 forks
[root@localhost ~]#




返回顶部