问题描述
无论如何,我是否可以交叉链接所有传入用户(CMD 中的 netstat -a)以创建一个监控系统来跟踪 Python 中每个用户使用的 CPU 百分比.Windows 系统是否会在其上写入任何日志文件?我有使用 psutil 的每个进程的 CPU 使用率,但我只是想不出一种方法来显示用户的 CPU 使用率.请我需要帮助.谢谢!
Is there anyway that I can cross link all incoming users (netstat -a in CMD) to create a montior system to track the percentage of CPU used by each of the users in python. Does the Windows system write any log files on that? I have the CPU usage per process using psutil but i just cant figure out a way to display CPU usageby user. Please I need help.Thanks!
推荐答案
无法单独计算每个用户的 CPU 使用率.您可以做的是计算某个用户拥有的进程的 CPU 使用率,如下所示:
It's not possible to figure out CPU usage per-user per-se.What you might do is figure out the CPU usages of processes owned by a certain user as in:
for p in psutil.process_iter():
if p.username == 'someusername':
print p.get_cpu_percent(interval=1)
将所有这些相加以获得总数不太可能产生有意义的值.
Summing all of them in order to obtain a total is unlikely to produce a meaningful value though.
这篇关于User-Python 的系统 CPU 使用率的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!