zoukankan      html  css  js  c++  java
  • cpu监控:mpstat命令

    mpstat是MultiProcessor Statistics的缩写,是实时系统监控工具。报告CPU的一些统计信息,这些信息存放在/proc/stat文件中。在多CPUs系统里,其不但能查看所有CPU的平均状况信息,而且能够查看特定CPU的信息。

    语法:

          mpstat [-P {|ALL}] [internal [count]]

    参数:

        (1)-P {|ALL}:表示监控哪个CPU,在[0,cpu个数-1]中取值;

        (2)internal:相邻的两次采样的间隔时间;

        (3)count:采样的次数,count只能和delay一起使用;

          备注:当没有参数时,mpstat则显示系统启动以后所有信息的平均值。有interval时,第一行的信息自系统启动以来的平均信息。从第二行开始,输出为前一个interval时间段的平均信息。

    [root@node01 ~]# yum install sysstat -y

    示例:

    (1)显示所有的CPU信息:mpstat -P ALL 1(间隔为1s)

    [root@node01 ~]# mpstat -P ALL 1
    Linux 3.10.0-693.el7.x86_64 (node01)    2020年03月17日  _x86_64_        (1 CPU)
    
    20时38分38秒  CPU    %usr   %nice    %sys %iowait    %irq   %soft  %steal  %guest  %gnice   %idle
    20时38分39秒  all    0.00    0.00    0.00    0.00    0.00    0.00    0.00    0.00    0.00  100.00
    20时38分39秒    0    0.00    0.00    0.00    0.00    0.00    0.00    0.00    0.00    0.00  100.00
    
    20时38分39秒  CPU    %usr   %nice    %sys %iowait    %irq   %soft  %steal  %guest  %gnice   %idle
    20时38分40秒  all    0.00    0.00    0.00    0.00    0.00    0.00    0.00    0.00    0.00  100.00
    20时38分40秒    0    0.00    0.00    0.00    0.00    0.00    0.00    0.00    0.00    0.00  100.00
    
    20时38分40秒  CPU    %usr   %nice    %sys %iowait    %irq   %soft  %steal  %guest  %gnice   %idle
    20时38分41秒  all    0.00    0.00    0.00    0.00    0.00    0.00    0.00    0.00    0.00  100.00
    20时38分41秒    0    0.00    0.00    0.00    0.00    0.00    0.00    0.00    0.00    0.00  100.00
    
    20时38分41秒  CPU    %usr   %nice    %sys %iowait    %irq   %soft  %steal  %guest  %gnice   %idle
    20时38分42秒  all    0.00    0.00    0.99    0.00    0.00    0.00    0.00    0.00    0.00   99.01
    20时38分42秒    0    0.00    0.00    0.99    0.00    0.00    0.00    0.00    0.00    0.00   99.01
    
    20时38分42秒  CPU    %usr   %nice    %sys %iowait    %irq   %soft  %steal  %guest  %gnice   %idle
    20时38分43秒  all    0.00    0.00    0.00    0.00    0.00    0.00    0.00    0.00    0.00  100.00
    20时38分43秒    0    0.00    0.00    0.00    0.00    0.00    0.00    0.00    0.00    0.00  100.00
    
    20时38分43秒  CPU    %usr   %nice    %sys %iowait    %irq   %soft  %steal  %guest  %gnice   %idle
    20时38分44秒  all    0.00    0.00    0.00    0.00    0.00    0.00    0.00    0.00    0.00  100.00
    20时38分44秒    0    0.00    0.00    0.00    0.00    0.00    0.00    0.00    0.00    0.00  100.00
    
    20时38分44秒  CPU    %usr   %nice    %sys %iowait    %irq   %soft  %steal  %guest  %gnice   %idle
    20时38分45秒  all    0.00    0.00    0.00    0.00    0.00    0.00    0.00    0.00    0.00  100.00
    20时38分45秒    0    0.00    0.00    0.00    0.00    0.00    0.00    0.00    0.00    0.00  100.00
    
    20时38分45秒  CPU    %usr   %nice    %sys %iowait    %irq   %soft  %steal  %guest  %gnice   %idle
    20时38分46秒  all    0.00    0.00    1.00    0.00    0.00    0.00    0.00    0.00    0.00   99.00
    20时38分46秒    0    0.00    0.00    1.00    0.00    0.00    0.00    0.00    0.00    0.00   99.00
    ^C
    
    平均时间:  CPU    %usr   %nice    %sys %iowait    %irq   %soft  %steal  %guest  %gnice   %idle
    平均时间:  all    0.00    0.00    0.25    0.00    0.00    0.00    0.00    0.00    0.00   99.75
    平均时间:    0    0.00    0.00    0.25    0.00    0.00    0.00    0.00    0.00    0.00   99.75

    2)显示ID为1的CPU信息:mpstat -P 1 1(间隔为1s)

    结果说明:

    (1)user:在internal时间段里,用户态的CPU时间(%),不包含nice值为负进程,值为 (usr/total)*100;

    (2)nice:在internal时间段里,nice值为负进程的CPU时间(%),值为(nice/total)*100;

    (3)system:在internal时间段里,核心时间(%),值为(system/total)*100;

    (4)iowait:在internal时间段里,硬盘IO等待时间(%),值为(iowait/total)*100;

    (5)irq:在internal时间段里,硬中断时间(%),值为(irq/total)*100;

    (6)soft:在internal时间段里,软中断时间(%),值为(softirq/total)*100;

    (7)idle:在internal时间段里,CPU除去等待磁盘IO操作外的因为任何原因而空闲的时间闲置时间(%),值为(idle/total)*100;

    (8)intr/s:在internal时间段里,每秒CPU接收的中断的次数,值为(intr/total)*100;

    它显示了系统中 CPU 的各种统计信息。–P ALL 选项指示该命令显示所有 CPU 的统计信息, 
    而不只是特定 CPU 的统计信息。参数 5 2 指示该命令每隔 5 秒运行一次,共运行 2 次。 
    以上输出首先显示了所有 CPU 的合计指标,然后显示了每个 CPU 各自的指标。最后,在结尾处显示所有 CPU 的平均值。 

    让我们看一看这些列值的含义: 

    %user 表示处理用户进程所使用 CPU 的百分比。用户进程是用于应用程序(如 Oracle 数据库)的非内核进程。 
    在本示例输出中,用户 CPU 百分比非常低。 

    %nice 表示使用 nice 命令对进程进行降级时 CPU 的百分比。在之前的部分中已经对 nice 命令进行了介绍。简单来说,nice 命令更改进程的优先级。 

    %system 表示内核进程使用的 CPU 百分比 

    %iowait 表示等待进行 I/O 所使用的 CPU 时间百分比 

    %irq 表示用于处理系统中断的 CPU 百分比 

    %soft 表示用于软件中断的 CPU 百分比 

    %idle 显示 CPU 的空闲时间 

    %intr/s 显示每秒 CPU 接收的中断总数 

    当您拥有前面所述的 vmstat 时,您可能想知道 mpstat 命令的作用。差别很大:mpstat 可以显示每个处理器的统计, 
    而 vmstat 显示所有处理器的统计。因此,编写糟糕的应用程序(不使用多线程体系结构)可能会运行在一个多处理器机器上, 
    而不使用所有处理器。从而导致一个 CPU 过载,而其他 CPU 却很空闲。通过 mpstat 可以轻松诊断这些类型的问题。 

    针对 Oracle 用户的用法 
    与 vmstat 相似,mpstat 命令还产生与 CPU 有关的统计信息,因此所有与 CPU 问题有关的讨论也都适用于 mpstat。 
    当您看到较低的 %idle 数字时,您知道出现了 CPU 不足的问题。当您看到较高的 %iowait 数字时, 
    您知道在当前负载下 I/O 子系统出现了某些问题。该信息对于解决 Oracle 数据库性能问题非常方便。

  • 相关阅读:
    C语言I博客作业09
    请看这里
    C++ 面向对象学习笔记[1]
    graphviz的使用
    KDE安装后的一些随笔
    近期内容整理
    链表
    理解C++ lvalue与rvalue
    再看“笕实智慧校园”——作品的复盘[1]
    无题
  • 原文地址:https://www.cnblogs.com/liujunjun/p/12513231.html
Copyright © 2011-2022 走看看