source: munin/plugins/node.d/apc_nis.in

devel
Last change on this file was 1c1624e, checked in by Kenyon Ralph <kenyon@…>, 6 weeks ago

plugins/node.d/apc_nis: improve maximum limits

Battery charge is a percentage, so can't be over 100. There's no
reason to limit load, time left, or temperature; doing so just creates
graphs with missing values when you have actual values over these
arbitrary limits.

  • Property mode set to 100644
File size: 3.1 KB
Line 
1#!@@PERL@@ -w
2# -*- perl -*-
3
4=head1 NAME
5
6apc_nis - Plugin to monitor APC UPS via the nis port of apcupsd
7
8=head1 CONFIGURATION
9
10The following configuration parameters are used by this plugin
11
12 [apc_nis]
13  env.host     - hostname to connect to
14  env.port     - port number to connect to
15
16=head2 DEFAULT CONFIGURATION
17
18 [apc_nis]
19  env.host 127.0.0.1
20  env.port 3551
21
22=head1 MAGIC MARKERS
23
24 #%# family=contrib
25 #%# capabilities=autoconf
26
27=cut
28
29use IO::Socket;
30use strict;
31
32if($ARGV[0] and $ARGV[0] eq "autoconf") {
33    print "yes\n";
34    exit 0;
35}
36
37my $host = exists $ENV{'host'} ? $ENV{'host'} : "127.0.0.1";
38my $port = exists $ENV{'port'} ? $ENV{'port'} : "3551";
39
40my $sock = new IO::Socket::INET (
41    PeerAddr => $host,
42    PeerPort => $port,
43    Proto => 'tcp'
44    );
45
46die "Could not create socket: $!\n" unless $sock;
47
48my $buf = pack("CC", 0, 6);
49print $sock $buf;
50print $sock "status\n";
51
52if($ARGV[0] and $ARGV[0] eq "config") {
53    # Test for some capabilities.
54    my $has_temperature = 0, my $line_volt_min, my $line_volt_max;
55    my $line;
56    do {
57        $line = <$sock>;
58        chomp($line);
59        if ($line =~ /\WITEMP /) {
60            $has_temperature = 1;
61        } elsif ($line =~ /\WLOTRANS /) {
62            $line =~ s/.* (\d+.\d+).*/$1/;
63            $line_volt_min = $line;
64        } elsif ($line =~ /\WHITRANS /) {
65            $line =~ s/.* (\d+.\d+).*/$1/;
66            $line_volt_max = $line;
67        }
68    } while(!($line =~ /END APC/));
69
70    close($sock);
71
72    print "graph_title APC UPS measurements\n";
73    print "graph_args -l 0 --base 1000\n";
74    print "graph_vlabel A bit of all (Volt, time, %)\n";
75    print "graph_info Values received for apcupsd available at $host:$port\n";
76    print "battery_volt.label batt volt (V)\n";
77    print "battery_volt.type GAUGE\n";
78    print "battery_volt.max 300\n";
79    print "battery_charge.label batt charge (%)\n";
80    print "battery_charge.type GAUGE\n";
81    print "battery_charge.max 100\n";
82    print "line_volt.label line (V)\n";
83    print "line_volt.type GAUGE\n";
84    print "line_volt.max 300\n";
85    print "line_volt.warning ${line_volt_min}:${line_volt_max}\n";
86    print "load.label ups load (%)\n";
87    print "load.type GAUGE\n";
88    print "time_left.label time left (min)\n";
89    print "time_left.type GAUGE\n";
90    if ($has_temperature) {
91        print "temperature.label internal temperature (°C)\n";
92        print "temperature.type GAUGE\n";
93    }
94    exit 0;
95}
96
97my $line;
98do {
99    $line = <$sock>;
100    chomp($line);
101    if($line =~ /\WBATTV /) {
102        $line =~ s/.* (\d+.\d+).*/$1/;
103        print "battery_volt.value $line\n";
104    } elsif($line =~ /\WLINEV /) {
105        $line =~ s/.* (\d+.\d+).*/$1/;
106        print "line_volt.value $line\n";
107    } elsif($line =~ /\WLOADPCT /) {
108        $line =~ s/.* (\d+.\d+).*/$1/;
109        print "load.value $line\n";
110    } elsif($line =~ /\WBCHARGE /) {
111        $line =~ s/.* (\d+.\d+).*/$1/;
112        print "battery_charge.value $line\n";
113    } elsif($line =~ /\WTIMELEFT /) {
114        $line =~ s/.* (\d+.\d+).*/$1/;
115        print "time_left.value $line\n";
116    } elsif($line =~ /\WITEMP /) {
117        $line =~ s/.* (\d+.\d+).*/$1/;
118        print "temperature.value $line\n";
119    }
120} while(!($line =~ /END APC/));
121
122close($sock);
Note: See TracBrowser for help on using the repository browser.