服务器任务状态报告命令pidstat的几个参数

pidstat 命令是报告Linux任务状态的一个工具。

pidstat 命令可以监控单个或多个由Linux内核所维护的进程情况(使用-p),也可以使用-T监控子线程。另外它还提供时间次数参数,例如每隔n秒刷新一次,运行m次,得到结果。

-C comm
    Display only tasks whose command name includes the string comm.

显示某个名称的进程信息。

-d  Report I/O statistics (kernels 2.6.20 and later only).  The following values are displayed:

    PID: The identification number of the task being monitored.

    kB_rd/s: Number of kilobytes the task has caused to be read from disk per second.

    kB_wr/s: Number of kilobytes the task has caused, or shall cause to be written to disk per second.

    kB_ccwr/s : Number  of  kilobytes  whose  writing  to  disk  has been cancelled by the task.
    This may occur when the task truncates some dirty pagecache.
    In this case, some IO which another task has been accounted for will not be happening.

    Command: The command name of the task.

报告I/O使用情况。

  • PID为进程ID
  • kB_rd/s 磁盘读取速率
  • kB_wr/s 磁盘写入速率
  • kB_cowr/s 取消磁盘写入速率,减少脏页面缓存时会发生
  • Command 命令或应用名称

    -h Display all activities horizontally on a single line.
    This is intended to make it easier to be parsed by other programs.

单行显示所有活动信息,方便其他程序读取

-l  Display the process command name and all its arguments.

显示command的全名

-p  { pid [,...] | SELF | ALL }

定制某个pid,或者本身,或者所有

-r  Report page faults and memory utilization.

    When reporting statistics for individual tasks, the following values are displayed:

        PID: The identification number of the task being monitored.

        minflt/s: Total number of minor faults the task has made per second,
        those which have not required loading a memory page from disk.

        majflt/s: Total number of major faults the task has made per second,
        those which have required loading a memory page from disk.

        VSZ: Virtual Size: The virtual memory usage of entire task in kilobytes.

        RSS: Resident Set Size: The non-swapped physical memory used by the task in kilobytes.

        Command: The command name of the task.


    When reporting global statistics for tasks and all their children, the following values are displayed:

        PID: The identification number of the task which is being monitored together with its children.

        minflt-nr: Total number of minor faults made by the task and all its children,
        and collected during the interval of time.

        majflt-nr: Total number of major faults made by the task and all its children,
        and collected during the interval of time.

        Command: The command name of the task which is being monitored together with its children.

报告系统页错误信息。

当监控独立任务时,显示如下列:

  • PID为进程ID
  • minflt/s 每秒次缺页错误次数(minor page faults),次缺页错误次数意即虚拟内存地址映射成物理内存地址产生的page fault次数
  • majflt/s 每秒主缺页错误次数(major page faults),当虚拟内存地址映射成物理内存地址时,相应的page在swap中,这样的page fault为major page fault,一般在内存使用紧张时产生
  • VSZ 该进程使用的虚拟内存(以kB为单位)
  • RSS 该进程使用的物理内存(以kB为单位)
  • Command 命令或应用名称

当监控全局任务和子线程任务时, 显示如下列:

  • PID为进程ID
  • minflt-nr 在指定的时间间隔内收集的进程和其子进程的次缺页错误次数
  • majflt-nr 在指定的时间间隔内收集的进程和其子进程的主缺页错误次数
  • Command 命令或应用名称
-t  Also display statistics for threads associated with selected tasks.

显示所关联的线程。

-T  { TASK | CHILD | ALL }

TASK是默认的,单个任务的报告。CHILD:指定的进程和他们的子进程的全局报告。ALL:相当于TASK和CHILD

-u  Report CPU utilization.

    When reporting statistics for individual tasks, the following values are displayed:

        PID: The identification number of the task being monitored.

        %usr: Percentage of CPU used by the task while executing at the user level (application),
        with or without nice priority.
        Note that this field does NOT include time spent running a  virtual  processor.

        %system: Percentage of CPU used by the task while executing at the system level (kernel).

        %guest: Percentage of CPU spent by the task in virtual machine (running a virtual processor).

        %CPU: Total percentage of CPU time used by the task.
        In an SMP environment, the task’s CPU usage will be divided by the total number of CPU’s
        if option -I has been entered on the command line.

        CPU: Processor number to which the task is attached.

        Command: The command name of the task.

    When reporting global statistics for tasks and all their children, the following values are displayed:

        PID: The identification number of the task which is being monitored together with its children.

        usr-ms: Total  number of milliseconds spent by the task and all its children
        while executing at the user level (application),
        with or without nice priority, and collected during the interval of time.
        Note that this field does NOT include time spent running a virtual processor.

        system-ms: Total number of milliseconds spent by the task and all its children
        while executing at the system level (kernel), and collected during the interval of time.

        guest-ms: Total number of milliseconds spent by the task and all
        its children in virtual machine (running a virtual processor).

        Command: The command name of the task which is being monitored together with its children.

报告CPU利用率

当监控独立任务时,显示如下列:

  • PID为进程ID
  • %usr 用户层任务正在使用的CPU百分比
  • %system 系统层正在执行的任务的CPU使用百分比
  • %guest 运行虚拟机的CPU占用百分比
  • %CPU 所有的使用的CPU的时间百分比
  • CPU 处理器数量
  • Command 命令或应用名称

当监控全局任务和子线程任务时, 显示如下列:

  • PID为进程ID
  • usr-ms 在指定时间内收集的在用户层执行的进程和它的子进程占用的CPU时间(毫秒)
  • system-ms 在指定时间内收集的在系统层执行的进程和它的子进程占用的CPU时间(毫秒)
  • guest-ms 花在虚拟机上的时间
  • Command 命令或应用名称

    -w Report task switching activity (kernels 2.6.23 and later only). The following values are displayed:

    PID: The identification number of the task being monitored.
    
    cswch/s: Total number of voluntary context switches the task made per second.
    A voluntary context switch occurs when a task blocks because it requires a resource that is unavailable.
    
    nvcswch/s: Total number of non voluntary context switches the task made per second.
    A involuntary context switch takes place when a task executes for the duration of its time slice and then  is  forced
    to relinquish the processor.
    
    Command
    The command name of the task.
    

报告任务切换

  • PID为进程ID
  • cswch/s 每秒自动上下文切换
  • nvcswch/s 每秒非自愿的上下文切换
  • Command 命令或应用名称