Your application is probably sending packets to a specific UDP or TCP port number or to a specific IP-address.
You can therefore use something like TCPdump to capture that traffic.
TCPdump doesn't give you the real-time stats you desire but you can feed it's output to something that does (I'll try to update this answer with an answer later).
Update:
$ sudo tcpdump -i eth1 -l -e -n | ./netbps
tcpdump: verbose output suppressed, use -v or -vv for full protocol decode
listening on eth1, link-type EN10MB (Ethernet), capture size 96 bytes
11:36:53 2143.33 Bps
11:37:03 1995.99 Bps
11:37:13 2008.35 Bps
11:37:23 1999.97 Bps
11:37:33 2083.32 Bps
131 packets captured
131 packets received by filter
0 packets dropped by kernel
I interrupted that after a minute by pressing Ctrl+C.
You'd need to add a suitable filter expression at the end of the tcpdump
command to only include the traffic generated by your app (e.g. port 123
)
The program netbps
is this:
#!/usr/bin/perl
use strict;
use warnings;
use Time::HiRes;
my $reporting_interval = 10.0; # seconds
my $bytes_this_interval = 0;
my $start_time = [Time::HiRes::gettimeofday()];
STDOUT->autoflush(1);
while (<>) {
if (/ length (\d+):/) {
$bytes_this_interval += $1;
my $elapsed_seconds = Time::HiRes::tv_interval($start_time);
if ($elapsed_seconds > $reporting_interval) {
my $bps = $bytes_this_interval / $elapsed_seconds;
printf "%02d:%02d:%02d %10.2f Bps\n", (localtime())[2,1,0],$bps;
$start_time = [Time::HiRes::gettimeofday()];
$bytes_this_interval = 0;
}
}
}
It's just an example, adjust to taste.
This one should work in busybox bash on embedded routers: https://gist.github.com/dagelf/8a842ed755354b31e79214042a4a4695
– Dagelf – 2018-05-23T16:35:25.150This is also achieved with
vnstat -tr
– St0rM – 2018-09-28T13:54:00.907Many thanks, i will wait for your working example. My goal was like i did with $ bwm-ng -o plain -N -d which shows output as bit by interfaces but that failes if the interface is used except lo. In other hand the IPtraf shows excellent bytes realtime. But there is no tools which can tell me like bits and bytes realtime in RX/TX for specific interface or any interface as total etc. I am missing it :-( – YumYumYum – 2011-11-13T11:05:13.657
@YumYum: answer updated. – RedGrittyBrick – 2011-11-13T11:46:12.027
1
@RedGrittyBrick You absolute legend! Great script! Thanks so much for sharing. This answers my question at http://superuser.com/questions/395226/command-line-how-to-get-instantaneous-bandwidth-on-a-port
– Eamorr – 2012-02-29T08:52:39.863