各位专家好!
你能帮忙吗。我想计算过去5分钟的CPU负载。我需要永久地得到这些值。
我发现非常有用和详细的文章:http://phoxis.org/2013/09/05/finding-overall-and-per-core-cpu-utilization/
但我不确定检索这些数字的最佳方法是什么:不断地每秒运行脚本,每300次迭代计算一次超额数(例如)?
提前谢谢你!
最佳答案
如果你编写自己的代码来监视使用情况,那么你将面临与海森堡不确定性原理相当的计算问题。或者可以使用“正常运行时间”命令。
% uptime
16:00:29 up 3 days, 18:31, 2 users, load average: 0.04, 0.12, 0.09
最后三个数字是过去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.
只要您知道系统中有多少CPU,这就可以满足您的需要。
第二次迭代:
# cat /proc/uptime
353615.60 344666.42
从/proc手册页:
/proc/uptime
This file contains two numbers: the uptime of the sys-
tem (seconds), and the amount of time spent in idle
process (seconds).
您可以每五分钟轮询一次并记录值的变化。
关于linux - 最近X分钟内的Linux cpu加载,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/29370939/