简体   繁体   中英

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.

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] . 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!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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