pidstat 统计进程、线程、进程组的资源消耗

标签

PostgreSQL , Linux , pidstat


背景

如果我们要查看Linux下面进程、进程组、线程的资源消耗的统计信息,可以使用pidstat,它可以收集并报告进程的统计信息。

pidstat实际上也是将/proc/pid下的统计信息统筹后展现给用户。

pidstat例子

1. 列出IO统计信息:-d

2. 列出内存使用统计,page fault:-r

3. CPU统计信息:-u

4. 上下文切换统计信息:-w

5. 指定输出的维度

指定命令: -C command

指定进程号:-p { pid [,...] | SELF | ALL }

将所有列输出到单行、便于导入单张表中:-h

按每个CPU核的统计:-I

按所有CPU核统计:默认

列出命令的完整内容,包括参数:-l

列出线程统计信息:-t

按进程维度单独统计、按进程全局+子进程单独统计、按进程全局、单独统计同时按子任务单独统计:-T { TASK | CHILD | ALL }

实例,统计5秒的值并输出

#pidstat -d -r -u -w -l -h -p ALL 5 1|less  

#      Time       PID    %usr %system  %guest    %CPU   CPU  minflt/s  majflt/s     VSZ    RSS   %MEM   kB_rd/s   kB_wr/s kB_ccwr/s   cswch/s nvcswch/s  Command
 1488541252         1    0.00    0.00    0.00    0.00     0      0.00      0.00   19348   1512   0.00      0.00      0.00      0.00      0.00      0.00  /sbin/init
 1488541252         2    0.00    0.00    0.00    0.00    50      0.00      0.00       0      0   0.00      0.00      0.00      0.00      0.00      0.00  kthreadd
 1488541252         3    0.00    0.00    0.00    0.00     0      0.00      0.00       0      0   0.00      0.00      0.00      0.00      0.59      0.00  migration/0
 1488541252         4    0.00    0.00    0.00    0.00     0      0.00      0.00       0      0   0.00      0.00      0.00      0.00      0.00      0.00  ksoftirqd/0
 1488541252         5    0.00    0.00    0.00    0.00     0      0.00      0.00       0      0   0.00      0.00      0.00      0.00      0.00      0.00  migration/0
 1488541252         6    0.00    0.00    0.00    0.00     0      0.00      0.00       0      0   0.00      0.00      0.00      0.00      0.00      0.00  watchdog/0  

 ......  

 1488541264     18523    0.00    0.20    0.00    0.20     5     10.78      0.00 137774940 3002232   0.57      0.00      0.00      0.00      1.96      0.20  /home/digoal/pgsql9.6/bin/postgres
 1488541264     18549    0.00    0.00    0.00    0.00    61      0.00      0.00  140892   2028   0.00      0.00      0.00      0.00      0.00      0.00  postgres: logger process
 1488541264     18552    0.00    0.00    0.00    0.00     0      0.00      0.00 137779116 5509520   1.04      0.00      0.00      0.00      0.00      0.00  postgres: checkpointer process
 1488541264     18554    0.00    0.00    0.00    0.00    20      0.00      0.00 137776328 1058572   0.20      0.00      0.00      0.00      3.92      0.00  postgres: writer process
 1488541264     18556    0.00    0.00    0.00    0.00    15      0.00      0.00 137774940  19120   0.00      0.00      0.00      0.00      3.92      0.00  postgres: wal writer process
 1488541264     18557    0.00    0.00    0.00    0.00    21      2.94      0.00 137779092   3404   0.00      0.00      0.00      0.00      3.92      0.00  postgres: autovacuum launcher process
 1488541264     18559    0.00    0.00    0.00    0.00    11      0.00      0.00  142988   2092   0.00      0.00      0.00      0.00      0.00      0.00  postgres: archiver process   last was 0000000100000030000000B2
 1488541264     18561    0.00    0.00    0.00    0.00    53      4.90      0.00  143556   2624   0.00      0.00    317.65    317.65      4.12      0.20  postgres: stats collector process

参考

man pidstat

PIDSTAT(1)                    Linux User’s Manual                   PIDSTAT(1)  

NAME
       pidstat - Report statistics for Linux tasks.  

SYNOPSIS
       pidstat [ -C comm ] [ -d ] [ -h ] [ -I ] [ -l ] [ -p { pid [,...] | SELF | ALL } ] [ -r ] [ -t ] [ -T { TASK | CHILD | ALL } ] [ -u ] [ -V ] [ -w ] [ interval [ count ] ]  

DESCRIPTION
       The  pidstat  command  is  used for monitoring individual tasks currently being managed by the Linux kernel.  It writes to standard output activities for every task selected with option -p or for every task
       managed by the Linux kernel if option -p ALL has been used. Not selecting any tasks is equivalent to specifying -p ALL but only active tasks (tasks with  non-zero  statistics  values)  will  appear  in  the
       report.  

       The pidstat command can also be used for monitoring the child processes of selected tasks.  Read about option -T below.  

       The  interval  parameter  specifies  the  amount  of time in seconds between each report.  A value of 0 (or no parameters at all) indicates that tasks statistics are to be reported for the time since system
       startup (boot).  The count parameter can be specified in conjunction with the interval parameter if this one is not set to zero. The value of count determines the number of  reports  generated  at  interval
       seconds apart. If the interval parameter is specified without the count parameter, the pidstat command generates reports continuously.  

       You can select information about specific task activities using flags.  Not specifying any flags selects only CPU activity.  

OPTIONS
       -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.  

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

       -I     In an SMP environment, indicate that tasks CPU usage (as displayed by option -u ) should be divided by the total number of processors.  

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

       -p { pid [,...] | SELF | ALL }
              Select tasks (processes) for which statistics are to be reported.  pid is the process identification number. The SELF keyword indicates that statistics are to be  reported  for  the  pidstat  process
              itself, whereas the ALL keyword indicates that statistics are to be reported for all the tasks managed by the system.  

       -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.  

       -t     Also display statistics for threads associated with selected tasks.  

              This option adds the following values to the reports:  

              TGID
                     The identification number of the thread group leader.  

              TID
                     The identification number of the thread being monitored.  

       -T { TASK | CHILD | ALL }
              This  option  specifies  what  has  to be monitored by the pidstat command. The TASK keyword indicates that statistics are to be reported for individual tasks (this is the default option) whereas the
              CHILD keyword indicates that statistics are to be globally reported for the selected tasks and all their children. The ALL keyword indicates that statistics are to be reported  for  individual  tasks
              and globally for the selected tasks and their children.  

              Note:  Global statistics for tasks and all their children are not available for all options of pidstat.  Also these statistics are not necessarily relevant to current time interval: The statistics of
              a child process are collected only when it finishes or it is killed.  

       -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.  

       -V     Print version number then exit.  

       -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.  

ENVIRONMENT
       The pidstat command takes into account the following environment variable:  

       S_TIME_FORMAT
              If  this  variable  exists  and  its  value  is ISO then the current locale will be ignored when printing the date in the report header.  The pidstat command will use the ISO 8601 format (YYYY-MM-DD)
              instead.  

EXAMPLES
       pidstat 2 5
              Display five reports of CPU statistics for every active task in the system at two second intervals.  

       pidstat -r -p 1643 2 5
              Display five reports of page faults and memory statistics for PID 1643 at two second intervals.  

       pidstat -T CHILD -r 2 5
              Display five reports of page faults statistics at two second intervals for the child processes of all tasks in the system. Only child processes with non-zero statistics values are displayed.  

BUGS
       /proc filesystem must be mounted for the pidstat command to work.  

FILES
       /proc contains various files with system statistics.  

AUTHOR
       Sebastien Godard (sysstat <at> orange.fr)  

SEE ALSO
       sar(1), top(1), ps(1), mpstat(1), iostat(1), vmstat(8)  

       http://pagesperso-orange.fr/sebastien.godard/  

Linux                            DECEMBER 2008                      PIDSTAT(1)

http://linoxide.com/linux-command/linux-pidstat-monitor-statistics-procesess/

http://www.cnblogs.com/ggjucheng/archive/2013/01/13/2858874.html

http://www.2cto.com/os/201306/217190.html

其他

mpstat  

vmstat  

top  

sar  

iostat  

dstat  

ps  
时间: 2024-09-13 07:40:01

pidstat 统计进程、线程、进程组的资源消耗的相关文章

进程 线程-进程与线程的区别????

问题描述 进程与线程的区别???? 进程与线程的区别??????????????????????????????????? 解决方案 一个进程可以开辟多个线程,线程是进程的子集 解决方案二: 操作系统将内存资源分配给进程,操作系统在进程下执行线程,一个进程下可以有多个线程.

1线程概念:线程和进程之间的关系,线程间可共享资源,线程间非共享资源,线程的优缺点

 1线程概念 1.1什么是线程 1.1.2线程和进程的关系         1.轻量级进程(light-weightprocess),也有PCB,创建线程使用底层函数和进程一样,都是clone. 2.从内核里看进程和线程是一样的,都有各自不同的PCB,但是PCB中指向内存资源的三级页表示相同的 3.进程可以蜕变成线程 4.在美国人眼里,线程就是寄存器和栈 5.在Linux下,线程是最小的执行单位:进程是最小的分配资源的单位   查看LWP号(通过这个命令可以查看到线程号),命令是: ps –

DB2的进程/线程解析

今天看到一个名词,数据库实例用户和实例隔离用户,那么什么是实例隔离用户呢,于是搜索以下,就涉及到了进程. 援引DB2中国上面的回答:   要理解DB2的fenced user, 需要先理解db2的fenced process.   DB2在V95之后从多进程模式改为多线程模式,也就是说绝大部分数据库核心程序都运行在db2sysc这个进程中.这种单进程多线程的架构改善了性能,但是同时增加了运行"不安全代码"带来的风险.因为大家都运行在一个进程里,任何一段不安全的代码出现问题会导致整个DB

opengl-linux api为什么只有内存 线程 进程 文件方面的?

问题描述 linux api为什么只有内存 线程 进程 文件方面的? 1.那么界面是不是要靠OpenGL? QT底层是OpenGL实现的吗?2.我如果不需要好的界面,只有API能实现任何功能吗?还是得学些别的? 解决方案 终极解答:1. 图形界面GUI,有很多不同的实现库,而且分很多层逐级实现,例如你说的QT界面库,它在不同的操作系统平台上底层依赖的更基础的图形库也不同,在Windows平台依赖GDI32.dll,在嵌入式平台可能依赖于fb,也可能依赖于XWindow.至于OpenGL是一个相当

并发性-Web服务器的最大并发数和进程线程的关系疑问

问题描述 Web服务器的最大并发数和进程线程的关系疑问 刚才看了一篇关于进程线程的文章,一个进程会分配2G可用内存,一个线程默认会分配1M内存.那么一个进程最多能产生2000左右的线程数.那么一个web服务器(Tomcat)中一个请求过来,就会创建一个线程来处理,理论上不是只能最多处理2000并发请求了?而nginx好像可以处理更大并发(上万个).这是怎么实现的(不是每个请求生成一个线程?)?另外一个进程会分配2G可用内存是不是绝对的?还是只针对32位系统,64位是不是不止这个大小. 请高手指点

urlproc.exe是什么进程?进程结束与删除的方法

urlproc.exe是360浏览器的安全红绿灯扩展程序文件,只要电脑中安装有360浏览器,并且随浏览器启动一起启动. urlproc.exe进程作用: 通过安全红绿灯能有效拦截挂马带毒.钓鱼.欺诈等威胁网站,同时可以进行修复浏览器.清理浏览痕迹.启动无痕浏览.启动隔离模式等操作,并能有效保护上网安全. 安全红绿灯拦截技术: URL拦截层:360安全浏览器的URL拦截应用了网页搜索技术,定位挂马.钓鱼.欺诈网址.这种依靠恶意网址库的拦截方式十分快速.准确,并且其资源消耗由360后台的服务器承担,

IBM MQ 错误日志:调用 MQ 错误记录例程,失败的进程是进程 4780

问题描述 -----amqxfdcp.c:815--------------------------------------------------------2013/2/1816:31:39-Process(4780.7859)User(MUSR_MQADMIN)Program(amqzlaa0.exe)Host(FTPSERVER)AMQ6119:发生了内部WebSphereMQ错误(Rc=112fromSetEndOfFile)说明:MQ检测到调用操作系统时发生的意外错误.调用MQ错误记

杀死Linux中的defunct进程(僵尸进程)的方法指南

一.什么是defunct进程(僵尸进程)在 Linux  系统中,一个进程结束了,但是他的父进程没有等待(调用wait /  waitpid)他,那么他将变成一个僵尸进程.当用ps命令观察进程的执行状态时,看到这些进程的状态栏为defunct.僵尸进程是一个早已死亡的进程,但在进程表(processs  table)中仍占了一个位置(slot).但是如果该进程的父进程已经先结束了,那么该进程就不会变成僵尸进程.因为每个进程结束的时候,系统都会扫描当前系统中所运行的所有进程,看看有没有哪个进程是刚

AIX/LINUX系统中如何查看单个进程在os层面的内存消耗

--如何查看单个进程在os层面的内存消耗 AIX: $ svmon -Pt10 | perl -e 'while(<>){print if($.==2||$&&&!$s++);$.=0 if(/^-+$/)}' ---- -用这个可以看最大的占用内存的10个进程 ------------------------------------------------------------------------------- Pid Command Inuse Pin Pgs