2

I'm running iperf multiple times via the following command

iperf -c 1.1.1.1 -t 60 -w 6400 -f m >> iperf.log

sometimes with different arguments. The resulting iperf.log may look like this:

[ 3] local 2.2.2.2 port 51129 connected with 1.1.1.1 port 5001 
[ ID] Interval Transfer Bandwidth 
[ 3] 0.0-20.0 sec 1869 MBytes 784 Mbits/sec
[ 3] local 2.2.2.2 port 51130 connected with 1.1.1.1 port 5001 
[ ID] Interval Transfer Bandwidth 
[ 3] 0.0-15.0 sec 1445 MBytes 808 Mbits/sec

what i'd like to able to do is once it completed to have the average transfer rate outputted ie

 average ....... XXX Mbits/sec
Dima Chubarov
  • 16,199
  • 6
  • 40
  • 76
Lurch
  • 819
  • 3
  • 18
  • 30
  • So when you tried to do that, did something go wrong? Is there a bug or design feature that you need help with? Does `iperf` report the rate and you want to filter it? – Brian Cain Dec 04 '13 at 15:05
  • sample output to iperf.log is [ 3] local 2.2.2.2 port 51129 connected with 1.1.1.1 port 5001 [ ID] Interval Transfer Bandwidth [ 3] 0.0-20.0 sec 1869 MBytes 784 Mbits/sec [ 3] 0.0-15.0 sec 1445 MBytes 808 Mbits/sec i'd like to be able to add up 784 and 808 and get the average. – Lurch Dec 04 '13 at 15:08
  • 2
    please learn to edit relevant details into your question above, rather than post it in replies to comments where it is unformatted. `awk` is a very good candidate to help with your problem. Read more at http://www.grymoire.com/Unix/Awk.html . Good luck. – shellter Dec 04 '13 at 15:27
  • The idea of adding up 784 and 808 to get the bandwidth looks suspicious since transmit times are different. I assume correct average would be to add up transfer sizes and divide by transfer times. – Dima Chubarov Dec 04 '13 at 16:15
  • yes that probably sounds a better way of doing it – Lurch Dec 04 '13 at 16:20

2 Answers2

1

awk is the way to go, you can try something like this:

iperf -c 1.1.1.1 -t 60 -w 6400 -f m|awk -F 'MBytes' {'print $2'} >> iperf.log

You just need to remove the empty lines now, that I will leave to you. :)

Paulo Freitas
  • 13,194
  • 14
  • 74
  • 96
0

Do you need to start and stop it? You might just want to use interval reporting (-i ) You can set i to 15 and set -t to samples desired * 15.

rjmcmahon
  • 324
  • 1
  • 3