如何在 iPerf3 的每个标准输出之前使用时间戳?

如何在 iPerf3 的每个标准输出之前使用时间戳?

我正在使用 iPerf3 来测量两个远程设备之间的吞吐量。我的 iPerf 命令的输出如下:

[  4]   0.00-0.20   sec   122 KBytes  4.98 Mbits/sec    7   29.7 KBytes       
[  4]   0.20-0.40   sec   110 KBytes  4.52 Mbits/sec    0   33.9 KBytes       
[  4]   0.40-0.60   sec   112 KBytes  4.58 Mbits/sec    1   25.5 KBytes       
[  4]   0.60-0.80   sec  84.8 KBytes  3.48 Mbits/sec    0   26.9 KBytes       
[  4]   0.80-1.00   sec   113 KBytes  4.63 Mbits/sec    0   26.9 KBytes       
[  4]   1.00-1.20   sec   113 KBytes  4.63 Mbits/sec    0   28.3 KBytes       
[  4]   1.20-1.40   sec  84.8 KBytes  3.47 Mbits/sec    0   29.7 KBytes       
[  4]   1.40-1.60   sec   113 KBytes  4.63 Mbits/sec    0   31.1 KBytes       
[  4]   1.60-1.80   sec   113 KBytes  4.63 Mbits/sec    0   32.5 KBytes       
[  4]   1.80-2.00   sec  84.8 KBytes  3.48 Mbits/sec    0   33.9 KBytes       
[  4]   2.00-2.20   sec   113 KBytes  4.63 Mbits/sec    0   35.4 KBytes       
[  4]   2.20-2.40   sec   116 KBytes  4.75 Mbits/sec    2   26.9 KBytes       
[  4]   2.40-2.60   sec  84.8 KBytes  3.47 Mbits/sec    0   28.3 KBytes       
[  4]   2.60-2.80   sec   113 KBytes  4.63 Mbits/sec    0   31.1 KBytes       
[  4]   2.80-3.00   sec  84.8 KBytes  3.47 Mbits/sec    0   31.1 KBytes       
[  4]   3.00-3.20   sec   113 KBytes  4.63 Mbits/sec    0   32.5 KBytes       
[  4]   3.20-3.40   sec  84.8 KBytes  3.47 Mbits/sec    1   28.3 KBytes       
[  4]   3.40-3.60   sec   115 KBytes  4.69 Mbits/sec    0   25.5 KBytes       
[  4]   3.60-3.80   sec   113 KBytes  4.63 Mbits/sec    0   26.9 KBytes       
[  4]   3.80-4.00   sec   113 KBytes  4.63 Mbits/sec    0   26.9 KBytes       
[  4]   4.00-4.20   sec  84.8 KBytes  3.48 Mbits/sec    0   28.3 KBytes       
[  4]   4.20-4.40   sec   113 KBytes  4.63 Mbits/sec    0   29.7 KBytes       
[  4]   4.40-4.60   sec   113 KBytes  4.63 Mbits/sec    0   31.1 KBytes       
[  4]   4.60-4.80   sec  84.8 KBytes  3.47 Mbits/sec    0   32.5 KBytes       
[  4]   4.80-5.00   sec   116 KBytes  4.75 Mbits/sec    0   33.9 KBytes       
[  4]   5.00-5.20   sec   102 KBytes  4.17 Mbits/sec    1   26.9 KBytes       
[  4]   5.20-5.40   sec  84.8 KBytes  3.47 Mbits/sec    0   28.3 KBytes       
[  4]   5.40-5.60   sec   113 KBytes  4.63 Mbits/sec    0   29.7 KBytes       
[  4]   5.60-5.80   sec   113 KBytes  4.63 Mbits/sec    0   31.1 KBytes       
[  4]   5.80-6.00   sec  91.9 KBytes  3.76 Mbits/sec    0   32.5 KBytes       
[  4]   6.00-6.20   sec   113 KBytes  4.64 Mbits/sec    0   32.5 KBytes       
[  4]   6.20-6.40   sec  84.8 KBytes  3.47 Mbits/sec    0   33.9 KBytes       
[  4]   6.40-6.60   sec   123 KBytes  5.04 Mbits/sec    1   24.0 KBytes       
[  4]   6.60-6.80   sec  84.8 KBytes  3.48 Mbits/sec    0   26.9 KBytes       
[  4]   6.80-7.00   sec   113 KBytes  4.63 Mbits/sec    0   28.3 KBytes       
[  4]   7.00-7.20   sec   113 KBytes  4.63 Mbits/sec    0   29.7 KBytes       
[  4]   7.20-7.40   sec   113 KBytes  4.63 Mbits/sec    0   31.1 KBytes       
[  4]   7.40-7.60   sec  84.8 KBytes  3.47 Mbits/sec    0   32.5 KBytes       
[  4]   7.60-7.80   sec   113 KBytes  4.63 Mbits/sec    0   32.5 KBytes       
[  4]   7.80-8.00   sec  91.9 KBytes  3.76 Mbits/sec    1   24.0 KBytes       
[  4]   8.00-8.20   sec  84.8 KBytes  3.48 Mbits/sec    0   26.9 KBytes       
[  4]   8.20-8.40   sec   113 KBytes  4.63 Mbits/sec    0   28.3 KBytes       
[  4]   8.40-8.60   sec   113 KBytes  4.63 Mbits/sec    0   29.7 KBytes       
[  4]   8.60-8.80   sec  84.8 KBytes  3.48 Mbits/sec    0   31.1 KBytes       
[  4]   8.80-9.00   sec   113 KBytes  4.63 Mbits/sec    0   32.5 KBytes       
[  4]   9.00-9.20   sec  84.8 KBytes  3.48 Mbits/sec    0   32.5 KBytes       
[  4]   9.20-9.40   sec   120 KBytes  4.92 Mbits/sec    1   24.0 KBytes       
[  4]   9.40-9.60   sec  84.8 KBytes  3.48 Mbits/sec    0   26.9 KBytes       
[  4]   9.60-9.80   sec   113 KBytes  4.63 Mbits/sec    0   28.3 KBytes       
[  4]   9.80-10.00  sec   113 KBytes  4.63 Mbits/sec    0   29.7 KBytes `

对于每条输出行,我想在前面添加一个时间戳。

答案1

您可以使用 iperf3 的 -T 选项将字符串添加到 iperf 每行的开头,但不幸的是,如果该字符串包含命令(例如date),它将仅使用该命令最初运行时的日期。

因此,缺少脚本来执行此操作的唯一方法是快速而肮脏的 for in 循环,一次运行 1 个数据包的 iperf:

┌─[root@Fedora]─[~]─[03:25 pm]
└─[$]› for i in {1..30}; do iperf3 -c 192.168.0.1 -i 1 -t 1 -T $(date "+%H:%M:%S ") | grep -A1 Interval | grep -v Interval ; done
15:26:26 :  [  4]   0.00-1.00   sec  8.23 MBytes  69.0 Mbits/sec    8    271 KBytes
15:26:26 :  [  4]   0.00-1.00   sec  8.23 MBytes  69.0 Mbits/sec    8             sender
15:26:27 :  [  4]   0.00-1.00   sec  12.4 MBytes   104 Mbits/sec  219    733 KBytes
15:26:27 :  [  4]   0.00-1.00   sec  12.4 MBytes   104 Mbits/sec  219             sender
15:26:29 :  [  4]   0.00-1.00   sec  12.5 MBytes   105 Mbits/sec  101    673 KBytes
15:26:29 :  [  4]   0.00-1.00   sec  12.5 MBytes   105 Mbits/sec  101             sender
15:26:30 :  [  4]   0.00-1.00   sec  14.0 MBytes   117 Mbits/sec    0   1.05 MBytes
15:26:30 :  [  4]   0.00-1.00   sec  14.0 MBytes   117 Mbits/sec    0             sender
15:26:32 :  [  4]   0.00-1.00   sec  12.4 MBytes   104 Mbits/sec   29    566 KBytes
15:26:32 :  [  4]   0.00-1.00   sec  12.4 MBytes   104 Mbits/sec   29             sender
15:26:33 :  [  4]   0.00-1.00   sec  14.0 MBytes   117 Mbits/sec    2    729 KBytes

尽管使用这种方法,这当然意味着您最终不会得到总体平均结果。我希望这有帮助。

答案2

作为iperf3.9--timestamps添加该标志是为了允许预先添加时间戳:

PS C:\Users\kyrlon> iperf3 -c 127.0.0.1 --timestamp
Thu Apr  4 17:32:38 2024 Connecting to host 127.0.0.1, port 5201
Thu Apr  4 17:32:38 2024 [  5] local 127.0.0.1 port 33864 connected to 127.0.0.1 port 5201
Thu Apr  4 17:32:39 2024 [ ID] Interval           Transfer     Bitrate
Thu Apr  4 17:32:39 2024 [  5]   0.00-1.00   sec   581 MBytes  4.86 Gbits/sec
Thu Apr  4 17:32:40 2024 [  5]   1.00-2.00   sec   578 MBytes  4.84 Gbits/sec
Thu Apr  4 17:32:41 2024 [  5]   2.00-3.00   sec   704 MBytes  5.92 Gbits/sec
Thu Apr  4 17:32:42 2024 [  5]   3.00-4.00   sec   778 MBytes  6.53 Gbits/sec
Thu Apr  4 17:32:43 2024 [  5]   4.00-5.00   sec   746 MBytes  6.25 Gbits/sec
Thu Apr  4 17:32:44 2024 [  5]   5.00-6.00   sec   796 MBytes  6.66 Gbits/sec
Thu Apr  4 17:32:45 2024 [  5]   6.00-7.00   sec   708 MBytes  5.96 Gbits/sec
Thu Apr  4 17:32:46 2024 [  5]   7.00-8.00   sec   790 MBytes  6.63 Gbits/sec
Thu Apr  4 17:32:47 2024 [  5]   8.00-9.00   sec   815 MBytes  6.84 Gbits/sec
Thu Apr  4 17:32:48 2024 [  5]   9.00-10.00  sec   881 MBytes  7.38 Gbits/sec
Thu Apr  4 17:32:48 2024 - - - - - - - - - - - - - - - - - - - - - - - - -
Thu Apr  4 17:32:48 2024 [ ID] Interval           Transfer     Bitrate
Thu Apr  4 17:32:48 2024 [  5]   0.00-10.00  sec  7.20 GBytes  6.19 Gbits/sec                  sender
Thu Apr  4 17:32:48 2024 [  5]   0.00-10.00  sec  7.20 GBytes  6.18 Gbits/sec                  receiver
Thu Apr  4 17:32:48 2024
Thu Apr  4 17:32:48 2024 iperf Done.

相关内容