Junos Automation (Scripting)
Reply
Contributor
ralwarrag
Posts: 138
Registered: ‎09-21-2010
0

event script for CPU utilization

Hi

I would like to write script ( event script ) that when ever there is high CPU utilization above the 60 % send me the output of  " show system processes extensive " to an FTP , so i can know which process at that time cause the high CPU

 

 Many Thanks

 

BR ,,,
Recognized Expert
Mattia
Posts: 198
Registered: ‎03-17-2010
0

Re: event script for CPU utilization

Hi Rashed, a possible approach which doesn't require a script but just some configuration may be to configure healt-monitoring or RMON (if they are supported on your platform) in order to log a specific message whenever the cpu rises above 60%; then you can write an event-policy to intercept the log message, to execute the operational commands and to store the output on an ftp server.

The policy would be like that:

 

root# show event-options 
policy SHOW_HIGH_CPU_PROCESSES {
    events <THE EVENT GENERATED BY RMON OR HEALTH-MONITOR>;
    then {
        execute-commands {
            commands {
                "show system processes extensive";
            }
            output-filename SYSTEM_PROCESSES;
            destination FTP_SERVER;
            output-format text;
        }
    }
}
destinations {
    FTP_SERVER {
        archive-sites {
            "ftp://user@1.1.1.1/var/tmp" password "$9$BPH1crLx-sY4"; ## SECRET-DATA
        }
    }
}

As for the generation of the event, personally I never used health monitoring or RMON, but it seems quite simple to configure.

Here is some reference documentation:

Health-Monitoring

RMON

 

Cheers,

Mattia

 

.................................................................................
JNCIP-ENT, JNCIP-SEC, JNCIS-SP
(If this post helped you, please mark it as an "Accepted Solution"; kudos are also appreciated!)


Contributor
ralwarrag
Posts: 138
Registered: ‎09-21-2010
0

Re: event script for CPU utilization

Hi Mattia

Thanks alot for your reply i just add those command but i am not sure if this is the right way to configure it  , i am not sure what should i write under the events " events [ jnxOperatingCPU jnxOperatingCPU.9.1.0.0 ]; "

 

many thanks once again

 

[edit]
+  event-options {
+      policy MON_CPU {
+          events [ jnxOperatingCPU jnxOperatingCPU.9.1.0.0 ];
+          then {
+              execute-commands {
+                  commands {
+                      "show system processes extensive";
+                  }
+                  output-filename CPU-Output;
+                  destination DNOC_FTP_SERVER;
+                  output-format text;
+              }
+          }
+      }
+      destinations {
+          DNOC_FTP_SERVER {
+              archive-sites {
+                  "ftp://noc:noc123@1.1.1.1/";
+              }
+          }
+      }
+  }
[edit snmp]
+   health-monitor {
+       rising-threshold 3;
+   }

BR ,,,
Trusted Expert
Trusted Expert
jtb
Posts: 314
Registered: ‎08-26-2009
0

Re: event script for CPU utilization

hi,

 

following config works on EX2200 running 11.4R2.14. Tune the thresholds/matching regex/event destination/etc to your needs. High CPU utilization test triggered with long snmpwalk towards EX.

 

snmp {
    health-monitor {
        interval 30;
        rising-threshold 60;
        falling-threshold 50;
    }
}


event-options {
    policy MONITOR-CPU {
        events snmpd_health_mon_thresh_cross;
        attributes-match {
            snmpd_health_mon_thresh_cross.event-name matches "Health Monitor.+CPU.+rising";
        }
        then {
            execute-commands {
                commands {
                    "show system processes extensive";
                }
                output-filename cpu-processes;
                destination local-flash;
                output-format text;
            }
        }                               
    }
    destinations {
        local-flash {
            archive-sites {
                /var/tmp;
            }
        }
    }
}

 

jtb

Contributor
ralwarrag
Posts: 138
Registered: ‎09-21-2010
0

Re: event script for CPU utilization

I thanks i think it's better to use RMON if you would like to monitor spacific hardware by writing the OID of it 

 

 

 

[edit]
+ event-options {
+ policy Monitor-CPU {
+ events SNMPD_RMON_EVENTLOG;
+ attributes-match {
+ snmpd_rmon_eventlog.message matches "Event 100 triggered";
+ }
+ then {
+ execute-commands {
+ commands {
+ "show system processes extensive |no-more";
+ "show chassis routing-engine | no-more";
+ }
+ output-filename cpu-data;
+ destination FTP_SERVER;
+ output-format text;
+ }
+ }
+ }
+ destinations {
+ FTP_SERVER {
+ archive-sites {
+ /var/tmp/;
+ }
+ }
+ }
+ }
[edit snmp]
+ rmon {
+ alarm 10 {
+ description CPU-Alarm;
+ interval 2;
+ falling-threshold-interval 5;
+ variable 1.3.6.1.4.1.2636.3.1.13.1.8.9.1.0.0;
+ sample-type absolute-value;
+ request-type get-request;
+ rising-threshold 70;
+ falling-threshold 1;
+ rising-event-index 100;
+ falling-event-index 100;
+ syslog-subtag CPUHIGHT;
+ }
+ event 100 {
+ description "CPU Utilization above the 60%";
+ type log;
+ }
+ }

{master}[edit]

 

BR ,,,
Copyright© 1999-2013 Juniper Networks, Inc. All rights reserved.