Friday, 7 December 2018

networking - Command line: how to get instantaneous bandwidth on a port


I'm trying to get the instantaneous bandwidth usage of eth0, port 10001. I've looked into using lots of different tools, but most of these seem to have an ncurses type output which isn't suitable for piping into my program.


I've seen How can I get an interface's bandwidth at any given second from the Linux command line?, but this only gives the total statistics over an interface and isn't broken down by port.


Ideally, I'd like a command that takes two arguments (eth0 and port 10001), runs for 500ms, calculates the number and size of packets and outputs a simple megabytes/second metric.


Is this too much to ask?


Anyone got any ideas?



Answer



You could try to use the ifstat command. With default invocation, it shows bandwidth usage periodically until you hit Control-C But you can invoke it like this:


ifstat    (i.e. ifstat 1 1)

So that it will give you the bandwidth usage in one second and it's scriptable.


No comments:

Post a Comment

Where does Skype save my contact's avatars in Linux?

I'm using Skype on Linux. Where can I find images cached by skype of my contact's avatars? Answer I wanted to get those Skype avat...