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}
评论列表
文章目录