Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/linux/22.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
测量Linux上的平均CPU负载(不包括磁盘负载)_Linux_Linux Kernel_Load - Fatal编程技术网

测量Linux上的平均CPU负载(不包括磁盘负载)

测量Linux上的平均CPU负载(不包括磁盘负载),linux,linux-kernel,load,Linux,Linux Kernel,Load,Linux上的平均负载(/proc/loadavg,也由uptime和top等报告)是CPU和磁盘负载的度量: 发件人: 我真的很想为找到一个负载平均指标,即CPU负载(运行队列中的作业数(状态R),不包括等待磁盘I/O的作业(状态d)。有人知道我是否可以得到它吗?简短的回答是“不,你不能。” 以下细节涉及内核版本3.8。一些变量和函数定义的位置随着时间的推移而改变,因此这不适用于最新的内核或早于3.4的内核 计算出的负载平均值存储在一个三槽数组struct taskinfo()中。负载平均值也

Linux上的平均负载(
/proc/loadavg
,也由
uptime
top
等报告)是CPU和磁盘负载的度量:

发件人:

我真的很想为找到一个负载平均指标,即CPU负载(运行队列中的作业数(状态R),不包括等待磁盘I/O的作业(状态d)。有人知道我是否可以得到它吗?

简短的回答是“不,你不能。”

以下细节涉及内核版本3.8。一些变量和函数定义的位置随着时间的推移而改变,因此这不适用于最新的内核或早于3.4的内核


计算出的负载平均值存储在一个三槽数组
struct taskinfo
()中。负载平均值也在另一个三槽数组
averun[3]
中循环,该数组在
kernel/sched/core.c
中定义(请参阅)。不包括等待I/O的线程的负载平均值根本无法计算,因此您必须在
kernel/sched/core.c
中处理如何计算的问题(例如,请参见函数
calc_load_n()
calc_global_nohz
)。

/proc/loadavg是通过跟踪{正在运行的任务数+io等待任务数},采样率为5秒

因此,我认为这是可能的:

如果您只想跟踪正在运行的任务的数量,那么可以制作一个简单的应用程序,定期读取/proc/stat,并在procs_运行时打印出指数移动平均值

   /proc/loadavg
          The first three fields in this file  are  load  average  figures
          giving  the number of jobs in the run queue (state R) or waiting
          for disk I/O (state D) averaged over 1, 5, and 15 minutes.  They
          are  the same as the load average numbers given by uptime(1) and
          other programs.  The fourth field consists of two numbers  sepa-
          rated  by a slash (/).  The first of these is the number of cur-
          rently  executing   kernel   scheduling   entities   (processes,
          threads); this will be less than or equal to the number of CPUs.
          The value after the slash is the  number  of  kernel  scheduling
          entities that currently exist on the system.  The fifth field is
          the PID of the process that was most  recently  created  on  the
          system.