<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN">
<html><body>
<p> Le 2015-01-12 07:01, Eli via Xymon a écrit :</p>
<blockquote type="cite" style="padding-left:5px; border-left:#1010ff 2px solid; margin-left:5px; width:100%">
<div>
<div>I want to create separate column for CPU utilization % is that possible take out from trend or other method.</div>
<div> </div>
<div>Thanks,</div>
</div>
<div>Eli<br /><br /></div>
</blockquote>
<div> </div>
<div>Hi,</div>
<div> </div>
<div>I use a personal script to do that:</div>
<div> </div>
<div>--- cut here ---</div>
<div>
<p>#!/usr/bin/perl</p>
<p># written by JC Simonetti<br /># version: 1.0, 2014-07-19</p>
<p>use warnings;<br />use strict;<br />use Hobbit;<br />use SNMP;</p>
<p>if (! -x '/usr/bin/vmstat') {<br /> exit 0;<br />}<br />if (! -x '/usr/bin/tail') {<br /> exit 0;<br />}</p>
<p>my $bb = new Hobbit('cpuUsage');</p>
<p>$bb->print("CPU Usage:\n\n");</p>
<p>#my @output = `/usr/bin/vmstat 1 2|/usr/bin/tail -1 2>&1` or die;<br />#foreach my $line (@output) {<br /># if ( $line =~ /\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+\s+/ ) {<br /># my $idle = defined($1)?$1:-1;<br /># my $color = "green";<br /># if ($idle < 30) {<br /># $color="yellow";<br /># }<br /># if ($idle < 10) {<br /># $color = "red";<br /># }<br /># my $used = 100-$idle . " %";<br /># $bb->color_line($color, $used);<br /># }<br />#}</p>
<p>my $session = new SNMP::Session(<br /> DestHost => "127.0.0.1",<br /> Community => "netcomm",<br /> Version => "2"<br />);</p>
<p>my $vb = new SNMP::Varbind(["UCD-SNMP-MIB::ssCpuIdle", 0]);<br />my $var = $session->get($vb);<br />my $output;<br />my $idle = -1;<br />if ($var =~ /NOSUCHINSTANCE/) {<br /> $var = -1;<br />}<br />if ($session->{ErrorNum}) {<br /> $output = $session->{ErrorStr};<br />} else {<br /> $idle = $var;<br /> $output = 100-$var . " %";<br />}</p>
<p>my $color = "green";<br />if ($idle < 30) {<br /> $color = "yellow";<br />}<br />if ($idle < 10) {<br /> $color = "red";<br />}<br />$bb->color_line($color, $output);</p>
<p>$bb->send;</p>
</div>
<div>
<div>--- cut here ---</div>
</div>
<div> </div>
<div>You'll see I use 2 methods to get back the CPU Usage: either by the system "vmstat" command (commented out in my script) or by SNMP (don't forget to adapt your "community").</div>
<div> </div>
<div>The script is called "/etc/hobbit/ext/cpuUsage", and there's also a config file "/etc/hobbit/clientlaunch.d/cpuUsage" that contains:</div>
<div>--- cut here ---</div>
<div>[cpuUsage]</div>
<div>#DISABLED</div>
<div>ENVFILE /etc/hobbit/hobbitclient.cfg</div>
<div>CMD /etc/hobbit/ext/cpuUsage</div>
<div>LOGFILE /var/log/hobbit/hobbitclient.log</div>
<div>INTERVAL 1m</div>
<div>--- cut here ---</div>
<div>
<p>This configuration will create a "cpuUsage" column with the percentage. The color values are for the moment hardcoded in the script: less than 30% free is yellow, less than 10% free is red. Adapt them if you want :)</p>
<p>My script is quite basic and all error use cases are not covered :)</p>
<p>Sincerely.</p>
<p>-- </p>
<p>Jean-Christian</p>
</div>
</body></html>