zoukankan      html  css  js  c++  java
  • Linux vmstat命令实战详解

    vmstat命令是最常用也是我最喜爱的Linux/Unix监控工具之一,他可以根据我们给定的时间间隔(秒)和采用次数来展示结果。包括服务器的CPU使用率,内存使用,虚拟内存交换情况,IO读写情况。

     实例:时间间隔2秒。共采集3次

    现在来介绍下各个参数的意思:

    可以参考下man vmstat帮助信息。
    Procs
    r: The number of runnable processes (running or waiting for run time)..--------等待运行时间的进程数量,相当于队列的概念。我当前的数量为4个。队列数过多,说明CPU会比较繁忙。
    b: The number of processes in uninterruptible sleep. -------不间断睡眠中的进程数。
    Memory
    swpd: the amount of virtual memory used.------虚拟内存使用量,如果大于0,表示你的机器物理内存不足了,如果不是程序内存泄露的原因,那么你该升级内存了或者把耗内存的任务迁移到其他机器。
    free: the amount of idle memory.-------空闲的物理内存大小。只是未分配的物理内存,它不是总的可用物理内存大小,实际可用的内存:free+buff+cache-固定不可用的一小部分物理内存。
    buff: the amount of memory used as buffers.------把分配但未使用的一部分物理内存,系统用来做临时写的存储,如:目录里面有什么内容、权限等的缓存。
    cache: the amount of memory used as cache.----把分配但未使用的一部分物理内存拿来做文件和目录的缓存,是为了提高 程序执行的性能,当程序使用内存时,buffer/cached会很快地被使用。
    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).每秒从磁盘读入虚拟内存的大小,如果这个值大于0,表示物理内存不够用或者内存泄露了,要查找耗内存进程解决掉。我的机器内存充裕,属于正常。
    so Amount of memory swapped to disk (/s). 每秒虚拟内存写入磁盘的大小,如果这个值大于0,同上。

    IO
    bi: Blocks received from a block device (blocks/s).——每秒从块设备接收到的块数,即读块设备。
    bo: Blocks sent to a block device (blocks/s).——每秒发送到块设备的块数,即写块设备。如图:当我复制文件,就会产生磁盘io,下图就可以监控到。


    System
    in: The number of interrupts per second, including the clock. -----每秒CPU的中断次数,包括时间中断
    cs: The number of context switches per second.------ 每秒上下文切换次数,例如我们调用系统函数,就要进行上下文切换,线程的切换,也要进程上下文切换,这个值要越小越好,太大了,要考虑调低线程或者进程的数目,例如在apache和nginx这种web服务器中,我们一般做性能测试时会进行几千并发甚至几万并发的测试,选择web服务器的进程可以由进程或者线程的峰值一直下调,压测,直到cs到一个比较小的值,这个进程和线程数就是比较合适的值了。系统调用也是,每次调用系统函数,我们的代码就会进入内核空间,导致上下文切换,这个是很耗资源,也要尽量避免频繁调用系统函数。上下文切换次数过多表示你的CPU大部分浪费在上下文切换,导致CPU干正经事的时间少了,CPU没有充分利用,是不可取的。
    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) -------系统CPU时间,如果太高,表示系统调用时间长,例如是IO操作频繁。
    id: Time spent idle. Prior to Linux 2.5.41, this includes IO-wait time.------空闲时间。在Linux 2.5.41之前,这包括IO等待时间。
    wa: Time spent waiting for IO. Prior to Linux 2.5.41, included in idle.------等待磁盘IO的时间。在Linux 2.5.41之前,包含在空闲时间中。
    st: Time stolen from a virtual machine. Prior to Linux 2.6.11, unknown.------从虚拟机中窃取的时间。在Linux 2.611之前,未知。

  • 相关阅读:
    tornado中form表单验证详解
    关于tornado中session的总结
    Linux常用命令
    css3动画属性详解 与超酷例子
    keepalive高可用的健康检查
    keepalive的nginx防火墙问题
    安装配置hadoop
    tmux的简单快捷键
    部署使用elk
    k8s搭建部署
  • 原文地址:https://www.cnblogs.com/jeson-lbb/p/10053796.html
Copyright © 2011-2022 走看看