簡介
本文說明如何使用Cisco IOS® Embedded Event Manager(EEM)子系統監控Cisco Catalyst系列交換器上的高CPU使用率。
必要條件
需求
本檔案假設使用者知道Cisco IOS內嵌式事件管理員(EEM)。
採用元件
本檔案中的資訊是根據Cisco Catalyst系列交換器。
本文中的資訊是根據特定實驗室環境內的裝置所建立。文中使用到的所有裝置皆從已清除(預設)的組態來啟動。如果您的網路正在作用,請確保您已瞭解任何指令可能造成的影響。
慣例
如需檔案慣例的相關資訊,請參閱思科技術提示慣例。
背景資訊
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會將flash:/TAC中各自檔案中的擷取資料重新導向上次執行EEM。
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.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.9.109.1.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
相關資訊