gpt4 book ai didi

过去 X 分钟的 Linux CPU 负载

转载 作者:太空宇宙 更新时间:2023-11-04 10:54:31 26 4
gpt4 key购买 nike

专家您好!
能否请你帮忙。我想计算过去 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).

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

关于过去 X 分钟的 Linux CPU 负载,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29370939/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com