============== 编写 EEM 脚本 ==================
! ! 注意:! !
1/ 有一些IOS 版本是不支持‘append’ 命令的,虽然可以敲。 所以就只能用‘redirected’命令另存不同的文件名字到flash。
2/ 'maxrun'命令是在12.4(20)T之后才加进去的。
3/ 如果EEM有哪条命令不熟悉的可以找一下命令手册和配置文档,这里就不复述了。
方法 1 - EEM HIGHCPU SCRIPT using SNMP OID
! ! 注意:! !
4/ EEM追踪CPU值是否成功,关键取决去SNMP监视的OID是否正确,会在后半段教程里介绍怎么查询OID。
模板:
event manager applet high-cpu
event snmp oid 1.3.6.1.4.1.9.9.109.1.1.1.1.3 get-type next entry-op gt entry-val 85 poll-interval 5 exit-time 500 maxrun 600
action 0.1 cli command "enable"
action 0.2 syslog msg "TAC - Capturing high cpu information to flash:"
action 0.3 cli command "term length 0"
action 1.1 cli command "show process cpu sorted | redirect flash:eem-cpu1.txt"
action 1.2 cli command "show interface | redirect flash:eem-interface1.txt"
action 1.3 cli command "show interface stats | redirect flash:eem-stat1.txt"
action 1.4 cli command "show ip traffic | redirect flash:eem-traffic1.txt"
action 2.1 cli command "show process cpu sorted | redirect flash:eem-cpu2.txt"
action 2.2 cli command "show interface | redirect flash:eem-interface2.txt"
action 2.3 cli command "show interface stats | redirect flash:eem-stat2.txt"
action 2.4 cli command "show ip traffic | redirect flash:eem-traffic2.txt"
action 4.1 syslog msg "TAC - Finished logging information to separate eem files in flash"
action 4.2 syslog msg "TAC - Removing eem applet from running config"
action 9.1 cli command "enable"
action 9.2 cli command "configure terminal"
action 9.3 cli command "no event manager applet high-cpu"
action 9.4 cli command "end"
action 9.5 cli command "term default length"
方法 2 - EEM HIGHCPU SCRIPT using CPU threshold syslog messages
模板:
logging buffered 8192 informational
process cpu threshold type total rising 85 interval 5
!
event manager applet high-cpu
event syslog pattern "CPURISINGTHRESHOLD"
action 0.1 syslog msg "EEM: HIGH CPU detected. Writing info to flash:eem-log.txt"
action 0.2 cli command "enable"
action 0.3 cli command "term exec prompt timestamp"
action 0.4 cli command "term len 0"
action 1.1 cli command "show process cpu sorted | append flash:eem-log.txt"
action 1.2 cli command "show proc mem sorted | append flash:eem-log.txt"
action 1.3 cli command "show mem alloc total | append flash:eem-log.txt"
action 1.4 cli command "show buffers | append flash:eem-log.txt"
action 1.5 cli command "show interfaces | append flash:eem-log.txt"
action 1.6 cli command "show interfaces stat | append flash:eem-log.txt"
action 1.7 cli command "show ip traffic | append flash:eem-log.txt"
action 2.2 syslog msg "EEM: Self-removing applet from configuration..."
action 2.3 cli command "configure terminal"
action 2.4 cli command "no event manager applet high_cpu"
action 2.5 cli command "end"
!
end
============= 如何定义CPU的SNMP OID ==============
第一步:单CPU OID选择
SNMP CPU OID的查询主要有一下三种方式(OID只是举例,需要在 SNMP Object Navigator 具体查询):
1/ cpmCPUTotal5secRev (.1.3.6.1.4.1.9.9.109.1.1.1.1.6): 在最近5秒内CPU的使用率是多少。
2/ cpmCPUTotal1minRev (.1.3.6.1.4.1.9.9.109.1.1.1.1.7): 在最近1分钟内CPU的使用率是多少。
3/ cpmCPUTotal5minRev (.1.3.6.1.4.1.9.9.109.1.1.1.1.8): 在最近5分钟内CPU的使用率是多少。
举例,在不同在IOS版本中,OID会有所变化:
第二步:多CPU OID选择
这个情况有些复杂,需要参考 cpmCPUTotalTable 和 entPhysicalTable 两张表的OID,这就意味着需要IOS版本必须支持 CISCO-PROCESS-MIB 和 ENTITY-MIB 的 CPU 使用率的查询。
Anyway,就是说要具体情况具体分析,建议大家还是开一个TAC的case来的准确。:lol
But,如果大家想研究一下的话可以参考以下链接:
Procedure for Devices with Multiple CPUs
第三步:使用 SNMP Object Navigator 确认CPU的SNMP OID
1/ 只要在Enter OID or object name: 填入要监控的对象组就ok了,是不是很简单?!
![213842jtytr6uskxvty6ly.jpg 213842jtytr6uskxvty6ly.jpg](/t5/image/serverpage/image-id/109902i0859F80AA19C57C4/image-size/large?v=v2&px=999)
2/ 在OID后面就会出现一串数字,这个就是我们要的!!
3/ 鼠标悬停在object Details会有相对应的解释。
![214038y0obgobdt0aapgsu.jpg 214038y0obgobdt0aapgsu.jpg](/t5/image/serverpage/image-id/109903iD0A1D022F69F6CCF/image-size/large?v=v2&px=999)
4/ 最后!!我们开始验证一下这个是否是我们这个IOS版本所支持的OID,点击[url=]View Supporting Images。[/url]
![215825cxlmwv0asmsjdmcw.jpg 215825cxlmwv0asmsjdmcw.jpg](/t5/image/serverpage/image-id/109904i30C53059CFD2F5CB/image-size/large?v=v2&px=999)
5/ 在弹出的窗口下,[url=]选择版本/平台/特性,查看一下是否包含我们现在运行的版本,Done![/url]
![215502yxxxuyu639c3693v.jpg 215502yxxxuyu639c3693v.jpg](/t5/image/serverpage/image-id/109905iA56C0D0200D9E9C4/image-size/large?v=v2&px=999)
OK,结束了 最后还有一个大招,如果搞不定,请拨 400-810-8886开 TAC case!:lol