01-15-2015 06:19 AM
Hello,
from time to time we are experiencing high cpu-load. I try to find out who is responsible for that load and i've found that example of an eem-script:
event manager applet high_cpu_load
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 95 poll-interval 1
action 0.0 syslog msg "High CPU DETECTED. Logging Information to disk0:high_cpu.txt"
action 0.1 cli command "enable"
action 0.2 cli command "show clock | append disk0:high_cpu.txt"
action 1.2 cli command "term length 0"
action 1.3 cli command "show process cpu sorted | append disk0:high_cpu.txt"
action 1.4 cli command "term length 50"
So far so good, but im not well versed in eem scripting. Can anybody help to modify this script so that it is able to filter out the 0.00% lines from the show process cpu sorted command? The command "show process cpu sorted | e 0.00& | append disk0:high_cpu.txt" doesn't work. Further it would be nice to have a single txt-file for every event like high_cpu_1.txt, high_cpu_2.txt an so on, instead of one big file.
Thanks in advance,
Stephan
01-15-2015 09:38 AM
This is an age-old issue with EEM. Only very recent versions of IOS can do direct file writes to enable this in applets. Else you'll have to switch to Tcl. What version of IOS do you have?
01-19-2015 12:25 AM
IP-Services 151-2.SY4
01-19-2015 10:43 AM
I believe that is EEM 3.0, so you will have to switch to Tcl to do what you want. Change your CLI command to "show proc cpu sort | exc 0.00", then take this applet to http://www.marcuscom.com/convert_applet/ . In the resulting Tcl policy, add the following after you run each command:
append output $_cli_result
Then at the end of the script:
set fd [open "disk0:high_cpu.txt" a]
puts $fd $output
close $fd
01-20-2015 12:02 AM
Hi Joseph,
that ist the output i get:
namespace import ::cisco::eem::*
namespace import ::cisco::lib::*
array set arr_einfo [event_reqinfo]
if [catch {cli_open} result] {
error $result $errorInfo
} else {
array set cli1 $result
}
action_syslog msg "High CPU DETECTED. Logging Information to disk0:high_cpu.txt"
if [catch {cli_exec $cli1(fd) "enable"} _cli_result] {
error $_cli_result $errorInfo
}
if [catch {cli_exec $cli1(fd) "show clock"} _cli_result] {
error $_cli_result $errorInfo
}
if [catch {cli_exec $cli1(fd) "term length 0"} _cli_result] {
error $_cli_result $errorInfo
}
if [catch {cli_exec $cli1(fd) "sh processes cpu sorted | exclude 0.00"} _cli_result] {
error $_cli_result $errorInfo
}
if [catch {cli_exec $cli1(fd) "term length 50"} _cli_result] {
error $_cli_result $errorInfo
}
# Close open cli before exit.
catch {cli_close $cli1(fd) $cli1(tty_id)} result
As aforementioned i have no experiences with tcl scripts, so where exactely have i to put in the additional lines?
Discover and save your favorite ideas. Come back to expert answers, step-by-step guides, recent topics, and more.
New here? Get started with these tips. How to use Community New member guide