如何仅输出间隔和带宽的 iperf 结果?

如何仅输出间隔和带宽的 iperf 结果?

我正在尝试获取命令的输出

iperf -c 10.0.0.1 -t 3600 -i 2

并且只需要列出整个小时的记录的间隔和带宽字段。

我已很多年没有使用过 grep 或 awk 了。

帮助将会非常棒!

示例输出:

------------------------------------------------------------
Client connecting to node2, TCP port 5001
TCP window size:  129 KByte (WARNING: requested  130 KByte)
------------------------------------------------------------
[  3] local <IP Addr node1> port 2530 connected with <IP Addr node2> port 5001
[ ID] Interval       Transfer     Bandwidth
[  3]  0.0-10.0 sec  19.7 MBytes  15.8 Mbits/sec

期望输出:

0.0-10.0 15.8

答案1

> iperf -c 127.0.0.1 -t 2 -i 0.5 -fm | tee log1
------------------------------------------------------------
客户端连接到 127.0.0.1,TCP 端口 5001
TCP 窗口大小:2.50 MByte(默认)
------------------------------------------------------------
[ 3] 本地 127.0.0.1 端口 42200 与 127.0.0.1 端口 5001 连接
[ ID] 间隔传输带宽
[ 3] 0.0-0.5 秒 449 MBytes 7537 Mbits/秒
[ 3] 0.5-1.0 秒 578 MBytes 9697 Mbits/秒
[ 3] 1.0-1.5 秒 575 MBytes 9649 Mbits/秒
[ 3] 1.5-2.0 秒 587 MBytes 9848 Mbits/秒
[ 3] 0.0-2.0 秒 2190 MBytes 9183 Mbits/秒
> awk -F'[ -]+' '/sec/{打印 $3"-"$4" "$8}' log1
0.0-0.5 7537
0.5-1.0 9697
1.0-1.5 9649
1.5-2.0 9848
0.0-2.0 9183
> iperf -c 127.0.0.1 -t 2 -i 0.5 -fm |\
> awk -Wi -F'[ -]+' '/sec/{打印 $3"-"$4" "$8}'
# 交互式结果如下 #
> iperf -c 127.0.0.1 -t 2 -i 0.5 -xc -yc | tee log2
20180515044354,,,,,3,0.0-0.5,536084480,8577351680
20180515044355,,,,,3,0.5-1.0,602537984,9640607744
20180515044355,,,,,3,1.0-1.5,621805568,9948889088
20180515044356,,,,,3,1.5-2.0,620888064,9934209024
20180515044356,,,,,3,0.0-2.0,2381447168,9524874284
> awk -F,'{打印 $7" "$9/1e6}' log2
0.0-0.5 8577.35
0.5-1.0 9640.61
1.0-1.5 9948.89
1.5-2.0 9934.21
0.0-2.0 9524.87
> iperf -c 127.0.0.1 -t 2 -i 0.5 -xc -yc | awk -Wi -F,'{打印$7" "$9/1e6}'
# 交互式结果如下 #

答案2

如果你正在使用 iperf2,你可能想尝试 -yC 格式化选项

[root@localhost iperf2-code]# src/iperf -c 192.168.1.4 -i 1 -yC -t 5 20180510151943,192.168.1.1,42090,192.168.1.4,5001,3,0.0-1.0,63438848,507510784 20180510151944,192.168.1.1,42090,192.168.1.4,5001,3,1.0-2.0,63569920,508559360 20180510151945,192.168.1.1,42090,192.168.1.4,5001,3,2.0-3.0,57802752,462422016 20180510151946,192.168.1.1,42090,192.168.1.4,5001,3,3.0-4.0,57409536,459276288 20180510151947,192.168.1.1,42090,192.168.1.4,5001,3,4.0-5.0,57016320,456130560 20180510151947,192.168.1.1,42090,192.168.1.4,5001,3,0.0-5.0,299237376,478429304

鲍勃

相关内容