- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - Linux
- >
- script to calculate mpstat output
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Discussions
Discussions
Discussions
Forums
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО04-03-2006 09:15 PM
тАО04-03-2006 09:15 PM
script to calculate mpstat output
Bascially the mpstat show the individual CPU utilization of the core. I need to write some alert script for CPU performance when any of the 3 CPU reach average 90% busy.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО04-03-2006 10:08 PM
тАО04-03-2006 10:08 PM
Re: script to calculate mpstat output
could be something like following script.
save it to some-name.pl and set +x permission,
then run:
some-name.pl < your-input-file
hope this helps.
antonio.
---------------------------------------
#!/bin/env perl
my @lines =
my %cpusld=();
my $cpu, $load;
foreach (@lines) {
if (m/\s*(\d+)\s+(\d+)\s+(\d+)\s+(\d+)\s+(\d+)\s+(\d+)\s+(\d+)\s+(\d+)\s+(\d+)\s+(\d+)\s+(\d+)\s+(\d+)\s+(\d+)\s+(\d+)\s+(\d+)\s+(\d+)/) {
# print "== $1 - $13 - $14 \n";
$cpu=$1;
$load=$13+$14;
if (exists $cpusld{$cpu}) {
$cpusld{$cpu}->{'load'} += $load;
$cpusld{$cpu}->{'nb'} ++;
} else {
$cpusld{$cpu}->{'load'} = $load;
$cpusld{$cpu}->{'nb'} = 1;
}
# print $cpu."==>".$cpusld{$cpu}->{'load'}." - ".$cpusld{$cpu}->{'nb'}."\n"
}
}
my $mail_text="";
foreach $cpu (sort(keys %cpusld)) {
my $avld=$cpusld{$cpu}->{'load'} / $cpusld{$cpu}->{'nb'};
print "average CPU load ($cpu) ==> $avld\n";
if ($avld > 90) {
$mail_text.="average CPU load ($cpu) ==> $avld\n";
}
}
if ($mail_text ne "") {
open(FD,">/tmp/tmpmail.sh") || die ("-E- can't open file: /tmp/tmpmail.txt for writing ($!)");
print FD "#!/bin/sh\n";
print FD 'mail -s "overload-problem" user@domain-name << EOF'."\n";
print FD $mail_text;
print FD "EOF\n";
close FD;
`chmod +x /tmp/tmpmail.sh`;
system("/tmp/tmpmail.sh");
} else {
print "no alert \n";
}
- Tags:
- Perl
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО04-03-2006 10:12 PM
тАО04-03-2006 10:12 PM
Re: script to calculate mpstat output
Your requirement is not very clear. You say average of 3 CPU - but the outputs you have shown seem to be for 2 different servers - one having 5 CPUs and other 8 CPUs, so what do you mean by average of 3 CPUs ?
Regards,
Ninad
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО04-03-2006 11:35 PM
тАО04-03-2006 11:35 PM
Re: script to calculate mpstat output
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО04-04-2006 01:39 AM
тАО04-04-2006 01:39 AM
Re: script to calculate mpstat output
Hmmm, that seems a rather arbitrary alert condition. It suggests that you do not trust the scheduler to 'do the right thing' or that the application has extensive scheduling control.
Anyway...
If I understand your description correctly, then the following perl script can detect the condition.
You woudld have to combine it with Antonio's code to make it send out mail. And you may or might not augment it to report the actual exceeding amounts.
hth,
Hein.
----
$number = shift @ARGV;
$maxuse = shift @ARGV or die "Please pass
while (<>) {
if (/^CPU/) {$n = 0; $text=""; $block++; next};
($cpu, $usr,$sys)= (split)[0,12,13];
$use = $usr + $sys;
if (($use) > $maxuse) {
$text .= " $cpu:$use";
$n++;
if ($n==$number) {
print "Max cpu exceeded in block $block. $text\n";
$alerts++;
}
}
}
print "\nTotal number of alert conditions: $alerts\n" if $alerts;
---- usage sample based on second part of attachment ---
C:\Temp>perl tmp.pl 3 50 tmp.txt
Max cpu exceeded in block 2. 0:63 1:99 2:99
Max cpu exceeded in block 3. 0:54 1:95 2:79
C:\Temp>perl tmp.pl 2 90 tmp.txt
Max cpu exceeded in block 2. 1:99 2:99