[ Index ]

PHP Cross Reference of Unnamed Project

title

Body

[close]

/se3master/usr/local/sysmon/ -> process.pl (source)

   1  #!/usr/bin/perl
   2  use POSIX;
   3  
   4  #========================================================
   5  # Memory an cpu usage for process script for mrtg
   6  #
   7  #    File:     process.pl
   8  #    Author:     Chretien Jean-Luc
   9  #               jeanluc.chretien@tice.ac-caen.fr
  10  #
  11  #    Version:    1.0
  12  #
  13  #    Date:    11/08/02
  14  #    Purpose:   This script reports process Memory usage
  15  #               for Men & Cpu to mrtg.
  16  #
  17  #    Usage:    /path/process.pl
  18  #
  19  #
  20  #    Info:    Designed on Debian Woody
  21  #--------------------------------------------------------
  22  
  23  $path = "/usr/bin/";
  24  $top = "top -b -n 1 | grep ";
  25  
  26  
  27  sub Validate() {    #validate command line args
  28    if ((scalar(@ARGV) > 1) || ($ARGV[0] eq '')) {
  29       print "ERR: Must specify  one process to be monitored.\n";
  30       Usage;
  31       exit;
  32    }
  33  }
  34  
  35  #####  Main Program Begins Here  ######
  36  Validate();
  37  # assign command line args to variables
  38  $process =  $ARGV[0];
  39  
  40  # Grab the top data locally
  41  $gettop = `$path$top $process`;
  42  
  43  ### DEBUG ###
  44  # print $gettop."\n";
  45  ### DEBUG ###
  46  
  47  # parse top data
  48  @lines=split /^/m, $gettop;
  49  
  50  foreach $line (@lines)  {
  51    @fields=split(/\s+/,$line);
  52    $getcpu = $getcpu+$fields[10];
  53    $getmem = $getmem+$fields[11];
  54  }
  55  
  56  #Print getcpu & getmem data for mrtg
  57  print ceil($getcpu)."\n";
  58  print ceil($getmem)."\n";
  59  
  60  exit (0);


Generated: Tue Mar 17 22:47:18 2015 Cross-referenced by PHPXref 0.7.1