计算属于GigabitEthernet102/的所有接口的输入/输出速率 [英] Calculate input/output rate for all interfaces which are part of GigabitEthernet102/
问题描述
我正在尝试捕获GigabitEthernet102一部分的接口的输入速率和输出速率之和.我有一些逻辑,但希望将其转换为合适的程序以实现此目的.
I am trying to capture the sum of input rate and output rate for interfaces which are part of GigabitEthernet102.. I have some logic but would like assistance converting it to a suitable program to achieve this.
输入
GigabitEthernet102/0/0/1 is up, line protocol is up
Interface state transitions: 5
Hardware is GigabitEthernet/IEEE 802.3 interface(s), address is sets.sets.sets
Description: xxx
Internet address is x.x.x.x
--More-- MTU 1514 bytes, BW 100000 Kbit (Max: 100000 Kbit)
reliability 255/255, txload 0/255, rxload 0/255
Encapsulation ARPA,
Full-duplex, 100Mb/s, 1000BASE-T, link type is force-up
output flow control is off, input flow control is off
Carrier delay (up) is 100 msec, Carrier delay (down) is 100 msec
loopback not set,
Last link flapped 10w3d
ARP type ARPA, ARP timeout 04:00:00
Last input 00:00:00, output 00:00:00
Last clearing of "show interface" counters never
30 second input rate 0 bits/sec, 0 packets/sec
30 second output rate 0 bits/sec, 0 packets/sec
5638310 packets input, 467600021 bytes, 27 total input drops
0 drops for unrecognized upper-level protocol
Received 4 broadcast packets, 186012 multicast packets
1 runts, 0 giants, 0 throttles, 0 parity
2 input errors, 1 CRC, 0 frame, 0 overrun, 0 ignored, 0 abort
4336700 packets output, 306662485 bytes, 0 total output drops
Output 44 broadcast packets, 0 multicast packets
0 output errors, 0 underruns, 0 applique, 0 resets
0 output buffer failures, 0 output buffers swapped out
0 carrier transitions
GigabitEthernet102/0/0/2 is administratively down, line protocol is administratively down
Interface state transitions: 0
Hardware is GigabitEthernet/IEEE 802.3 interface(s), address is sets.sets.sets
Internet address is Unknown
MTU 1514 bytes, BW 100000 Kbit (Max: 100000 Kbit)
reliability 255/255, txload 0/255, rxload 0/255
Encapsulation ARPA,
--More-- Full-duplex, 100Mb/s, 1000BASE-T, link type is force-up
output flow control is off, input flow control is off
Carrier delay (up) is 100 msec, Carrier delay (down) is 100 msec
loopback not set,
Last input never, output never
Last clearing of "show interface" counters never
5 minute input rate 0 bits/sec, 0 packets/sec
5 minute output rate 0 bits/sec, 0 packets/sec
0 packets input, 0 bytes, 0 total input drops
0 drops for unrecognized upper-level protocol
Received 0 broadcast packets, 0 multicast packets
0 runts, 0 giants, 0 throttles, 0 parity
0 input errors, 0 CRC, 0 frame, 0 overrun, 0 ignored, 0 abort
0 packets output, 0 bytes, 0 total output drops
Output 0 broadcast packets, 0 multicast packets
0 output errors, 0 underruns, 0 applique, 0 resets
0 output buffer failures, 0 output buffers swapped out
0 carrier transitions
TenGigE0/2/0/3 is up, line protocol is up
Interface state transitions: 3
Hardware is TenGigE, address is sets.sets.sets
Layer 1 Transport Mode is LAN
--More-- Description:
Internet address is x.x.x.x
MTU 1536 bytes, BW 10000000 Kbit (Max: 10000000 Kbit)
reliability 255/255, txload 0/255, rxload 0/255
Encapsulation ARPA,
Full-duplex, 10000Mb/s, LR, link type is force-up
output flow control is off, input flow control is off
Carrier delay (up) is 10 msec
loopback not set,
Last link flapped 18w3d
ARP type ARPA, ARP timeout 04:00:00
Last input 00:00:00, output 00:00:00
Last clearing of "show interface" counters 10w1d
5 minute input rate 0 bits/sec, 1 packets/sec
5 minute output rate 0 bits/sec, 1 packets/sec
3907990 packets input, 341219535 bytes, 0 total input drops
10323 drops for unrecognized upper-level protocol
Received 0 broadcast packets, 218445 multicast packets
0 runts, 0 giants, 0 throttles, 0 parity
0 input errors, 0 CRC, 0 frame, 0 overrun, 0 ignored, 0 abort
6795781 packets output, 490559886 bytes, 0 total output drops
Output 0 broadcast packets, 0 multicast packets
0 output errors, 0 underruns, 0 applique, 0 resets
0 output buffer failures, 0 output buffers swapped out
0 carrier transitions
GigabitEthernet102/0/0/3 is up, line protocol is up
Interface state transitions: 1
Hardware is GigabitEthernet/IEEE 802.3 interface(s), address is x.x.x.x
Description: xxx
Internet address is x.x.x.x
MTU 1514 bytes, BW 100000 Kbit (Max: 100000 Kbit)
reliability 255/255, txload 0/255, rxload 0/255
Encapsulation ARPA,
Full-duplex, 100Mb/s, 1000BASE-T, link type is force-up
output flow control is off, input flow control is off
Carrier delay (up) is 100 msec, Carrier delay (down) is 100 msec
loopback not set,
--More-- Last link flapped 18w3d
ARP type ARPA, ARP timeout 04:00:00
Last input 00:00:00, output 00:00:00
Last clearing of "show interface" counters never
5 minute input rate 2000 bits/sec, 2 packets/sec
5 minute output rate 1000 bits/sec, 2 packets/sec
23543445 packets input, 2623268477 bytes, 66 total input drops
18599 drops for unrecognized upper-level protocol
Received 37519 broadcast packets, 225636 multicast packets
0 runts, 0 giants, 0 throttles, 0 parity
0 input errors, 0 CRC, 0 frame, 0 overrun, 0 ignored, 0 abort
24806600 packets output, 2739397694 bytes, 0 total output drops
Output 3 broadcast packets, 0 multicast packets
0 output errors, 0 underruns, 0 applique, 0 resets
0 output buffer failures, 0 output buffers swapped out
0 carrier transitions
建议的程序流程
1>捕获UP并具有GigabitEthernet102/[0-9] {3}语法的接口
1> Capture interfaces which are UP and have GigabitEthernet102/[0-9]{3} syntax
GigabitEthernet102/0/0/1
GigabitEthernet102/0/0/1
GigabitEthernet102/0/0/3
GigabitEthernet102/0/0/3
2>使用这些界面再次搜索文件(可能正向后看?)以捕获输入速率.对输出速率做同样的事情.
2> Search file again with these interfaces (possibly positive lookbehind?) to capture input rate. Do the same thing for output rate.
3>使用数组执行输入/输出速率之和.
3> Use array to perform sum of the input/output rates.
期望的输出
Total input traffic: x bits
Total output traffic: x bits
尝试
1> awk '/^GigabitEthernet102/ && !/down/' sat_int_acc.txt
GigabitEthernet102/0/0/1 is up, line protocol is up
GigabitEthernet102/0/0/3 is up, line protocol is up
GigabitEthernet102/0/0/4 is up, line protocol is up
...
2> awk '/^GigabitEthernet102/ && !/down/ {intf[$1]} END {for(i in intf) print i}' sat_int_acc.txt
GigabitEthernet102/0/0/30
GigabitEthernet102/0/0/21
GigabitEthernet102/0/0/12
GigabitEthernet102/0/0/40
...
awk '/^GigabitEthernet102/ && !/down/; /^GigabitEthernet102/,/input rate/' sat_int_acc.txt
谢谢.
推荐答案
这应该与一个 awk
命令一起使用.
This should work with one awk
command.
awk '/protocol is/ {f=0} /GigabitEthernet102.* is up/ {f=1} f && /5 minute/ {sum+=$5} END {print sum}' file
3000
-
/protocol is/{f = 0}
测试是否开始新的接口块并将标志f
设置为0
-
/GigabitEthernet102.*已启动/{f = 1}
(如果找到正确的接口),将标志f
设置为1
-
f&&/5分钟/{sum + = $ 5}
,如果标志f \为真且行为
5分钟` -
END {print sum}'
然后打印回合输入和输出的总和 /protocol is/ {f=0}
Test if start of new interface block and set flagf
to0
/GigabitEthernet102.* is up/ {f=1}
if correct interface is found set flagf
to1
f && /5 minute/ {sum+=$5}
if flagf\ is true and line is
5 minute`END {print sum}'
then print sum of bout input and output
注意,您无需混用 5分钟
和 30秒
输入.
NB you need to not mix 5 minute
and 30 second
input.
这篇关于计算属于GigabitEthernet102/的所有接口的输入/输出速率的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!