cisco接口计数器,多字符串值

2024-05-26 16:29:04 发布

您现在位置:Python中文网/ 问答频道 /正文

要分别提取RX,TX计数器。有没有python示例以下面的方式从string_输出中打印计数器?在

RX_unicast_packets = 2735118
RX_multicast_packets = 703555

TX_unicast_packets = 3983205
TX_multicast_packets = 1916649


RX
    2735118 unicast packets  703555 multicast packets  677 broadcast packets
    3439365 input packets  3803190483 bytes
    1867301 jumbo packets  0 storm suppression bytes
    0 runts  0 giants  0 CRC  0 no buffer
    0 input error  0 short frame  0 overrun   0 underrun  0 ignored
    0 watchdog  0 bad etype drop  0 bad proto drop  0 if down drop
    0 input with dribble  291 input discard
    15 Rx pause
  TX
    3983205 unicast packets  1916649 multicast packets  340 broadcast packets
    5900194 output packets  3546311266 bytes
    1702539 jumbo packets
    0 output errors  0 collision  0 deferred  0 late collision
    0 lost carrier  0 no carrier  0 babble 0 output discard
    0 Tx pause
"

Tags: noinputoutputbytes计数器rxdropdiscard
1条回答
网友
1楼 · 发布于 2024-05-26 16:29:04

我相信regex表达式在这里可能很有价值,我不确定它们是如何接收上述输出的,但我会假设它是一个字符串类型:

要分析TX值:

string = 'RX 2735118 unicast packets 703555 multicast packets 677 broadcast packets 3439365 input packets 3803190483 bytes 1867301 jumbo packets 0 storm suppression bytes 0 runts 0 giants 0 CRC 0 no buffer 0 input error 0 short frame 0 overrun 0 underrun 0 ignored 0 watchdog 0 bad etype drop 0 bad proto drop 0 if down drop 0 input with dribble 291 input discard 15 Rx pause TX 3983205 unicast packets 1916649 multicast packets 340 broadcast packets 5900194 output packets 3546311266 bytes 1702539 jumbo packets 0 output errors 0 collision 0 deferred 0 late collision 0 lost carrier 0 no carrier 0 babble 0 output discard 0 Tx pause'

re.findall(r'RX \d+\ ', string) #to get the matching RX values

re.findall(r'TX \d+\ ', string)#to get the matching TX values

如果要匹配特定值,可以使用搜索团体

RX_unicast_packets = re.search(r'RX (\d+)\ \w+\ \w+\ (\d+)\ ', string).group(1)

RX_multicast_packets = re.search(r'RX (\d+)\ \w+\ \w+\ (\d+)\ ', string).group(2) 如果你需要进一步的帮助,请告诉我,我很乐意在这里帮忙

相关问题 更多 >

    热门问题