LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Server (https://www.linuxquestions.org/questions/linux-server-73/)
-   -   Measure incoming multicast unicast bandwidth (https://www.linuxquestions.org/questions/linux-server-73/measure-incoming-multicast-unicast-bandwidth-4175459711/)

markotitel 04-26-2013 04:55 PM

Measure incoming multicast unicast bandwidth
 
Hi I wanted to make a script which will measure $Subject.

Command like this
Code:

tcpdump -n "broadcast or multicast"
has the right output.

how can I parse it in a terms of bandwidth.

unSpawn 04-28-2013 05:58 AM

tcpstat or ratesniff?

markotitel 04-28-2013 12:56 PM

Hi thanks for reply actually here is what I came up with the help of google.

Quote:

tcpdump -tnn -i eth1 -f multicast | sort | uniq -c | awk '{print $3,"> "$5,$1*$NF/2*8/1024 " Kbps"}' | awk '$1 > 10' & sleep 2s && pkill -HUP -f tcpdump
The output is what I wanted like this
Quote:

[root@titel ~]# > 0.00390625 Kbps
192.168.15.179.12345 > 224.0.248.237.12345: 23.4375 Kbps
192.168.15.179.15223 > 224.3.248.237.15223: 193.359 Kbps

[1]+ Done tcpdump -tnn -i eth1 -f multicast | sort | uniq -c | awk '{print $3,"> "$5,$1*$NF/2*8/1024 " Kbps"}' | awk '$1 > 10'
But I need to hit enter to actually exit to prompt. Where am I wrong here.

markotitel 04-28-2013 03:18 PM

Hi I came with really dirty bash script that does the job.

here it is
Quote:

#!/bin/bash

time=$1

tcpdump -tnn -i eth1 -f multicast > out &


sleep $time
pkill -TERM -f tcpdump

cat out | sort | uniq -c | awk -v time=${time} '{print $3,"> "$5,$1*$NF/time*8/1024 "Kbps"}'

rm out
I have a question, how to write a script for a program that outputs data until we break it (like tcpdump) and do commands like the one in my script.

unSpawn 04-28-2013 07:14 PM

Well you shouldn't kill the process until you're done. Apart from the 'sort|uniq' a file to tail, a loop, a FIFO or piping it through something else like netbps.pl (can't remember where I got it from):
Code:

#!/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()];

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;
    }
  }
}

should all work.


All times are GMT -5. The time now is 06:26 PM.