简介
本文档介绍如何使用Cisco IOS®嵌入式事件管理器(EEM)子系统来监控Cisco Catalyst系列交换机上的高CPU利用率。
先决条件
要求
本文档假设用户了解Cisco IOS嵌入式事件管理器(EEM)。
使用的组件
本文档中的信息基于Cisco Catalyst系列交换机。
本文档中的信息都是基于特定实验室环境中的设备编写的。本文档中使用的所有设备最初均采用原始(默认)配置。如果您使用的是真实网络,请确保您已经了解所有命令的潜在影响。
规则
有关文档规则的信息,请参阅 Cisco 技术提示规则。
背景信息
EEM是非常有用的工具,可排除偶发的、偶发的CPU尖峰,这些尖峰的寿命很短,并且难以通过命令行界面手动排除故障。以下是CPU峰值的示例:
Switch#show process cpu history
<snip>
11111822511 11 111277711111 124111 11 1211111112161116
143342171209994090111878458239607111981270283361362429475
100
90
80 * ***
70 * *** *
60 * *** * *
50 * * *** * * *
40 * * *** * * *
30 * ** *** * * *
20 **** **** ** *** ** * ** ** **
10 *********************************************************
0....5....1....1....2....2....3....3....4....4....5....5....6....6....7.
0 5 0 5 0 5 0 5 0 5 0 5 0
CPU% per hour (last 72 hours)
* = maximum CPU% # = average CPU%
故障排除
本部分包括使用EEM脚本监控CPU利用率的几个示例。Catalyst 2960和3750交换机允许EEM使用非易失性RAM(NVRAM);Catalyst 4500交换机允许EEM写入bootflash;和Catalyst 6500交换机允许EEM使用disk0和sup-bootdisk。
注意:使用命令查找工具(仅限注册用户)可获取有关本部分所使用命令的详细信息。
EEM用于在2960X上出现CPU峰值时捕获数据。
Catalyst 2960X不支持附加到闪存。下面的EEM将从EEM的上次运行中重定向闪存:/TAC中各个文件中捕获的数据。
logging buffered 8192 informational
process cpu threshold type total rising 80 interval 5
!
event manager applet High_CPU authorization bypass
event syslog pattern "CPURISINGTHRESHOLD"
action 001 syslog msg "EEM: HIGH CPU detected. Writing info to flash:"
action 002 cli command "enable"
action 003 cli command "term exec prompt timestamp"
action 004 cli command "term len 0"
action 005 cli command "mkdir TAC" pattern "Create.*"
action 006 cli command "TAC" pattern "Create.*"
action 007 cli command " "
action 008 cli command "show process cpu sorted | redirect flash:TAC/TAC_CPU.txt"
action 009 cli command "show buffers | redirect flash:TAC/TAC_Buffers.txt"
action 010 cli command "show interfaces summary | redirect flash:TAC/TAC_IntSumm.txt"
action 011 cli command "show interfaces stats | redirect flash:TAC/TAC_IntStat.txt"
action 012 cli command "show ip traffic | redirect flash:TAC/TAC_IPTraffic.txt"
action 013 cli command "show ip cef switching statistics | redirect flash:TAC/TAC_IPCef.txt"
action 014 cli command "show controllers cpu-interface | redirect flash:TAC/TAC_Controllers.txt"
action 015 cli command "show platform port-asic stats drop | redirect flash:TAC/TAC_Port-Asic.txt"
action 016 cli command "show platform ip unicast statistics | redirect flash:TAC/TAC_UnicastStats.txt"
action 017 cli command "show platform ip unicast counts | redirect flash:TAC/TAC_UnicastCounts.txt"
action 018 cli command "show platform tcam utilization | redirect flash:TAC/TAC_TCAM.txt"
action 019 syslog msg "EEM: Self-removing applet from configuration..."
action 020 cli command "configure terminal"
action 021 cli command "no event manager applet High_CPU"
action 022 syslog msg "EEM: Finished removing from configuration!"
action 023 cli command "end"
电子邮件警报
当CPU利用率超过50%时,此脚本会发送警报。邮件正文是show process cpu sorted命令的输出。
event manager applet highcpu
event snmp oid 1.3.6.1.4.1.9.9.109.1.1.1.1.3.1 get-type exact entry-op ge entry-val 50 poll-interval 0.5
action 1.0 cli command "enable"
action 2.0 cli command "show proc cpu sorted"
action 3.0 mail server "192.168.1.1" to "user-to@domain.com" from "user-from@domain.com" subject "High CPU Alert" body "$_cli_result"
斜体变量的定义如下:
- highcpu — 事件管理器应用的名称
- let/script
- 1.3.6.1.4.1.9.109.1.1.1.1.3.1 — 用于轮询路由处理器(RP)的CPU总利用率的对象标识符(OID)
- 50 — 触发脚本的CPU利用率
- poll-interval 0.5 — 脚本监控CPU的频率(每0.5秒)
- 192.169.1.1 — 邮件服务器的IP
将输出附加到本地文件
此脚本将所需输出附加到本地文件系统中的文件。将文件系统替换为交换机上的相应文件系统。
event manager scheduler script thread class default number 1
event manager applet High_CPU
event snmp oid 1.3.6.1.4.1.9.9.109.1.1.1.1.3.1 get-type exact entry-op ge entry-val 50 poll-interval 0.5
action 0.0 syslog msg "High CPU DETECTED. Please wait - logging Information to file system:high_cpu.txt"
action 0.1 cli command "enable"
action 0.2 cli command "show clock | append file system:high_cpu.txt"
action 1.2 cli command "term length 0"
action 1.3 cli command "show process cpu sorted | append file system:high_cpu.txt"
action 1.4 cli command "show log | append file system:high_cpu.txt"
action 1.5 cli command "show interfaces | append file system:high_cpu.txt"
action 1.6 cli command "term length 24"
将输出附加到本地文件并删除脚本
此脚本将show process cpu sorted命令的输出附加到本地文件系统中的文件,然后在完成后将其删除。将文件系统替换为交换机上的相应文件系统。
event manager scheduler script thread class default number 1
event manager applet High_CPU
event snmp oid 1.3.6.1.4.1.9.9.109.1.1.1.1.3.1 get-type exact entry-op gt entry-val 50 poll-interval 0.5
action 0.0 syslog msg "High CPU DETECTED. Please wait - logging Information to flash:high_cpu.txt"
action 0.1 cli command "enable"
action 0.2 cli command "term exec prompt timestamp"
action 1.3 cli command "show process cpu sorted | append file system:high_cpu.txt"
action 1.4 cli command "show process cpu sorted | append file system:high_cpu.txt"
action 1.4 cli command "show process cpu sorted | append file system:high_cpu.txt"
action 5.1 syslog msg "Finished logging information to file system:high_cpu.txt..."
action 5.1 syslog msg "Self-removing applet from configuration..."
action 5.2 cli command "term no exec prompt timestamp"
action 9.1 cli command "configure terminal"
action 9.2 cli command "no event manager applet High_CPU"
action 9.3 cli command "end"
收集输出并写入本地文件
此脚本使用基于系统日志的触发器来运行和收集所需输出,并将这些输出写入本地文件系统。将文件系统替换为交换机上的相应文件系统。
process cpu threshold type total rising 70 interval 15
event manager applet DETECT_CPU
event syslog pattern ".*SYS-1-CPURISINGTHRESHOLD.*"
action 1 cli command "en"
action 2 cli command "show clock | append file system:cpuinfo"
action 3 cli command "show proc cpu sort | append file system:cpuinfo"
action 4 cli command "show line | append file system:cpuinfo"
监控模块化IOS上的CPU利用率
Cisco EEM还可用于监控模块化IOS上的CPU利用率。由于模块化IOS上CPU的监控方式不同,您可以使用简单网络管理协议(SNMP)OID(1.3.6.1.4.1.9.109.1.1.1.3.1)来检查IOS基本进程的CPU利用率。
此脚本使用OID作为触发器,并将所需输出写入本地文件系统。将文件系统替换为交换机上的相应文件系统。
event manager scheduler script thread class default number 1
event manager applet High_CPU
event snmp oid 1.3.6.1.4.1.9.9.109.1.1.1.1.10.1 get-type exact entry-op ge entry-val 50 poll-interval 0.5
action 0.0 syslog msg "High CPU DETECTED. Please wait - logging Information to file system:high_cpu.txt"
action 0.1 cli command "enable"
action 0.2 cli command "show clock | append file system:high_cpu.txt"
action 1.2 cli command "term length 0"
action 1.3 cli command "show process cpu sorted | append file system:high_cpu.txt"
action 1.4 cli command "show log | append file system:high_cpu.txt"
action 1.5 cli command "show interfaces | append file system:high_cpu.txt"
action 1.6 cli command "term length 24"
删除脚本
输入以下命令以删除EEM脚本:
Switch(config)#no event manager applet applet name
相关信息