简体   繁体   English

如何通过psutil获取磁盘IO和网络使用百分比

[英]How to get disk IO and network usage as percent by psutil

Is there a way to get disk IO and network usage as a percentage by psutil. 有没有办法通过psutil获取磁盘IO和网络使用百分比。

I found some useful function. 我发现了一些有用的功能。 But I don't know, how to get as a percentage using 但我不知道,如何使用百分比

psutil.disk_io_counters()

psutil.net_io_counters()

You can get the result as a percentage if you follow this method: 如果您遵循此方法,您可以获得结果百分比:

import psutil
n_c = tuple(psutil.disk_io_counters())
n_c = [(100.0*n_c[i+1]) / n_c[i] for i in xrange(0, len(n_c), 2)]
print n_c

For my system, the output was [18.154375810797326, 40.375844302056244, 40.33502202082432] . 对于我的系统,输出为[18.154375810797326, 40.375844302056244, 40.33502202082432] Each index is a percentage of write upon read data. 每个索引是读取数据的写入百分比。 Eg n_c[0] is the percentage write_count/read_count and n_c[1] is the percentage write_bytes/read_bytes Similarly you can get percentage data for net_io_counters(). 例如, n_c[0]是百分比write_count/read_countn_c[1]是百分比write_bytes/read_bytes同样,您可以获得net_io_counters()的百分比数据。 Hope this helps! 希望这可以帮助!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM