<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: script to calculate mpstat output in Operating System - Linux</title>
    <link>https://community.hpe.com/t5/operating-system-linux/script-to-calculate-mpstat-output/m-p/3765111#M101893</link>
    <description>&lt;BR /&gt;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.&lt;BR /&gt;&lt;BR /&gt;Anyway...&lt;BR /&gt;&lt;BR /&gt;If I understand your description correctly, then the following perl script can detect the condition.&lt;BR /&gt;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.&lt;BR /&gt;&lt;BR /&gt;hth,&lt;BR /&gt;Hein.&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;---- &lt;BR /&gt;$number = shift @ARGV;&lt;BR /&gt;$maxuse = shift @ARGV or die "Please pass &lt;NUMBER-OF-CPUS&gt; and &lt;MAX-USAGE&gt; numbers";&lt;BR /&gt;while (&amp;lt;&amp;gt;) {&lt;BR /&gt;  if (/^CPU/) {$n = 0; $text=""; $block++; next};&lt;BR /&gt;  ($cpu, $usr,$sys)= (split)[0,12,13];&lt;BR /&gt;  $use = $usr + $sys;&lt;BR /&gt;  if (($use) &amp;gt; $maxuse) {&lt;BR /&gt;     $text .= " $cpu:$use";&lt;BR /&gt;     $n++;&lt;BR /&gt;     if ($n==$number) {&lt;BR /&gt;        print "Max cpu exceeded in block $block. $text\n";&lt;BR /&gt;        $alerts++;&lt;BR /&gt;        }&lt;BR /&gt;  }&lt;BR /&gt;}&lt;BR /&gt;print "\nTotal number of alert conditions: $alerts\n" if $alerts;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;---- usage sample based on second part of attachment ---&lt;BR /&gt;&lt;BR /&gt;C:\Temp&amp;gt;perl tmp.pl  3 50 tmp.txt&lt;BR /&gt;Max cpu exceeded in block 2.  0:63 1:99 2:99&lt;BR /&gt;Max cpu exceeded in block 3.  0:54 1:95 2:79&lt;BR /&gt;&lt;BR /&gt;C:\Temp&amp;gt;perl tmp.pl  2 90 tmp.txt&lt;BR /&gt;Max cpu exceeded in block 2.  1:99 2:99&lt;BR /&gt;&lt;BR /&gt;&lt;/MAX-USAGE&gt;&lt;/NUMBER-OF-CPUS&gt;</description>
    <pubDate>Tue, 04 Apr 2006 08:39:01 GMT</pubDate>
    <dc:creator>Hein van den Heuvel</dc:creator>
    <dc:date>2006-04-04T08:39:01Z</dc:date>
    <item>
      <title>script to calculate mpstat output</title>
      <link>https://community.hpe.com/t5/operating-system-linux/script-to-calculate-mpstat-output/m-p/3765107#M101889</link>
      <description>I have one Solaris machine that output the mpstat output.  I have another HPUX server will pick up and process the file.&lt;BR /&gt;&lt;BR /&gt;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.</description>
      <pubDate>Tue, 04 Apr 2006 04:15:14 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/script-to-calculate-mpstat-output/m-p/3765107#M101889</guid>
      <dc:creator>kholikt</dc:creator>
      <dc:date>2006-04-04T04:15:14Z</dc:date>
    </item>
    <item>
      <title>Re: script to calculate mpstat output</title>
      <link>https://community.hpe.com/t5/operating-system-linux/script-to-calculate-mpstat-output/m-p/3765108#M101890</link>
      <description>Hi, &lt;BR /&gt;could be something like following script. &lt;BR /&gt;save it to some-name.pl and set +x permission, &lt;BR /&gt;then run:&lt;BR /&gt;some-name.pl &amp;lt; your-input-file&lt;BR /&gt;&lt;BR /&gt;hope this helps. &lt;BR /&gt;antonio.&lt;BR /&gt;&lt;BR /&gt;---------------------------------------&lt;BR /&gt;#!/bin/env perl &lt;BR /&gt;&lt;BR /&gt;my @lines = &lt;STDIN&gt;;&lt;BR /&gt;my %cpusld=();&lt;BR /&gt;my $cpu, $load;&lt;BR /&gt;foreach (@lines) {&lt;BR /&gt; 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+)/) {&lt;BR /&gt;  # print "== $1 - $13 - $14 \n";&lt;BR /&gt;  $cpu=$1;&lt;BR /&gt;  $load=$13+$14;&lt;BR /&gt;  if (exists $cpusld{$cpu}) {&lt;BR /&gt;   $cpusld{$cpu}-&amp;gt;{'load'} += $load;&lt;BR /&gt;   $cpusld{$cpu}-&amp;gt;{'nb'} ++;&lt;BR /&gt;  } else {&lt;BR /&gt;   $cpusld{$cpu}-&amp;gt;{'load'} = $load;&lt;BR /&gt;   $cpusld{$cpu}-&amp;gt;{'nb'} = 1;&lt;BR /&gt;  }&lt;BR /&gt;  # print $cpu."==&amp;gt;".$cpusld{$cpu}-&amp;gt;{'load'}." - ".$cpusld{$cpu}-&amp;gt;{'nb'}."\n"&lt;BR /&gt; }&lt;BR /&gt;}&lt;BR /&gt;&lt;BR /&gt;my $mail_text="";&lt;BR /&gt;foreach $cpu (sort(keys %cpusld)) {&lt;BR /&gt; my $avld=$cpusld{$cpu}-&amp;gt;{'load'} / $cpusld{$cpu}-&amp;gt;{'nb'};&lt;BR /&gt; print "average CPU load ($cpu) ==&amp;gt; $avld\n";&lt;BR /&gt; if ($avld &amp;gt; 90) {&lt;BR /&gt;  $mail_text.="average CPU load ($cpu) ==&amp;gt; $avld\n";&lt;BR /&gt; }&lt;BR /&gt;}&lt;BR /&gt;&lt;BR /&gt;if ($mail_text ne "") {&lt;BR /&gt;    open(FD,"&amp;gt;/tmp/tmpmail.sh") || die ("-E- can't open file: /tmp/tmpmail.txt for writing ($!)");&lt;BR /&gt; print FD "#!/bin/sh\n";&lt;BR /&gt; print FD 'mail -s "overload-problem" user@domain-name &amp;lt;&amp;lt; EOF'."\n";&lt;BR /&gt; print FD $mail_text;&lt;BR /&gt; print FD "EOF\n";&lt;BR /&gt; close FD;&lt;BR /&gt; `chmod +x /tmp/tmpmail.sh`; &lt;BR /&gt; system("/tmp/tmpmail.sh");&lt;BR /&gt;} else {&lt;BR /&gt; print "no alert \n";&lt;BR /&gt;}&lt;BR /&gt;&lt;/STDIN&gt;</description>
      <pubDate>Tue, 04 Apr 2006 05:08:50 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/script-to-calculate-mpstat-output/m-p/3765108#M101890</guid>
      <dc:creator>Antonio Cardoso_1</dc:creator>
      <dc:date>2006-04-04T05:08:50Z</dc:date>
    </item>
    <item>
      <title>Re: script to calculate mpstat output</title>
      <link>https://community.hpe.com/t5/operating-system-linux/script-to-calculate-mpstat-output/m-p/3765109#M101891</link>
      <description>Kholikt,&lt;BR /&gt;&lt;BR /&gt;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 ?&lt;BR /&gt;&lt;BR /&gt;Regards,&lt;BR /&gt;Ninad</description>
      <pubDate>Tue, 04 Apr 2006 05:12:17 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/script-to-calculate-mpstat-output/m-p/3765109#M101891</guid>
      <dc:creator>Ninad_1</dc:creator>
      <dc:date>2006-04-04T05:12:17Z</dc:date>
    </item>
    <item>
      <title>Re: script to calculate mpstat output</title>
      <link>https://community.hpe.com/t5/operating-system-linux/script-to-calculate-mpstat-output/m-p/3765110#M101892</link>
      <description>the file is copy and paste error.  I only monitored one server.  This particular solaris servers has 8 core.  From the mpstat output I need to monitor 3 out of this 8 core is having CPU utilization of 90% then I will get the alert</description>
      <pubDate>Tue, 04 Apr 2006 06:35:42 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/script-to-calculate-mpstat-output/m-p/3765110#M101892</guid>
      <dc:creator>kholikt</dc:creator>
      <dc:date>2006-04-04T06:35:42Z</dc:date>
    </item>
    <item>
      <title>Re: script to calculate mpstat output</title>
      <link>https://community.hpe.com/t5/operating-system-linux/script-to-calculate-mpstat-output/m-p/3765111#M101893</link>
      <description>&lt;BR /&gt;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.&lt;BR /&gt;&lt;BR /&gt;Anyway...&lt;BR /&gt;&lt;BR /&gt;If I understand your description correctly, then the following perl script can detect the condition.&lt;BR /&gt;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.&lt;BR /&gt;&lt;BR /&gt;hth,&lt;BR /&gt;Hein.&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;---- &lt;BR /&gt;$number = shift @ARGV;&lt;BR /&gt;$maxuse = shift @ARGV or die "Please pass &lt;NUMBER-OF-CPUS&gt; and &lt;MAX-USAGE&gt; numbers";&lt;BR /&gt;while (&amp;lt;&amp;gt;) {&lt;BR /&gt;  if (/^CPU/) {$n = 0; $text=""; $block++; next};&lt;BR /&gt;  ($cpu, $usr,$sys)= (split)[0,12,13];&lt;BR /&gt;  $use = $usr + $sys;&lt;BR /&gt;  if (($use) &amp;gt; $maxuse) {&lt;BR /&gt;     $text .= " $cpu:$use";&lt;BR /&gt;     $n++;&lt;BR /&gt;     if ($n==$number) {&lt;BR /&gt;        print "Max cpu exceeded in block $block. $text\n";&lt;BR /&gt;        $alerts++;&lt;BR /&gt;        }&lt;BR /&gt;  }&lt;BR /&gt;}&lt;BR /&gt;print "\nTotal number of alert conditions: $alerts\n" if $alerts;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;---- usage sample based on second part of attachment ---&lt;BR /&gt;&lt;BR /&gt;C:\Temp&amp;gt;perl tmp.pl  3 50 tmp.txt&lt;BR /&gt;Max cpu exceeded in block 2.  0:63 1:99 2:99&lt;BR /&gt;Max cpu exceeded in block 3.  0:54 1:95 2:79&lt;BR /&gt;&lt;BR /&gt;C:\Temp&amp;gt;perl tmp.pl  2 90 tmp.txt&lt;BR /&gt;Max cpu exceeded in block 2.  1:99 2:99&lt;BR /&gt;&lt;BR /&gt;&lt;/MAX-USAGE&gt;&lt;/NUMBER-OF-CPUS&gt;</description>
      <pubDate>Tue, 04 Apr 2006 08:39:01 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/script-to-calculate-mpstat-output/m-p/3765111#M101893</guid>
      <dc:creator>Hein van den Heuvel</dc:creator>
      <dc:date>2006-04-04T08:39:01Z</dc:date>
    </item>
  </channel>
</rss>

