Linux性能监控指令vmstat

一、概述

监控通常分为机器监控和服务监控,机器监控是基础监控,目的是为了获得系统当前的运行状态,服务监控则是主要目的,也是最应该关心的监控,机器监控也是为了更好的服务监控而存在,简单来说,服务监控和系统上部署的具体服务有关,但监控模式可以统一。

监控是为了获得相关的目标数据,获得数据是为了异常情况下作出分析,分析的目的是为了解决线上case以及性能调优。这基本上就是监控存在的意义了。一台线上服务器的机器监控,基本上可以分成四大类:cpu监控、磁盘容量监控、IO监控和网卡监控。不同业务将会导致服务器不同的瓶颈,应该视具体业务而言。本文主要讨论Linux下常见的获得cpu状态的命令行:vmstat。

二、使用详解

在使用指令之前,应该明白监控的具体内容以及含义。cpu监控分为两种:cpu使用率和IPC/CPI,两者的应用场景也不相同,通常使用的是cpu使用率监控,基本上操作系统都会提供,而IPC/CPI监控则需要性能专家的协助,操作系统上基本没有相关的指令。

非计算密集型只需要监控cpu的使用率,而cpu的使用率需要关注用户态cpu使用率和系统态cpu使用率,前者表示系统上运行业务获得cpu的执行时间占总cpu时间的百分比,后者表示系统获得cpu时间的百分比。对用户而言,用户态cpu百分比为100%是最理想的状况,但这通常不可能,当出现程序调度、线程上下文切换以及IO交互的时候,系统态cpu使用率会较多的增长。应当明确的是,应用消耗很多CPU并不意味着性能或者扩展性达到了最高或瓶颈。如果长时间出现系统态cpu使用率居高不下,那么就需要关注,有可能是程序写的不优雅,有可能是磁盘即将损坏导致IO消耗时间过长,这时候就需要cpu监控从而分析得出结果。

对计算密集型应用来首,只监控cpu使用率是不够的,还需要监控IPC(每时钟指令数)或CPI(每指令时钟周期)。为什么需要知道这一项数据?IPC或CPI都可以反映了没有指令被执行的时候占用cpu时钟周期的百分比,简而言之就是CPU等待指令从内存中装入寄存器消耗时间的百分比,即停滞(stall)。停滞——当cpu执行指令而所用到的操作数不在寄存器或缓存中并且当前钟周期还未失效时,cpu就需要停滞等待数据从内存中装入寄存器,停滞一旦发生,通常会浪费几百个cpu时钟周期。要想提高计算密集型应用的性能,就需要获得IPC/CPI监控数据,减少停滞减少cpu等待内存数据时间或改善高速缓存。

1. vmstat用法

[work@localhost ~]$ vmstat –helpusage: vmstat [-V] [-n] [delay [count]] -V prints version. -n causes the headers not to be reprinted regularly. -a print inactive/active page stats. -d prints disk statistics -D prints disk table -p prints disk partition statistics -s prints vm table -m prints slabinfo -t add timestamp to output -S unit size delay is the delay between updates in seconds. unit size k:1000 K:1024 m:1000000 M:1048576 (default is K) count is the number of updates.

2. vmstat示例

[work@localhost ~]$ vmstat 1procs ———–memory———- —swap– —–io—- –system– —–cpu—–r b swpd free buff cache si so bi bo in cs us sy id wa st0 0 0 56400 43444 324868 0 0 20 14 28 45 0 0 99 1 00 0 0 56400 43452 324864 0 0 0 48 36 58 0 0 98 2 00 0 0 56400 43452 324868 0 0 0 0 22 34 0 0 100 0 00 0 0 56400 43452 324868 0 0 0 0 34 48 0 1 99 0 01 0 0 56400 43452 324868 0 0 0 0 22 31 0 1 99 0 00 0 0 56400 43452 324868 0 0 0 0 31 48 0 0 100 0 00 0 0 56400 43452 324868 0 0 0 0 129 163 3 1 96 0 00 0 0 56400 43452 324868 0 0 0 0 35 56 0 2 98 0 00 0 0 56400 43452 324868 0 0 0 0 22 32 0 0 100 0 00 0 0 56400 43452 324868 0 0 0 0 58 61 0 0 100 0 00 0 0 56400 43452 324868 0 0 0 0 24 38 0 1 99 0 0

3. vmstat详解

vmstat 1:表示每隔一秒钟采集、展示一次数据,要想停下来Ctrl+d即可,如果想指定采集次数,则使用“vmstat 1 10″,表示每隔一秒钟采集一次数据,总共采集10次。

procs:

酒般的思念,一饮就醉,醉时就用全部的热情读这忧伤的月色,

Linux性能监控指令vmstat

相关文章:

你感兴趣的文章:

标签云: