取消
显示结果 
搜索替代 
您的意思是: 
cancel
5458
查看次数
10
有帮助
8
评论
minyang2
Cisco Employee
Cisco Employee
本帖最后由 minyang2 于 2019-7-10 12:54 编辑
关于接口的实时速率, 通过采OID的方式无法取得, 我们的算法是每分钟取一次接口的字节总数, 然后进行差值计算.
E1/1口为例, 首先我们确定E1/1接口的index值:
LC-SWG-Leaf-001(config)# show interface snmp-ifindex | in 1/1
Eth1/1 436207616 (0x1a000000)
然后使用以下snmpwalk 命令进行采集数据,需要注意的是,在设备上无法直接采集到接口的实时速率,需要使用差值计算的方法来获得:
C:\Users\minyang2>snmpwalk-c cisco -v 2c 10.75.49.1591.3.6.1.2.1.4.31.3.1.6.436207616 (接口接收数据包字节数总量的OID为:1.3.6.1.2.1.4.31.3.1.6
IP-MIB::ipIfStatsHCInOctets.436207616 = Counter64: 528
1. 等待1分钟之后,再收集一次
C:\Users\minyang2>snmpwalk -c cisco -v 2c 10.75.49.1591.3.6.1.2.1.4.31.3.1.6.436207616
IP-MIB::ipIfStatsHCInOctets.436207616 = Counter64: 261224
2. 接口速率计算如下, 5分钟的速率计算方法也是相同的:
RX : (261224-528)*8/60=34759.46(bits/s)

==============================================
这是一个showinterface的示例:Ethernet2/2is down (Administratively down)
Dedicated Interface
Hardware: 10/100/1000 Ethernet, address: 0026.982e.5cc1 (bia0025.84e6.f86d)
Description: abc
MTU 1500 bytes, BW 1000000 Kbit, DLY 10 usec
reliability 255/255, txload 1/255, rxload 1/255
Encapsulation ARPA
auto-duplex, 1000 Mb/s
Beacon is turned off
Auto-Negotiation is turned on
Input flow-control is off, output flow-control is off
Auto-mdix is turned on
Switchport monitor is off
EtherType is 0x8100
Last link flapped 00:00:04
Last clearing of "show interface" counters never
30 seconds input rate 7744 bits/sec, 3 packets/sec
30 seconds output rate 56 bits/sec, 0 packets/sec
Load-Interval #2: 5 minute (300 seconds)
input rate 7.36 Kbps, 7 pps; output rate 24 bps, 0 pps
L3 in Switched:
ucast: 0 pkts, 0 bytes - mcast: 0 pkts, 0 bytes
L3 out Switched:
ucast: 0 pkts, 0 bytes - mcast: 0 pkts, 0 bytes
RX
12889503 unicast packets 610215 multicastpackets 1157003 broadcast packets
14656721 input packets 1580675456 bytes
0 jumbo packets 0 storm suppression packets
0 runts 0 giants 0 CRC 0 no buffer
0 input error 0 short frame 0overrun 0 underrun 0 ignored
0 watchdog 0 bad etype drop 0 bad protodrop 0 if down drop
0 input with dribble 0 input discard
0 Rx pause
TX
0 unicast packets 4251 multicast packets 0broadcast packets
4251 output packets 973471 bytes
0 jumbo packets
0 output error 0 collision 0 deferred 0late collision
0 lost carrier 0 no carrier 0 babble 0output discard
0 Tx pause
1 interface resets接口的这些计数器涉及到的SNMPobject的对应关系:
InterfaceName :ifName in IF-MIB
Oper Status :ifOperStatus in IF-MIB
address :ifPhysAddressin IF-MIB
Description :ifAlias of ifXEntry in IF-MIB
MTU :ifMtu in IF-MIB
Interface duplex :dot3StatsDuplexStatus in EtherLike-MIB
Interfacespeed :ifHighSpeed in IF-MIB
Rx unicastpackets :ifHCInUcastPkts in IF-MIB
Rx multicastpackets :ifHCInMulticastPkts in IF-MIB
Rx broadcastpackets :ifHCInBroadcastPkts in IF-MIB
Rxbytes :ifHCInOctets in IF-MIB
Rx inputerror :ifInErrors in IF-MIB
Rx bad protodrop :ifInUnknownProtos in IF-MIB
Rx inputdiscard :ifInDiscards in IF-MIB
Tx unicastpackets :ifHCOutUcastPkts in IF-MIB
Tx multicastpackets :ifHCOutMulticastPkts in IF-MIB
Tx broadcastpackets :ifHCOutBroadcastPkts in IF-MIB
Txbytes :ifHCOutOctets in IF-MIB
Tx outputerror :ifOutErrors in IF-MIB
Tx outputdiscard :ifOutDiscards in IF-MIB
Interface UPtime :ifLastChange in IF-MIB
State ChangeReason :cieIfStateChangeReason inCISCO-IF-EXTENSION-MIB
RXrunts :cieIfInRuntsErrs in CISCO-IF-EXTENSION-MIB
RXgiants :cieIfInGiantsErrs in CISCO-IF-EXTENSION-MIB
RXoverrun :cieIfInOverrunErrs inCISCO-IF-EXTENSION-MIB
RXignored :cieIfInIgnored in CISCO-IF-EXTENSION-MIB关于接口,主要会用到两个MIB库,一个库是公有库:IF-MIB,一个是思科私有库:CISCO-IF-EXTENSION-MIB
库的连接如下:
ftp://ftp.cisco.com/pub/mibs/v2/IF-MIB.my
ftp://ftp.cisco.com/pub/mibs/v2/CISCO-IF-EXTENSION-MIB.my在库文件中定义了每个Object的用途,我们以ifName这个Object为例,在库文件中描述如下:ifNameOBJECT-TYPE
SYNTAX DisplayString
MAX-ACCESS read-only
STATUS current
DESCRIPTION
"Thetextual name of the interface. The value of this
object shouldbe the name of the interface as assigned by
the localdevice and should be suitable for use in commands
entered atthe device's `console'. This might be a text
name, suchas `le0' or a simple port number, such as `1',
depending onthe interface naming syntax of the device. If
severalentries in the ifTable together represent a single
interface asnamed by the device, then each will have the
same valueof ifName. Note that for an agent which responds
to SNMPqueries concerning an interface on some other
(proxied)device, then the value of ifName for such an
interface is theproxied device's local name for it.Ifthere is no local name, or this object is otherwise not
applicable,then this object contains a zero-length string."
::= { ifXEntry 1 }我们通过这个网址可以将对应的Object翻译为OID:
http://snmp.cloudapps.cisco.com/Support/SNMP/do/BrowseOID.do?local=en
方法见图:
这里填入Object的名字,点击Translate就可以翻译为OID 1.3.6.1.2.1.31.1.1.1.1:
此时我们可以使用网管系统或者snmpwalk软件来测试这个OID,例如:
C:\Users\minyang2>snmpwalk -v 2c -c cisco 10.75.61.18 1.3.6.1.2.1.31.1.1.1.1
IF-MIB::ifName.83886080 = STRING: mgmt0
IF-MIB::ifName.151060481 = STRING: Vlan1
IF-MIB::ifName.151060482 = STRING: Vlan2
IF-MIB::ifName.151060483 = STRING: Vlan3
IF-MIB::ifName.151060484 = STRING: Vlan4
IF-MIB::ifName.151060485 = STRING: Vlan5
IF-MIB::ifName.151060490 = STRING: Vlan10
IF-MIB::ifName.151060491 = STRING: Vlan11
IF-MIB::ifName.151060493 = STRING: Vlan13
IF-MIB::ifName.151060494 = STRING: Vlan14
IF-MIB::ifName.151060499 = STRING: Vlan19
IF-MIB::ifName.151060500 = STRING: Vlan20
IF-MIB::ifName.151060501 = STRING: Vlan21
我们可以得到接口的名字,ifName字符串后面的数字则是接口所对应的SNMPinterface index,可能会在其他的OID中用到。比如说我们取E1/1接口的状态,我们找到接口的SNMPinterface index
switch# show interface snmp-ifindex | i "Eth1/1"
Eth1/1 436207616 (0x1a000000)
然后我们查到ifOperStatus所对应的OID为:1.3.6.1.2.1.2.2.1.8
C:\Users\minyang2>snmpwalk -v 2c -c cisco 10.75.61.181.3.6.1.2.1.2.2.1.8.436207616
IF-MIB::ifOperStatus.436207616 = INTEGER: down(2)
对于检测VPC的member接口或者是普通的LACP member接口。您可以参考如下案例。 背景:E1/4E1/3存在于port-channel3中。N3K# show port-csu
Flags: D - Down P - Up inport-channel (members)
I - Individual H - Hot-standby(LACP only)
s - Suspended r -Module-removed
S - Switched R -Routed
U - Up (port-channel)
M - Not in use. Min-links not met
--------------------------------------------------------------------------------
Group Port- Type Protocol Member Ports
Channel
--------------------------------------------------------------------------------
3 Po3(SU) Eth NONE Eth1/3(P) Eth1/4(P)
--------------------------------------------------------------------------------------------------------
For interface name OID:
ifname: 1.3.6.1.2.1.31.1.1.1.1
Forinterface name OID:
ifname: 1.3.6.1.2.1.31.1.1.1.1
Example:
C:\Users\minyang2>snmpwalk>snmpwalk -c cisco -v 2c 10.75.62.16 1.3.6.1.2.1.31.1.1.1.1
...
IF-MIB::ifName.369098754 = STRING: port-channel3
...
IF-MIB::ifName.436215808 = STRING: Ethernet1/3
IF-MIB::ifName.436219904 = STRING: Ethernet1/4
For interface status:
ifOperStatus: 1.3.6.1.2.1.2.2.1.8
Example:
C:\Users\minyang2>snmpwalk>snmpwalk -c cisco -v 2c 10.75.62.16 1.3.6.1.2.1.2.2.1.8
...
IF-MIB::ifOperStatus.369098754 = INTEGER: up(1)
...
IF-MIB::ifOperStatus.436215808 = INTEGER: up(1)
IF-MIB::ifOperStatus.436219904 = INTEGER: up(1)
For port-channel member ports:
clagAggPortListPorts: 1.3.6.1.4.1.9.9.225.1.4.1.1.1
Example:
C:\Users\minyang2>snmpwalk>snmpwalk -ccisco -v 2c 10.75.62.16 1.3.6.1.4.1.9.9.225.1.4.1.1.1
SNMPv2-SMI::enterprises.9.9.225.1.4.1.1.1.369098754 = Hex-STRING: 00 02 00 83 00 84
在这里,您可以看到.369098754是port-channel 3的index,红色部分,前2个八位字节00 02是它有多少个成员端口,接下来的2个八位字节00 83是您的第一个成员端口,接下来的2个 八位字节00 84是您的第二个成员端口,成员端口可以转换为插槽/端口,例如00 83,其二进制格式为00000000 1000 0011,第一个9位0000 0000 1是插槽编号1,最后7位000 0011是端口号3,所以我们可以得到它的第一个成员端口E1 / 3,理论上第二个是E1 / 4。对于portchannel成员端口flag:它在前发布的版本中是不被支持的。


当前nexus 39K支持的SNMP MIB:
ftp://ftp.cisco.com/pub/mibs/supportlists/nexus3548/Nexus3548MIBSupportList.html
ftp://ftp.cisco.com/pub/mibs/supportlists/nexus9000/Nexus9000MIBSupportList.html
评论
one-time
Level 13
Level 13
感谢楼主实力分享,谢谢~
Luke Huang
Cisco Employee
Cisco Employee
干得漂亮,明明
nlg2013503
Community Member
不知道是否适应于华为设备,先收藏了,谢谢楼主分享
moxiuli
Level 9
Level 9
阅读了。谢谢楼主分享
lwyisccie_cisco
Community Member
楼主研究的挺深:)
Yanli Sun
Community Manager
Community Manager
thanks for sharing
Yanli Sun
Community Manager
Community Manager
thanks for sharing
Zhixin
Level 1
Level 1
很透彻,学习了
入门指南

使用上面的搜索栏输入关键字、短语或问题,搜索问题的答案。

我们希望您在这里的旅程尽可能顺利,因此这里有一些链接可以帮助您快速熟悉思科社区:









快捷链接