过去X分钟的linux cpu负载

过去X分钟的linux cpu负载,linux,Linux,各位专家好! 你能帮忙吗。我想计算过去5分钟的CPU负载。我需要永久地获得这些值 我发现了一篇非常有用且详细的文章: 但我不确定检索这些数字的最佳方法是什么:每隔一秒不断运行脚本,每300次迭代计算一次超期数(例如)? 提前谢谢你 如果您编写自己的代码来监控使用情况,您将面临与海森堡不确定性原理相当的计算难题。或者,您可以使用“正常运行时间”命令 最后三个数字是过去1、5和15分钟内的系统负载平均值。从手册页: System load averages is the average num

各位专家好!
你能帮忙吗。我想计算过去5分钟的CPU负载。我需要永久地获得这些值

我发现了一篇非常有用且详细的文章:
但我不确定检索这些数字的最佳方法是什么:每隔一秒不断运行脚本,每300次迭代计算一次超期数(例如)?
提前谢谢你

如果您编写自己的代码来监控使用情况,您将面临与海森堡不确定性原理相当的计算难题。或者,您可以使用“正常运行时间”命令

最后三个数字是过去1、5和15分钟内的系统负载平均值。从手册页:

   System load averages is the average number of processes that are
   either in a runnable or uninterruptable state.  A process  in  a
   runnable  state  is  either  using the CPU or waiting to use the
   CPU.  A process in uninterruptable state is waiting for some I/O
   access,  eg  waiting  for disk.  The averages are taken over the
   three time intervals.  Load averages are not normalized for  the
   number  of CPUs in a system, so a load average of 1 means a sin-
   gle CPU system is loaded all the time while on a 4 CPU system it
   means it was idle 75% of the time.
   /proc/uptime
          This file contains two numbers: the uptime of the sys-
          tem  (seconds),  and  the amount of time spent in idle
          process (seconds).
只要您知道系统中有多少CPU,这就可以满足您的需要

第二次迭代:

# cat /proc/uptime
353615.60 344666.42
从/proc手册页:

   System load averages is the average number of processes that are
   either in a runnable or uninterruptable state.  A process  in  a
   runnable  state  is  either  using the CPU or waiting to use the
   CPU.  A process in uninterruptable state is waiting for some I/O
   access,  eg  waiting  for disk.  The averages are taken over the
   three time intervals.  Load averages are not normalized for  the
   number  of CPUs in a system, so a load average of 1 means a sin-
   gle CPU system is loaded all the time while on a 4 CPU system it
   means it was idle 75% of the time.
   /proc/uptime
          This file contains two numbers: the uptime of the sys-
          tem  (seconds),  and  the amount of time spent in idle
          process (seconds).

您可以每五分钟轮询一次,并记录值的变化。

基本上,我会以%为单位监视上一次的平均CPU利用率。由于I/O等待时间的原因,处于不间断状态的进程可能处于该状态。这意味着进程正在等待磁盘I/O。但这并不意味着CPU正忙。换句话说,CPU只需查看进程并等待它何时可以移动到可运行队列。如果我弄错了,请纠正我:)我想知道这一点,这就是我检查手册页的原因。当我读取提取的位时,“
平均负载为1意味着单个CPU系统始终处于加载状态”
,这似乎解决了这个问题?虽然这应该是单核系统,而不是单CPU系统。艾伦,你能告诉我你到底读了什么手册吗?:)my man proc说:/proc/loadavg此文件中的前三个字段是负载平均数,给出了运行队列(状态R)或等待磁盘I/O(状态D)的作业数平均超过1、5和15分钟。第四个字段由斜杠(/)分隔的两个数字组成。第一个是当前执行的内核调度实体(进程、线程)的数量;这将小于或等于CPU的数量。斜杠后面的值是系统上当前存在的内核调度实体的数量。我引用的两个手册页是
man正常运行时间
man进程
。我用的是Debian气喘模型。