process_cpu-usage_multi.pl
Code: Select all
#!/usr/bin/perl
open(PROCESS, 'ps h -eo pid,pcpu | tr "\n" " " |');
$ps=<PROCESS>;
close(PROCESS);
$ps =~ s/\s+/ /g;
@elem = split(/ /, $ps);
@output = ();
$n = 1;
foreach (@ARGV) {
open(FILE, $_) || die("$!: $_");
$argv = <FILE>;
$i = 0;
foreach (@elem) {
if ( $_ eq $argv ) {
push(@output, "cpu$n:$elem[$i+1]");
$n++;
}
$i++;
}
}
foreach (@output) {
print $_." ";
}
Code: Select all
# perl process_cpu-usage_multi.pl <absolute pid-file path process1> <absolute pid-file path process2> ...
returns for example:
cpu1:0.1 cpu2:0.0 ...
Code: Select all
# php -q cmd.php
02/13/2011 01:29:34 PM - CMDPHP: Poller[0] Host[1] DS[18] CMD: perl /var/www/cacti/scripts/process_cpu-usage_multi.pl /home/zope/instances/zope1/var/instance.pid /home/zope/instances/zope2/var/instance.pid /home/zope/instances/zope3/var/instance.pid /home/zope/instances/zope4/var/instance.pid /home/zope/instances/zope5/var/instance.pid, output: cpu1:0.1 cpu2:0.0 cpu3:0.0 cpu4:0.3 cpu5:4.0
Code: Select all
# spine -R -S --verbosity=5 -H 1
Host[1] DEBUG: The NIFTY POPEN returned the following File Descriptor 6
Host[1] TH[1] DS[18] SCRIPT: perl /var/www/cacti/scripts/process_cpu-usage_multi.pl /home/zope/instances/zope1/var/instance.pid /home/zope/instances/zope2/var/instance.pid /home/zope/instances/zope3/var/instance.pid /home/zope/instances/zope4/var/instance.pid /home/zope/instances/zope5/var/instance.pid, output: 0
OS: Debian 4.0
Cacti: 0.8.7g
Cacti-spine: 0.8.7g