如何通过psutil获取磁盘IO和网络使用率百分比 [英] How to get disk IO and network usage as percent by psutil

查看:1232
本文介绍了如何通过psutil获取磁盘IO和网络使用率百分比的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有一种方法可以通过psutil获取磁盘IO和网络使用率的百分比.

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

对于我的系统,输出为[18.154375810797326, 40.375844302056244, 40.33502202082432].每个索引都是读取数据后写入的百分比.例如,n_c[0]是百分比write_count/read_count,而n_c[1]是百分比write_bytes/read_bytes同样,您可以获取net_io_counters()的百分比数据.希望这会有所帮助!

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!

这篇关于如何通过psutil获取磁盘IO和网络使用率百分比的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆