[mrtg] Re: problems with disk/cpu data collections

Daniel Curry dcurry at dollar.com
Thu Nov 18 21:00:32 MET 1999


Here is the full e-mail I get from running these in the mrtg.cfg:

Target[viper.disk.1]: `perl /home/dcurry/mrtg-2.8.9/run/getdisk.pl viper
1`
Title[viper.disk.1]: Viper's Root Partition % used
MaxBytes[viper.disk.1]: 100
PageTop[viper.disk.1]: <H1> Disk Space Usage for System: Viper </H1>
Suppress[viper.disk.1]: y
LegendI[viper.disk.1]: % used
LegendO[viper.disk.1]:
Legend1[viper.disk.1]: % used
Legend2[viper.disk.1]:
YLegend[viper.disk.1]: percent used
ShortLegend[viper.disk.1]: used
Options[viper.disk.1]: gauge

Target[158.146.12.75.2]: `/home/dcurry/mrtg-2.8.9/run/cpuinfo.pl`
MaxBytes[158.146.12.75.2]: 100
Options[158.146.12.75.2]: nopercent
Unscaled[158.146.12.75.2]: dwym
YLegend[158.146.12.75.2]: % of CPU used
ShortLegend[158.146.12.75.2]: %
LegendO[158.146.12.75.2]: &nbsp;CPU System:
LegendI[158.146.12.75.2]: &nbsp;CPU User:
Title[158.146.12.75.2]: Machine name
PageTop[158.146.12.75.2]: <H1>CPU usage for Machine name
 </H1>
 <TABLE>
   <TR><TD>System:</TD><TD>Machine name</TD></TR>
 </TABLE>

************************************************************************
***************

Permission denied.
Permission denied.
Problem with Externale get '`/home/dcurry/mrtg-2.8.9/run/cpuinfo.pl`':
   Expected an INTEGER for 'in' but got ''

Problem with Externale get '`/home/dcurry/mrtg-2.8.9/run/cpuinfo.pl`':
    Expected an INTEGER for 'out' but got 'viper'

Problem with Externale get '`perl /home/dcurry/mrtg-2.8.9/run/getdisk.pl
viper 1`':
    Expected an INTEGER for 'out' but got ''

************************************************************************
***************

I am not sure where it is getting its info for hte errors  Here is the
cpuinfo.pl script as modified for my use here:

#   -------------------------------------------------------------
#
#    Sample cfg:
#
#  Target[machine]: `./cpuinfo.pl`
#  MaxBytes[machine]: 100
#  Options[machine]: gauge, nopercent
#  Unscaled[machine]: dwym
#  YLegend[machine]: % of CPU used
#  ShortLegend[machine]: %
#  LegendO[machine]: &nbsp;CPU System:
#  LegendI[machine]: &nbsp;CPU User:
#  Title[machine]: Machine name
#  PageTop[machine]: <H1>CPU usage for Machine name
#   </H1>
#   <TABLE>
#     <TR><TD>System:</TD><TD>Machine name</TD></TR>
#    </TABLE>
#
#  --------------------------------------------------------------  
#
#         Ok, we are now done with the notes :)
#	
#========================================================
# setup local vars
my($machine, $os);

#=======================================================
# == Enter your default machine name and os here ==

$machine = "viper";	# Enter machine to monitor here
$os = "digital";		# Currently there is only linux and sun

# == You shouldn't need to edit anything below this line ==
#========================================================

# This allows command args to override defaults listed above
if (scalar(@ARGV) > 2) 
   {
   print("USAGE: cpuinfo.pl {machine} {os}\n");
   exit(-1);
   }     

if ($ARGV[0] ne '' && $ARGV[0] ne '#')
   {
   $machine = $ARGV[0];
   }

if ($ARGV[1] ne '' && $ARGV[1] ne '#')
   {
   $os = $ARGV[1];
   }

# Validate the os
SWITCH: 
{
  if ($os =~ /^sun$/){last SWITCH;}
  if ($os =~ /^linux$/){last SWITCH;}
  if ($os =~ /^digital$/){last SWITCH;}


  # DEFAULT: Die if we can't figure out what the os is 
  die "Can't figure out which OS the machine is.\n";
}

# Execute the appropriate subroutine based on the os
&$os;

exit(0);

#=======================================================
# Subroutines: names of subroutines are supported OSs.
#========================================================
sub sun
  {

   # Run commands
   $getcpu = `rsh $machine "sar -u 1 10" | grep Average`;
   $getuptime = `rsh $machine "uptime"`;
   
   # Parse though getcpu and get data
   $getcpu =~ /^Average\s+(\d+)\s+(\d+)\s+/;
   $outputusr = $1;
   $outputsys = $2;

   # Print getcpu data for mrtg
   print $outputusr."\n";
   print $outputsys."\n";

   # Parse though getuptime and get data
   $getuptime =~ /^\s+(\d{1,2}:\d{2}..)\s+up\s+(\d+)\s+(......),/;

   # Print getuptime data for mrtg
   print $2." ".$3."\n"; 

   # Print machine name for mrtg
   print $machine."\n";

  }

sub linux
  {
   # Run commands
   $getcpu = `rsh $machine "/usr/local/bin/sar -u 1 10 | grep Average"`;
   $getuptime = `rsh $machine "/usr/bin/uptime"`;
   
   # Parse though getcpu and get data 
   $getcpu =~
/^Average:\s+(\d+).(\d+)%\s+(\d+).(\d+)%\s+(\d+).(\d+)%\s+(\d+).(\d+)%/;
   $getcpuusr = $1;
   $getcpusys = $5;

   # Print getcpu data for mrtg
   print $getcpuusr."\n";
   print $getcpusys."\n";

   # Parse though getuptime and get data
   $getuptime =~ /^\s+(\d{1,2}:\d{2}..)\s+up\s+(\d+)\s+(\w+),/;

   # Print getuptime data for mrtg
   print $2." ".$3."\n";
   
   # Print machine name for mrtg
   print $machine."\n";

  }


sub digital
  {
   # Run commands
   $getcpu = `rsh $machine "sar -u 1 10 | grep Average"`;
   $getuptime = `rsh $machine "uptime"`;

   # Parse though getcpu and get data
   @gotcpu = split(/      /, $getcpu);
   $getcpuusr = @gotcpu[1];
   $getcpusys = @gotcpu[4];

   # Print getcpu data for mrtg
   print $getcpuusr."\n";
   print $getcpusys;

   # Parse though getuptime and get data
   $getuptime =~ /^\s+(\d{1,2}:\d{2}..)\s+up\s+(\d+)\s+(\w+),/;
   @gotuptime = split(/  /, $getuptime);

   # Print getuptime data for mrtg
   print @gotuptime[1]." ". at gotuptime[3];

   # Print machine name for mrtg
   print $machine."\n";

  }





-----Original Message-----
From: Daniel R. Kilbourne [mailto:drk at voyager.net]
Sent: Thursday, November 18, 1999 1:42 PM
To: Daniel Curry; 'Stieers, Ken'; 'mrtg'
Subject: [mrtg] Re: problems with disk/cpu data collections


use the absolute path to getdisk.pl


ie: /usr/sbin/getdisk.pl

************************************************************************
******************

And here is the getdisk.pl script:

#!/usr/bin/perl
# This script is used to establish a TCP connection with a host to get
the 
# disk info provided by showdisk.pl.
#
# use: ./getdisk.pl <hostname> <disk number>
#
# By Steven Micallef <smic at wire.net.au> on the 24/4/1999.

use Net::Telnet ();


$hostname = $ARGV[0];
$disk_no = $ARGV[1];

# If you've changed the port showdisk.pl runs on, change it here too.
$port = 9047;

$i = 0;

if ($hostname eq "" || $disk_no eq "" )
{
  print "Usage: $0 <hostname> <disk number>\n";
  exit;
}


$t = new Net::Telnet ( Host => $hostname, Port => $port);
$t->open("$hostname");

do
{
  $data = $t->getline(Timeout => 40);
  $i++;
  if ($i eq $disk_no)
  {
    print $data;
  }
} while ($i != $disk_no);

************************************************************************
****


I know this is a LONG msg, but I want to give as much info to help as
possible.

Sorry about the bandwidth.

Thanks

Daniel

--
* To unsubscribe from the mrtg mailing list, send a message with the
  subject: unsubscribe to mrtg-request at list.ee.ethz.ch
* The mailing list archive is at http://www.ee.ethz.ch/~slist/mrtg


More information about the mrtg mailing list