Révision 2ef171cb
obsolete
| plugins/other/apcupsd | ||
|---|---|---|
| 1 |
#!/usr/bin/env perl
|
|
| 1 |
This plugin is obsolete. Instead, please use apcupsd_pct plugin:
|
|
| 2 | 2 |
|
| 3 |
use strict; |
|
| 4 |
use warnings; |
|
| 5 |
use Carp; |
|
| 6 |
use Pod::Usage; |
|
| 3 |
apcupsd_pct plugin |
|
| 4 |
http://exchange.munin-monitoring.org/plugins/apcupsd_pct/details |
|
| 7 | 5 |
|
| 8 |
our $APCACCESS = $ENV{apcaccess} || "/sbin/apcaccess";
|
|
| 9 |
our $UPS_MODEL = $ENV{ups_model} || "ES 725";
|
|
| 10 |
our $VERSION = 1.0; |
|
| 11 |
my %Graph; |
|
| 12 |
my %Metric; |
|
| 13 |
|
|
| 14 |
MAIN: {
|
|
| 15 |
decide_monitor_type(); |
|
| 16 |
|
|
| 17 |
my $mode = $ARGV[0] || "fetch"; |
|
| 18 |
$mode =~ /^-/ && pod2usage(); |
|
| 19 |
|
|
| 20 |
### $mode |
|
| 21 |
eval "do_${mode}();"
|
|
| 22 |
or croak "do_${mode}: $@";
|
|
| 23 |
|
|
| 24 |
### end |
|
| 25 |
exit 0; |
|
| 26 |
} |
|
| 27 |
|
|
| 28 |
=begin comment |
|
| 29 |
|
|
| 30 |
pct |
|
| 31 |
LOADPCT is the percentage of load capacity as estimated by the UPS. |
|
| 32 |
15.0 Percent Load Capacity |
|
| 33 |
BCHARGE is the percentage charge on the batteries. |
|
| 34 |
100.0 Percent |
|
| 35 |
|
|
| 36 |
volt |
|
| 37 |
LINEV is the current line voltage as returned by the UPS. |
|
| 38 |
102.0 Volts |
|
| 39 |
BATTV is the battery voltage as supplied by the UPS. |
|
| 40 |
13.5 Volts |
|
| 41 |
|
|
| 42 |
time |
|
| 43 |
TIMELEFT is the remaining runtime left on batteries as estimated by the UPS. |
|
| 44 |
38.4 Minutes |
|
| 45 |
|
|
| 46 |
=end comment |
|
| 47 |
|
|
| 48 |
=cut |
|
| 49 |
|
|
| 50 |
sub decide_monitor_type {
|
|
| 51 |
my $type = $0 =~ /_pct/ ? "pct" : |
|
| 52 |
$0 =~ /_volt/ ? "volt" : |
|
| 53 |
$0 =~ /_time/ ? "time" : undef |
|
| 54 |
or croak "unknown monitor type: $0"; |
|
| 55 |
|
|
| 56 |
# common |
|
| 57 |
%Graph = ( |
|
| 58 |
graph_title => "APC Status".($UPS_MODEL?" ($UPS_MODEL)":"")." - ", |
|
| 59 |
graph_category => "ups", |
|
| 60 |
graph_info => "This graph shows information about your APC UPS", |
|
| 61 |
graph_args => "--base 1000 --lower-limit 0", |
|
| 62 |
); |
|
| 63 |
|
|
| 64 |
if ($type eq "pct") {
|
|
| 65 |
$Graph{graph_title} .= "Percentage";
|
|
| 66 |
$Graph{graph_vlabel} = "%";
|
|
| 67 |
%Metric =( |
|
| 68 |
LOADPCT => {
|
|
| 69 |
label => "load capacity pct", |
|
| 70 |
}, |
|
| 71 |
BCHARGE => {
|
|
| 72 |
label => "charge on the batteries pct", |
|
| 73 |
}, |
|
| 74 |
); |
|
| 75 |
} elsif ($type eq "volt") {
|
|
| 76 |
$Graph{graph_title} .= "Voltage";
|
|
| 77 |
$Graph{graph_vlabel} = "Volts";
|
|
| 78 |
%Metric =( |
|
| 79 |
LINEV => {
|
|
| 80 |
label => "line voltage as returned by the UPS", |
|
| 81 |
}, |
|
| 82 |
BATTV => {
|
|
| 83 |
label => "battery voltage as supplied by the UPS", |
|
| 84 |
}, |
|
| 85 |
); |
|
| 86 |
} elsif ($type eq "time") {
|
|
| 87 |
$Graph{graph_title} .= "Time";
|
|
| 88 |
$Graph{graph_vlabel} = "minutes";
|
|
| 89 |
%Metric =( |
|
| 90 |
TIMELEFT => {
|
|
| 91 |
label => "remaining runtime left on batteries", |
|
| 92 |
}, |
|
| 93 |
); |
|
| 94 |
} |
|
| 95 |
} |
|
| 96 |
|
|
| 97 |
sub do_fetch {
|
|
| 98 |
### do_fetch |
|
| 99 |
|
|
| 100 |
my @status_data = retrieve_apcupsd_status() |
|
| 101 |
or croak "failed: retrieve_apcupsd_status"; |
|
| 102 |
### status_data: \@status_data |
|
| 103 |
|
|
| 104 |
my $status = parse_status_data(@status_data); |
|
| 105 |
### status: $status |
|
| 106 |
|
|
| 107 |
my $FIELD; |
|
| 108 |
while (my($field,$attr) = each %Metric) {
|
|
| 109 |
$field = lc $field; |
|
| 110 |
$FIELD = uc $field; |
|
| 111 |
printf "%s.value %.1f\n", $field, (exists $status->{$FIELD} ? ($status->{$FIELD} =~ /([\d]+\.?[\d]*)/) : 0);
|
|
| 112 |
} |
|
| 113 |
|
|
| 114 |
return 1; |
|
| 115 |
} |
|
| 116 |
|
|
| 117 |
sub do_config {
|
|
| 118 |
### do_config |
|
| 119 |
|
|
| 120 |
while (my($k,$v) = each %Graph) {
|
|
| 121 |
printf "%s %s\n", $k, $v; |
|
| 122 |
} |
|
| 123 |
while (my($field,$attr) = each %Metric) {
|
|
| 124 |
$field = lc $field; |
|
| 125 |
while (my($k,$v) = each %$attr) {
|
|
| 126 |
printf "%s.%s %s\n", $field, $k, $v; |
|
| 127 |
} |
|
| 128 |
} |
|
| 129 |
|
|
| 130 |
return 1; |
|
| 131 |
} |
|
| 132 |
|
|
| 133 |
sub do_autoconf {
|
|
| 134 |
### do_config |
|
| 135 |
print "yes\n"; |
|
| 136 |
} |
|
| 137 |
|
|
| 138 |
sub retrieve_apcupsd_status {
|
|
| 139 |
open my $apc, '-|', $APCACCESS |
|
| 140 |
or croak $!; |
|
| 141 |
my @status_data = <$apc>; |
|
| 142 |
close $apc; |
|
| 143 |
chomp @status_data; |
|
| 144 |
return @status_data; |
|
| 145 |
} |
|
| 146 |
|
|
| 147 |
sub parse_status_data {
|
|
| 148 |
my $status = {};
|
|
| 149 |
my($k,$v); |
|
| 150 |
for (@_) {
|
|
| 151 |
($k,$v) = split /\s*:\s*/, $_, 2; |
|
| 152 |
$status->{$k} = $v;
|
|
| 153 |
} |
|
| 154 |
return $status; |
|
| 155 |
} |
|
| 156 |
|
|
| 157 |
|
|
| 158 |
__END__ |
|
| 159 |
|
|
| 160 |
=head1 NAME |
|
| 161 |
|
|
| 162 |
B<apcupsd_pct>, B<apcupsd_volt>, B<apcupsd_time> - munin plugin for APC UPS |
|
| 163 |
|
|
| 164 |
=head1 SYNOPSIS |
|
| 165 |
|
|
| 166 |
B<apcupsd_pct> [ I<config>|I<fetch> ] |
|
| 167 |
|
|
| 168 |
B<apcupsd_volt> [ I<config>|I<fetch> ] |
|
| 169 |
|
|
| 170 |
B<apcupsd_time> [ I<config>|I<fetch> ] |
|
| 171 |
|
|
| 172 |
|
|
| 173 |
=head1 DESCRIPTION |
|
| 174 |
|
|
| 175 |
munin plugin to monitor APC UPS via apcupsd by apcaccess. |
|
| 176 |
|
|
| 177 |
=head1 INSTALLATION |
|
| 178 |
|
|
| 179 |
cp apcupsd_pct $MUNIN_LIBDIR/plugsin/ |
|
| 180 |
|
|
| 181 |
cd YOUR_MUNIN_PLUGINS_DIR |
|
| 182 |
(make symbolic links different name) |
|
| 183 |
ln -s $MUNIN_LIBDIR/plugsin/apcupsd_pct apcupsd_pct |
|
| 184 |
ln -s $MUNIN_LIBDIR/plugsin/apcupsd_pct apcupsd_volt |
|
| 185 |
ln -s $MUNIN_LIBDIR/plugsin/apcupsd_pct apcupsd_time |
|
| 186 |
|
|
| 187 |
restart munin-node |
|
| 188 |
|
|
| 189 |
=head1 REPOSITORY |
|
| 190 |
|
|
| 191 |
L<http://github.com/hirose31/munin-apcupsd-fixme/tree/master> |
|
| 192 |
|
|
| 193 |
git clone git://github.com/hirose31/fixme.git |
|
| 194 |
|
|
| 195 |
patches and collaborators are welcome. |
|
| 196 |
|
|
| 197 |
=head1 SEE ALSO |
|
| 198 |
|
|
| 199 |
L<http://munin.projects.linpro.no/wiki/HowToWritePlugins>, |
|
| 200 |
L<http://munin.projects.linpro.no/wiki/protocol-config> |
|
| 201 |
|
|
| 202 |
=head1 AUTHOR |
|
| 203 |
|
|
| 204 |
HIROSE, Masaaki E<lt>hirose31 _at_ gmail.comE<gt> |
|
| 205 |
|
|
| 206 |
=head1 COPYRIGHT & LICENSE |
|
| 207 |
|
|
| 208 |
This program is free software; you can redistribute it and/or modify it |
|
| 209 |
under the same terms as Perl itself. |
|
| 210 |
|
|
| 211 |
=cut |
|
| 212 |
|
|
| 213 |
# for Emacsen |
|
| 214 |
# Local Variables: |
|
| 215 |
# mode: cperl |
|
| 216 |
# cperl-indent-level: 4 |
|
| 217 |
# indent-tabs-mode: nil |
|
| 218 |
# coding: utf-8 |
|
| 219 |
# End: |
|
| 220 |
|
|
| 221 |
# vi: set ts=4 sw=4 sts=0 : |
|
| 6 |
thanks. |
|
Formats disponibles : Unified diff