Monitoring a SmartUPS3000

Templates, scripts for templates, scripts and requests for templates.

Moderators: Developers, Moderators

Post Reply
Morpheus
Posts: 3
Joined: Tue May 18, 2004 7:02 am
Location: Amsterdam / NL

Monitoring a SmartUPS3000

Post by Morpheus »

Here is a script which I hacked together from the weatherbug script.
So that I could monitor my SmartUPS which is connected to my Linux Box and monitored by apcupsd.

If your apcaccess program gives out other value-pair you can easely change the script ...

Code: Select all

#!/usr/bin/perl

# Modified Weatherbug Perl Script to monitor a UPS connected to 'apcupsd'

@upsoutput=`/sbin/apcaccess`;

foreach(@upsoutput) {
  chomp();
  split();
    if ( $_[0] eq 'BCHARGE' ) {
        $bcharge = $_[2];
    }

    if ( $_[0] eq 'LINEV' ) {
        $linev = $_[2];
    }

    if ( $_[0] eq 'LOADPCT' ) {
        $loadpct = $_[2];
    }

    if ( $_[0] eq 'TIMELEFT' ) {
        $timeleft = $_[2];
    }
  
    if ( $_[0] eq 'NOMBATTV' ) {
        $nombattv = $_[2];
    }

    if ( $_[0] eq 'MAXLINEV' ) {
        $maxlinev = $_[2];
    }

    if ( $_[0] eq 'MINLINEV' ) {
        $minlinev = $_[2];
    }

    if ( $_[0] eq 'OUTPUTV' ) {
        $outputv = $_[2];
    }

    if ( $_[0] eq 'ITEMP' ) {
        $itemp = $_[2];
    }

    if ( $_[0] eq 'BATTV' ) {
        $battv = $_[2];
    }

    if ( $_[0] eq 'LINEFREQ' ) {
        $linefreq = $_[2];
    }

    if ( $_[0] eq 'NOMOUTV' ) {
        $nomoutv = $_[2];
    }



}
print " batt_charge:"   . $bcharge . 
      " timeleft:"      . $timeleft .
      " nom_battv:"     . $nombattv .
      " line_volt:"     . $linev .
      " load_pct:"      . $loadpct .
      " max_linev:"     . $maxlinev .
      " min_linev:"     . $minlinev .
      " outputv:"       . $outputv .
      " int_temp:"      . $itemp .
      " battv:"         . $battv .
      " linefreq:"      . $linefreq .
      " nom_outputv:"   . $nomoutv .
      "\n";

Just dropt this script in your cacti-scripts dir and create the 'data input method' and the 'Data Source' and ofcourse your graph :-) ....
Attachments
UPS Image of the Line Voltage
UPS Image of the Line Voltage
ups.png (5.66 KiB) Viewed 6864 times
Temperature of the UPS
Temperature of the UPS
ups-temp.png (4.76 KiB) Viewed 6863 times
--
[ To Err is human, to really foul up things requires a computer ]
OllyM
Posts: 1
Joined: Fri Dec 09, 2005 2:26 pm

Post by OllyM »

Has anybody had any luck getting this to work?

I just can't seem to get cacti to draw any graphs using this... don't suppose somebody could do a quick runthrough of how to actually set this up?
krumbold
Posts: 1
Joined: Mon Jan 02, 2006 1:20 pm

Post by krumbold »

OllyM wrote:Has anybody had any luck getting this to work?

I just can't seem to get cacti to draw any graphs using this... don't suppose somebody could do a quick runthrough of how to actually set this up?
I didn't get any output either. But I think the above script will not deliver any values at all. So the graphs won't be generated (no values -> no graph) ;-)

I have tried to run the script on my shell but no output at all... So I decided to write it from scratch (reading the input from STDIN)

I have not integrated it into cacti yet but it already delivers output values of my BACK UPS 800 RS. If you don't get any output you perhabs have to adjust the regex statements a little bit (according the output of your apcaccess program).

Invoke it (as root) like this:

apcaccess | /usr/local/bin/cacti-apcupsd.pl

This should print the current apcupsd values to stdout:

Code: Select all

/usr/local/bin # apcaccess | ./cacti-apcupsd.pl
load_pct: 18.0
b_charge: 100.0
time_left: 42.2
out_volt: 230.0
int_temp: 29.2
bat_volt: 27.4
line_freq: 50.0
tot_on_bat: 0
cum_on_bat: 0
nom_batv: 24.0
In the moment I don't know how and I don't know when I'll integrate it into my cacti configuration. So I can't help you with this. Good luck!

Cheers Krum


Code: Select all

#!/usr/bin/perl

#script that parses output of apcaccess for cacti internal processing:

while(<STDIN>) {
        chomp;
        if (s/^TIMELEFT[ ]*[:][ ]*(\d+\.*\d+).*/\1/) {
                print "time_left: $_\n";
        }
        if (s/^NOMBATTV[ ]*[:][ ]*(\d+\.*\d+).*/\1/) {
                print "nom_batv: $_\n";
        }
        if (s/^LOADPCT[ ]*[:][ ]*(\d+\.*\d+).*/\1/) {
                print "load_pct: $_\n";
        }
        if (s/^ITEMP[ ]*[:][ ]*(\d+\.*\d+).*/\1/) {
                print "int_temp: $_\n";
        }
        if (s/^BATTV[ ]*[:][ ]*(\d+\.*\d+).*/\1/) {
                print "bat_volt: $_\n";
        }
        if (s/^BCHARGE[ ]*[:][ ]*(\d+\.*\d+).*/\1/) {
                print "b_charge: $_\n";
        }
        if (s/^OUTPUTV[ ]*[:][ ]*(\d+\.*\d+).*/\1/) {
                print "out_volt: $_\n";
        }
        if (s/^LINEFREQ[ ]*[:][ ]*(\d+\.*\d+).*/\1/) {
                print "line_freq: $_\n";
        }
        if (s/^TONBATT[ ]*[:][ ]*(\d+).*/\1/) {
                print "tot_on_bat: $_\n";
        }
        if (s/^CUMONBATT[ ]*[:][ ]*(\d+).*/\1/) {
                print "cum_on_bat: $_\n";
        }

}
Post Reply

Who is online

Users browsing this forum: No registered users and 2 guests