Custom script not working with spine

Post support questions that directly relate to Linux/Unix operating systems.

Moderators: Developers, Moderators

Post Reply
abstractsrl
Posts: 2
Joined: Fri Feb 11, 2011 11:38 am

Custom script not working with spine

Post by abstractsrl »

Hi, I have written a custom script to collect cpu usage (from the shell command ps) for multiple processes, passing the pid-files of the processes.

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 $_." ";
}
The script is working fine in the shell:

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 ...
It works also with cmd.php:

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
but it doesn't work with spine:

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
Here are some system informations:
OS: Debian 4.0
Cacti: 0.8.7g
Cacti-spine: 0.8.7g
User avatar
Linegod
Developer
Posts: 1626
Joined: Thu Feb 20, 2003 10:16 am
Location: Canada
Contact:

Re: Custom script not working with spine

Post by Linegod »

Ensure you are using the full path to perl

http://docs.cacti.net/manual:087:4_help.2_debugging
--
Live fast, die young
You're sucking up my bandwidth.

J.P. Pasnak,CD
CCNA, LPIC-1
http://www.warpedsystems.sk.ca
abstractsrl
Posts: 2
Joined: Fri Feb 11, 2011 11:38 am

Re: Custom script not working with spine [Solved]

Post by abstractsrl »

Ok, at the end I figured out the problem, spine require a single print statement, therefore I changed the following code ad it works:

Code: Select all

foreach (@output) {
    print $_." ";
}
changed with:

Code: Select all

print join(" ",@output);
User avatar
Linegod
Developer
Posts: 1626
Joined: Thu Feb 20, 2003 10:16 am
Location: Canada
Contact:

Re: Custom script not working with spine

Post by Linegod »

Glad to hear it is working for you.

As a note, single line output is covered in the documentation. Perhaps we need to make it more obvious?
--
Live fast, die young
You're sucking up my bandwidth.

J.P. Pasnak,CD
CCNA, LPIC-1
http://www.warpedsystems.sk.ca
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest