使用 EEM 脚本监控在思科 Catalyst 系列交换机的高 CPU 利用率 目录 简介先决条件要求使用的组件规则背景信息故障排除获取在 CPU 峰值事件的数据的 EEM 在 2960X 的 电子邮件告警对本地文件的追加的输出追加输出到本地文件并且删除脚本收集输出并且写到本地文件在模块化 IOS 的箴言报 CPU 利用率删除脚本相关信息 简介 本文描述如何使用 Cisco IOS 被嵌入的活动管理器 (EEM) 子系统为了监控在思科 Catalyst 系列交换机的高 CPU 利用率 先决条件 要求 本文假设, 用户有知识 Cisco IOS 被嵌入的活动管理器 (EEM) 使用的组件 本文档中的信息根据思科 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;Catalyst 4500 交换机允许 EEM 写入到 Bootflash; 并且 Catalyst 6500 交换机允许 EEM 使用 disk0 和超级启动盘 Note: 使用命令查找工具 ( 仅限注册用户 ) 可获取有关本部分所使用命令的详细信息 获取在 CPU 峰值事件的数据的 EEM 在 2960X 的 Catalyst 2960X 不支持闪烁的添附 下面 EEM 将重定向在各自文件的获取数据在 flash: 从 EEM 的为时运行的 /TAC logging buffered 8192 informational process cpu threshold type total rising 80 interval 5! 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 " action 022 syslog msg "EEM: Finished removing from configuration!" action 023 cli command "end" 电子邮件告警 当 CPU 利用率在 50 百分比上时, 去此脚本给警报发电子邮件 电子邮件的正文是 show process CPU 排序的命令的输出 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 pollinterval 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 - 活动管理器 app 的名称 让 / 脚本 1.3.6.1.4.1.9.9.109.1.1.1.1.3.1 - 轮询的路由处理器 (RP) 的总 CPU 利用率 Object Identifier (OID) 50 - 触发脚本的 CPU 利用率 轮询间隔时间 - 频率 ( 每 秒 ) 脚本监控 CPU 192.169.1.1 - 邮件服务器的 IP 对本地文件的追加的输出 此脚本添附需要的输出到文件在本地文件系统 用在交换机的适当的文件系统替换文件系统 event manager scheduler script thread class default number 1 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 pollinterval action 0.0 syslog msg "High CPU DETECTED. Please wait - logging Information to file system:high_cpu.txt" action 0.2 cli command "show clock append file system:high_cpu.txt" action 1.2 cli command "term length 0" 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 排序的命令的输出到文件在本地文件系统, 然后删除曾经完成 用在交换机的适当的文件系统替换文件系统
event manager scheduler script thread class default number 1 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 pollinterval action 0.0 syslog msg "High CPU DETECTED. Please wait - logging Information to flash:high_cpu.txt" action 0.2 cli command "term exec prompt timestamp" 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 " 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 利用率 思科 EEM 可能也用于监控在模块化 IOS 的 CPU 利用率 由于在 CPU 如何的差异在模块化 IOS 监控, 您能使用简单网络管理协议 (SNMP) OID (1.3.6.1.4.1.9.9.109.1.1.1.1.3.1) 为了由 IOS 基础进程检查 CPU 利用率 此脚本使用 OID 作为触发并且写入需要的输出到本地文件系统 用在交换机的适当的文件系统替换文件系统 event manager scheduler script thread class default number 1 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 pollinterval action 0.0 syslog msg "High CPU DETECTED. Please wait - logging Information to file system:high_cpu.txt" action 0.2 cli command "show clock append file system:high_cpu.txt" action 1.2 cli command "term length 0" 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 相关信息 技术支持和文档 - Cisco Systems