Linux Live RX and TX Betting

I'm looking for a programming method (be it a library call or a standalone program) that tracks direct IP traffic on Linux. I do not need totals, I want to use the current bandwidth. I am looking for a tool similar (but not graphical) to OS X istat a network traffic monitoring menu.

I'm pretty sure something like this exists, but I'm not sure where to look, and I would rather not reinvent the wheel.

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

+2
source share
3 answers

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) 
+9
source

I use a small program known as dstat It combines many "stats" as functions into 1 quick output. Very customizable. This will give you current network bandwidth as well as much more.

On linux, the netstat program will give you raw network statistics. You can analyze these statistics yourself to create a meaningful result (which is what dstat does).

+1
source

You can get network bandwidth and number of packets using the following dstat command:

 dstat -n --net-packets -f 10 

Or, if you want to control certain interfaces, you can do:

 dstat -n --net-packets -N eth0,wlan0 10 

If you prefer the more usual output bits per second :

 dstat -n --net-packets -N eth0,wlan0 --bits 10 

This will give you 10 second averages. If you prefer to write this for post-processing, you can export it to a CSV file using:

 dstat -n --net-packets -N eth0,wlan0 --bits 10 

Dstat comes with many plugins for comparing these metrics with other metrics on your system and gives you the option to add your own (python) plugins if you need to customize data or control something specific for your environment.

0
source

Source: https://habr.com/ru/post/1412363/


All Articles