#!/usr/bin/perl use strict; =comment This script looks at the past 10 minutes of CPU Wait readings and generates an email notification based on the settings of $wait_maximum and $wait_maximum_occurs =cut use Net::SMTP; require "graphVM.lib"; my ($logdate) = @ARGV; my $log_in = 'vmstatlog.'.$logdate; my $log_out = 'vmstatlog_out.'.$logdate; open (VMSTATS_FILE_OUT, ">$log_out"); my $content = `tail -n 120 $log_in`; my @content_array = split(/\n/,$content); #my $date_month = substr($logdate,0,2); #my $date_day = substr($logdate,2,2); #my $date_year = substr($logdate,4,2); #my $date_today = $date_month.'/'.$date_day.'/'.$date_year; my $date_today = `date --date='10 minutes ago' +"%D %T"`; chomp($date_today); my $date_new; my $seconds_count = 0; my $line_record; my $wait_maximum = 95; my $wait_maximum_occurs = 119; my $wait_maximum_count = 0; foreach $line_record (@content_array) { $date_new = `date --date='$date_today $seconds_count seconds' +"%D %T"`; chomp($date_new); print VMSTATS_FILE_OUT $date_new.' '; print VMSTATS_FILE_OUT $line_record."\n"; $seconds_count = $seconds_count+5; my @line_array = split(/\s+/,$line_record); if (@line_array[16] > $wait_maximum) { $wait_maximum_count++; } } close (VMSTATS_FILE_OUT); ###mail my ($message_subject,$send_message,$message_importance); if ($wait_maximum_count > $wait_maximum_occurs) { $message_subject = "Subject: Trident System Notice - cpu wait $wait_maximum/$wait_maximum_count"; $send_message = "Trident System Notice - the cpu wait maximum of $wait_maximum has been exceeded more than $wait_maximum_occurs times at $wait_maximum_count occurences. \nhttp://nautilus.baruch.sc.edu/stats/vmstats.php"; } if ($send_message) { my $send_list = <<"END_OF_LIST"; This message was sent to the following persons: jcothran\@carocoops.org; pseal\@inlet.geol.sc.edu END_OF_LIST $send_message = $send_message.$send_list; my $smtp; $smtp = Net::SMTP->new("nautilus.baruch.sc.edu"); $smtp->mail("jcothran\@carocoops.org"); my $testing = 0; #1=testing, 0=production if ($testing) { $send_message = "DISREGARD THIS MESSAGE - THIS IS A TEST MESSAGE ONLY \n".$send_message; $smtp->to("jcothran\@carocoops.org", { SkipBad => 1 }); } else { $smtp->to("jcothran\@carocoops.org", "pseal\@inlet.geol.sc.edu", { SkipBad => 1 }); } $smtp->data();$smtp->datasend($message_importance);$smtp->datasend($message_subject); $smtp->datasend("\n"); $smtp->datasend($send_message); $smtp->dataend(); $smtp->quit(); } exit 0;