从 /proc/stat 计算 user、nice、sys、idle、iowait、irq 和 Sirq
/proc/stat 显示 user、nice、sys、idle、iowait、irq 和 Sirq 的刻度,如下所示:
cpu 6214713 286 1216407 121074379 260283 253506 197368 0 0 0
如何计算各个利用率(在%) 对于用户来说,这些值很好等吗?就像“top”或“vmstat”中显示的值一样。
/proc/stat shows ticks for user, nice, sys, idle, iowait, irq and sirq like this:
cpu 6214713 286 1216407 121074379 260283 253506 197368 0 0 0
How can I calculate the individual utilizations (in %) for user, nice etc with these values? Like the values that shows in 'top' or 'vmstat'.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
此代码计算所有核心上的用户利用率分布。
This code calculates user utilization spread over all cores.
来自
Documentation/filesystems/proc.txt
:因此,要计算利用率百分比,您需要:
USER_HZ
第二个很简单:同一个文件中有一个
btime
行,您可以使用它。对于USER_HZ
,请查看 如何获取每 jiffy 的毫秒数。From
Documentation/filesystems/proc.txt
:So to figure out utilization in terms of percentages you need to:
USER_HZ
is on the machineThe second one is easy: there is a
btime
line in that same file which you can use for that. ForUSER_HZ
, check out How to get number of mili seconds per jiffy.