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

╄→гoц情女王★ 提交于 2020-01-03 17:01:35

问题


Is there a way to get disk IO and network usage as a percentage by psutil.

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()

回答1:


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]. 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(). Hope this helps!



来源:https://stackoverflow.com/questions/31860163/how-to-get-disk-io-and-network-usage-as-percent-by-psutil

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!