Projet

Général

Profil

Paste
Télécharger au format
Statistiques
| Branche: | Révision:

root / plugins / omreport / omreport_pwrmon_current @ e08a6448

Historique | Voir | Annoter | Télécharger (2,97 ko)

1 b65ecef1 Andrew Chadwick
#!/usr/bin/perl
2
#
3
# Copyright (C) 2009 Andrew Chadwick, University of Oxford <andrew.chadwick@ceu.ox.ac.uk>
4
# Based on work by Rackspace US, Inc. <http://www.rackspace.com>, (C) 2008.
5
# 
6
# This program is free software; you can redistribute it and/or
7
# modify it under the terms of the GNU General Public License
8
# as published by the Free Software Foundation; version 2 dated June,
9
# 1991.
10
#
11
# This program is distributed in the hope that it will be useful,
12
# but WITHOUT ANY WARRANTY; without even the implied warranty of
13
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
# GNU General Public License for more details.
15
#
16
# You should have received a copy of the GNU General Public License
17
# along with this program; if not, see http://www.gnu.org/licenses/gpl.txt
18
#
19
#
20
# This plugin will graph the per-PSU current draw of a Dell PowerEdge Server
21
# via the omreport tool. It has been tested on the following chassis:
22
#
23
#   PowerEdge R905
24
#
25
# To enable, create a link in your plugins directory to wherever you
26
# installed this file, e.g.:
27
#
28
#   cd /etc/munin/plugins
29
#   ln -s /usr/share/munin/plugins/omreport_pwrmon_current
30
#
31
# Configuration parameters for /etc/munin/plugin-conf.d/munin-node
32
#
33
# [omreport_*]
34
#   user         - User that has permissions to run the omreport binary
35
#   env.omreport - Path to the omreport binary
36
#
37
# Parameters:
38
#
39
#   config
40
#   autoconf
41
#
42
# Author: Andrew Chadwick <andrew.chadwick@ceu.ox.ac.uk>
43
# Revision: 0.1  2008-01-28
44
#
45
#%# family=auto
46
#%# capabilities=autoconf
47
48
49
use strict;
50
my $omreport = $ENV{"omreport"} || "/usr/bin/omreport";
51
52
if ($ARGV[0] && $ARGV[0] eq "autoconf") {
53
    if (-f $omreport) {
54
        print "yes\n";
55
    }
56
    else {
57
        print "no ($omreport does not exist)\n";
58
        exit(1);
59
    }
60
}
61
else {
62
    my @cmd = ($omreport, qw{chassis pwrmonitoring});
63
    my ($index, %val);
64
    my $pid = open(my $cmd_out, '-|', @cmd) or die "@cmd: $!\n";
65
    defined $pid or die "fork() failed: $!\n";
66
    my $amperage_idx = 0;
67
    while (<$cmd_out>) {
68
        s/\s+/\040/g;
69
        s/\s+$//;
70
        s/^\s+//;
71
72
        /^Amperage\b/ .. /^Power\s+Tracking\b/ or next;
73
74
        my ($field, $value) = split(/\s+\:\s+/, $_);
75
        if ($field eq 'Location') {
76
            $index = "current_${amperage_idx}";
77
            ++$amperage_idx;
78
            $val{$index} = {
79
                label => $value,
80
            };
81
        }
82
        elsif ($field eq 'Reading') {
83
            $value =~ s{\s+A$}{};
84
            $value =~ s{\[N/A\]}{}g;
85
            $val{$index}{value} = $value;
86
        }
87
    }
88
    close $cmd_out;
89
90
    if ($ARGV[0] && $ARGV[0] eq "config") {
91
        print "graph_title OpenManage - Power Monitoring - Current\n";
92
        print "graph_args --base 1000 -l 0\n";
93
        print "graph_vlabel Amps\n";
94
        print "graph_category Sensors\n";
95
        foreach my $j (sort keys %val) {
96
            print "$j.label $val{$j}{label}\n";
97
        }
98
    }
99
    else {
100
        foreach my $j (sort keys %val) {
101
            print "$j.value $val{$j}{value}\n";
102
        }
103
    }
104
}
105
exit(0);