实时RX和TX速率在linux [英] Live RX and TX rates in linux

查看:1367
本文介绍了实时RX和TX速率在linux的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在寻找一种方法来编程(无论是调用库,还是一个独立的程序)监控live ip流量在linux。我不想总计,我想要使用的当前带宽。我正在寻找一个类似(但非图形)到OS X的istat菜单的网络流量监视器。

I'm looking for a way to programatically (whether calling a library, or a standalone program) monitor live ip traffic in linux. I don't want totals, i want the current bandwidth that is being used. I'm looking for a tool similar (but non-graphical) to OS X's istat menu's network traffic monitor.

我相当肯定这样的东西存在,但我不知道在哪里看,我宁愿不必重新发明轮子。

I'm fairly certain something like this exists, but I'm not sure where to look, and i'd rather not have to reinvent the wheel.

它和监控套接字一样简单吗?

Is it as simple as monitoring a socket? Or do I need a utility that handles alot of overhead for me?

推荐答案

我们在/ proc / net中有字节和包计数器/ dev,因此:

We have byte and packet counters in /proc/net/dev, so:

import time

last={}

def diff(col): return counters[col] - last[iface][col]

while True:
  print "\n%10s: %10s %10s %10s %10s"%("interface","bytes recv","bytes sent", "pkts recv", "pkts sent")
  for line in open('/proc/net/dev').readlines()[2:]:
    iface, counters = line.split(':')
    counters = map(int,counters.split())
    if iface in last:
      print "%10s: %10d %10d %10d %10d"%(iface,diff(0), diff(8), diff(1), diff(9))

    last[iface] = counters

  time.sleep(1)

这篇关于实时RX和TX速率在linux的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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