host.py 文件源码

python
阅读 22 收藏 0 点赞 0 评论 0

项目:webkvmmgr 作者: crazw 项目源码 文件源码
def get_rx_tx(self, itface):
        try:
            cmd_rx = "cat /sys/class/net/%s/statistics/rx_bytes" % itface
            cmd_tx = "cat /sys/class/net/%s/statistics/tx_bytes" % itface
            data_rx_prev = commands.getoutput(cmd_rx)
            data_tx_prev = commands.getoutput(cmd_tx)

            time.sleep(1)
            data_rx_now = commands.getoutput(cmd_rx)
            data_tx_now = commands.getoutput(cmd_tx)

            rx = (float(data_rx_now) - float(data_rx_prev))/1024
            rx = ("%.2f" % rx)
            tx = (float(data_tx_now) - float(data_tx_prev))/1024
            tx = ("%.2f" % tx)

        except Exception, e:
            logger.exception(e)
            return None

        return {"in" : rx, "out" : tx}
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号