问题
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