[Xymon] CPU utilization column
    Christian 
    xymon at elysiria.fr
       
    Mon Jan 12 07:57:40 CET 2015
    
    
  
 
 Le 2015-01-12 07:01, Eli via Xymon a écrit : 
> I want to create
separate column for CPU utilization % is that possible take out from
trend or other method. 
> 
> Thanks, 
> Eli
Hi, 
I use a personal
script to do that: 
--- cut here --- 
#!/usr/bin/perl 
# written by
JC Simonetti
# version: 1.0, 2014-07-19 
use warnings;
use strict;
use
Hobbit;
use SNMP; 
if (! -x '/usr/bin/vmstat') {
 exit 0;
}
if (! -x
'/usr/bin/tail') {
 exit 0;
} 
my $bb = new Hobbit('cpuUsage');
$bb->print("CPU Usage:nn"); 
#my @output = `/usr/bin/vmstat 1
2|/usr/bin/tail -1 2>&1` or die;
#foreach my $line (@output) {
# 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+/ )
{
# my $idle = defined($1)?$1:-1;
# my $color = "green";
# if ($idle <
30) {
# $color="yellow";
# }
# if ($idle < 10) {
# $color = "red";
# }
#
my $used = 100-$idle . " %";
# $bb->color_line($color, $used);
# }
#}
my $session = new SNMP::Session(
 DestHost => "127.0.0.1",
 Community
=> "netcomm",
 Version => "2"
); 
my $vb = new
SNMP::Varbind(["UCD-SNMP-MIB::ssCpuIdle", 0]);
my $var =
$session->get($vb);
my $output;
my $idle = -1;
if ($var =~
/NOSUCHINSTANCE/) {
 $var = -1;
}
if ($session->{ErrorNum}) {
 $output =
$session->{ErrorStr};
} else {
 $idle = $var;
 $output = 100-$var . "
%";
} 
my $color = "green";
if ($idle < 30) {
 $color = "yellow";
}
if
($idle < 10) {
 $color = "red";
}
$bb->color_line($color, $output);
$bb->send; 
--- cut here --- 
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"). 
The
script is called "/etc/hobbit/ext/cpuUsage", and there's also a config
file "/etc/hobbit/clientlaunch.d/cpuUsage" that contains: 
--- cut here
--- 
[cpuUsage] 
#DISABLED 
ENVFILE /etc/hobbit/hobbitclient.cfg 
CMD
/etc/hobbit/ext/cpuUsage 
LOGFILE /var/log/hobbit/hobbitclient.log
INTERVAL 1m 
--- cut here --- 
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 :) 
My script is quite basic
and all error use cases are not covered :) 
Sincerely. 
--
Jean-Christian 
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.xymon.com/pipermail/xymon/attachments/20150112/ccf79a0c/attachment.html>
    
    
More information about the Xymon
mailing list