Projet

Général

Profil

Révision 31c6aa39

ID31c6aa39f9f3007f30ae90a9e72cb38af3d360dc
Parent 02af22a2
Enfant c1985259

Ajouté par Benjamin Pineau il y a presque 14 ans

Initial version

Voir les différences:

plugins/other/ipmi_sdr_
1
#!/usr/bin/perl -w
2
#
3
# IPMI data gathering for munin.
4
# 
5
# Author: 2008 Benjamin Pineau <ben.pineau@gmail.com>
6
# This work is hereby released into the Public Domain. 
7
# To view a copy of the public domain dedication, visit
8
# http://creativecommons.org/licenses/publicdomain/
9
#
10
# Requirements :
11
#
12
#   - ipmitool command line utility (and kernel drivers)
13
#   - access rights to /dev/ipmi0 device (ie, root privileges
14
#     can be configured in /etc/munin/plugin-conf.d/munin-node)
15
# 
16
# Parameters supported:
17
#
18
#   config
19
#   autoconf
20
#
21
# Setup :
22
#
23
#   ipmitool sdr || echo "please load IPMI kernel modules"
24
#   cp ipmi_sdr_ /usr/share/munin/plugins/
25
#   chmod +x /usr/share/munin/plugins/ipmi_sdr_
26
#   ln -s /usr/share/munin/plugins/ipmi_sdr_ /etc/munin/plugins/ipmi_sdr_fan
27
#   ln -s /usr/share/munin/plugins/ipmi_sdr_ /etc/munin/plugins/ipmi_sdr_current
28
#   ln -s /usr/share/munin/plugins/ipmi_sdr_ /etc/munin/plugins/ipmi_sdr_voltage
29
#   ln -s /usr/share/munin/plugins/ipmi_sdr_ /etc/munin/plugins/ipmi_sdr_temperature
30
#   echo -e "\n[ipmi_sdr*]\nuser root\ntimeout 15\n" >> /etc/munin/plugin-conf.d/munin-node
31
#   /etc/init.d/munin-node restart
32
#
33
# Magic markers
34
#%# family=auto
35
#%# capabilities=autoconf
36

  
37
use strict;
38
use warnings;
39

  
40
$ENV{'LANG'} = 'C';
41
$ENV{'LC_ALL'} = 'C';
42

  
43
my $ipmidump = $ENV{'ipmidump'} || '/var/lib/munin/plugin-state/ipmi_sdr';
44
my $ipmitool = $ENV{'ipmitool'} || 'ipmitool';
45
my $drefresh = $ENV{'drefresh'} || 86400;
46

  
47
my %sensors;
48

  
49
my $desc = {
50
    'fan'         => {
51
        'graph_title'  => 'Fans rotations per minute',
52
        'graph_vlabel' => 'RPM',
53
        'graph_info'   => 'Fans rotations per minute',
54
    },
55
    'voltage'     => {
56
        'graph_title'  => 'Electrical tensions',
57
        'graph_vlabel' => 'Volts',
58
        'graph_info'   => 'Electrical tensions',
59
    },
60
    'temperature' => {
61
        'graph_title'  => 'Hardware temperatures',
62
        'graph_vlabel' => 'Degrees Celsius',
63
        'graph_info'   => 'Hardware temperature sensors output',
64
    },
65
    'current'     => {
66
        'graph_title'  => 'Hardware power consumption',
67
        'graph_vlabel' => 'Watts or Amperes',
68
        'graph_info'   => 'Hardware power consumption',
69
    },
70
};
71

  
72
my $stype = $0 =~ /.*ipmi_sdr_(\w+)$/ ? lc($1) : 'temperature';
73

  
74
if (!defined($desc->{"$stype"})) {
75
    printf STDERR "Unknown sensor type : '$stype'. Aborting.\n";
76
    exit 1;
77
}
78

  
79
sub strip_spaces($) {
80
    (my $s = shift) =~ s/^\s*(.*?)\s*\n?$/$1/;
81
    return $s;
82
}
83

  
84
sub normalize_name($) {
85
    (my $l = lc(strip_spaces(shift))) =~ tr/\t ./_/;
86
    return $l;
87
}
88

  
89
sub sdrlist_parse(@) {
90
    foreach(@_) {
91
        next unless /^([^\|]+)\s*\|\s*(\w+)\s*\|[^\|]+\|[^\|]+\|\s*([\d\.]+)\s+/;
92
        $sensors{$_}{"name"}  = strip_spaces($1);
93
        $sensors{$_}{"value"} = strip_spaces($3);
94
        $sensors{$_}{"label"} = normalize_name($1) . normalize_name($2);
95
    }
96
}
97

  
98
if (defined $ARGV[0] and $ARGV[0] eq 'autoconf') {
99
    `$ipmitool help 2> /dev/null`;
100
    if ($?) {
101
        print "no ($ipmitool not found)";
102
        exit 1;
103
    }
104

  
105
    `$ipmitool sdr dump $ipmidump`;
106
    if ($?) {
107
        printf "no (ipmitool sdr dump returned code %d)\n", $? >> 8;
108
        exit 1;
109
    }
110

  
111
    `$ipmitool sdr type $stype -S $ipmidump`;
112
    if ($?) {
113
        print "no (ipmitool didn't found any sensor of type ";
114
        printf "'$stype', returned code %d)\n", $? >> 8;
115
        exit 1;
116
    }
117

  
118
    print "yes\n";
119
    exit 0;
120
}
121

  
122
# "ipmitool dump" dumps speeds up data retreival big time, by avoiding
123
# IPMI sensors autodiscovery. This only caches sensors names/types/ids 
124
# (not values/datas), so we can have a very long cache lifetime policy.
125
if (-f $ipmidump) {
126
    unlink($ipmidump) if (time - (stat($ipmidump))[9] >= $drefresh);
127
}
128
 
129
unless (-f $ipmidump) {
130
    `$ipmitool sdr dump $ipmidump` || die $!;
131
}
132
 
133
(my @dt = `$ipmitool sdr type $stype -S $ipmidump`) || die $!;
134
sdrlist_parse(@dt);
135

  
136
if (defined($ARGV[0]) && $ARGV[0] eq "config") {
137
    print "graph_category system\n";
138
    print "graph_title "  . $desc->{$stype}->{"graph_title"}  . "\n";
139
    print "graph_vlabel " . $desc->{$stype}->{"graph_vlabel"} . "\n";
140
    print "graph_info "   . $desc->{$stype}->{"graph_info"}   . "\n";
141

  
142
    foreach my $v (values(%sensors)) {
143
        print $v->{"label"} . ".label " . $v->{"name"} . "\n";
144
        print $v->{"label"} . ".type GAUGE\n";
145
    }
146

  
147
    exit 0;
148
}
149

  
150
foreach my $v (values(%sensors)) {
151
    print $v->{"label"} . ".value " . $v->{"value"} . "\n";
152
}
153

  

Formats disponibles : Unified diff