Projet

Général

Profil

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

root / plugins / sensors / hwmon @ ef960abc

Historique | Voir | Annoter | Télécharger (4,74 ko)

1 fd5126e0 Diego Elio Pettenò
#!/usr/bin/perl -w
2
# -*- cperl -*-
3
=head1 NAME
4
5
  hwmon - Multigraph-plugin to monitor Linux hwmon drivers
6
7
=head1 CONFIGURATION
8
9
There is no environment configuration for this plugin on the node
10
side. If you need to ignore some values, do so from the master
11
directly.
12
13
The data is being received directly by the kernel-configured
14
parameters. Some of these parameters are initialized by lm_sensors
15
depending on your driver and distribution, so while the plugin does
16
not require you to have the package installed, it's still suggested.
17
18
=head1 AUTHOR
19
20
Diego Elio Pettenò <flameeyes@flameeyes.eu>.
21
22
=head1 LICENSE
23
24
GPLv2
25
26
=head1 MAGIC MARKERS
27
28
 #%# family=manual
29
 #%# capabilities=autoconf
30
31
=cut
32
33
use strict;
34
use Munin::Plugin;
35
use File::Basename;
36
37
sub readpath {
38
  my $path = shift;
39
  open READ, $path or return '';
40
  chomp(my $read = readline(READ));
41
  close READ;
42
43
  return $read;
44
}
45
46
# we'll opent he hwmon class, then find all the devices registered
47
# there.
48
my $classdir = '/sys/class/hwmon';
49
my @devdirs = <$classdir/hwmon*>;
50
51
if ( defined $ARGV[0] and $ARGV[0] eq 'autoconf' ) {
52 157c0675 Diego Elio Pettenò
  if ( scalar(@devdirs) > 0 ) {
53 fd5126e0 Diego Elio Pettenò
    print "yes\n";
54
  } else {
55
    print "no (no hwmon device found)\n";
56
  }
57
58
  exit 0;
59
}
60
61
my %sensors = (
62
	     in => {
63
		    inputs => [],
64
		    title => "Voltages",
65
		    vlabel => "Volt",
66
		    graph_args => "--base 1000 --logarithmic",
67
		    denominator => 1000 # milliVolt -> Volt
68
		   },
69
	     fan => {
70
		     inputs => [],
71
		     title => "Fans speed",
72
		     vlabel => "RPM",
73
		     graph_args => "--base 1000 -l 0",
74
		     denominator => 1
75
		    },
76
	     temp => {
77
		      inputs => [],
78
		      title => "Temperatures",
79
		      vlabel => "Degrees Celsius",
80
		      graph_args => "--base 1000 -l 0",
81
		      denominator => 1000 # milliCelsius -> Celsius
82
		     },
83
	     curr => {
84
		      inputs => [],
85
		      title => "Currents",
86
		      vlabel => "A",
87
		      graph_args => "--base 1000 -l 0",
88
		      denominator => 1000 # milliAmperes -> Amperes
89
		     },
90
	     power => {
91
		       inputs => [],
92
		       title => "Power",
93
		       vlabel => "W",
94
		       graph_args => "--base 1000 -l 0",
95
		       denominator => 1000000 # microWatts -> Watts
96
		      },
97
	     humidity => {
98
			  inputs => [],
99
			  title => "Humidity",
100
			  vlabel => "%",
101
			  graph_args => "--base 1000 -l 0 -u 100",
102
			  denominator => 1
103
			 }
104
	    );
105
106
foreach my $devdir (@devdirs) {
107
  my $devname = basename($devdir);
108
109
  # we have to find where the actual data is. Unfortunately some
110
  # drivers use /sys/class/hwmon/hwmon* directly while most use
111
  # /sys/class/hwmon/hwmon*/device.
112
  if (-e "$devdir/device/name") {
113
    $devdir = "$devdir/device";
114
  } elsif (! -e "$devdir/name") {
115
    next;
116
  }
117
118
  my $devlabel = readpath "$devdir/name";
119
120
  foreach my $input (<$devdir/*_input>) {
121
    basename($input) =~ /^(([a-z]+)[0-9]+)_input$/;
122
    my $name = $1;
123
    my $type = $2;
124
    my $graphid = clean_fieldname("$devname $name");
125
    my $path = "$devdir/$name";
126
    my $label = "$devlabel $name";
127
128
    push(@{$sensors{$type}->{inputs}}, { path => $path, label => $label, graphid => $graphid });
129
  }
130
}
131
132
if ( defined $ARGV[0] and $ARGV[0] eq 'config' ) {
133
  foreach my $type (keys %sensors) {
134
    # don't print anything if no value is found
135
    next if scalar(@{$sensors{$type}->{inputs}}) == 0;
136
137
    print <<END;
138
139
multigraph hwmon_$type
140
graph_title $sensors{$type}->{title}
141
graph_vlabel $sensors{$type}->{vlabel}
142
graph_args $sensors{$type}->{graph_args}
143
graph_category sensors
144
END
145
146
    foreach my $sensor (@{$sensors{$type}->{inputs}}) {
147
      my $label = readpath("$sensor->{path}_label");
148
      $label = $sensor->{label} if $label eq '';
149
150
      print "$sensor->{graphid}.label $label\n";
151
152
      my $lwarn = readpath("$sensor->{path}_min");
153
      $lwarn = $lwarn/$sensors{$type}->{denominator}
154
	unless $lwarn eq '';
155
156
      my $hwarn = readpath("$sensor->{path}_max");
157
      $hwarn = $hwarn/$sensors{$type}->{denominator}
158
	unless $hwarn eq '';
159
160
      print "$sensor->{graphid}.warning $lwarn:$hwarn\n"
161
	unless $lwarn eq '' and $hwarn eq '';
162
163
      my $lcrit = readpath("$sensor->{path}_lcrit");
164
      $lcrit = $lcrit/$sensors{$type}->{denominator}
165
	unless $lcrit eq '';
166
167
      my $hcrit = readpath("$sensor->{path}_crit");
168
      $hcrit = $hcrit/$sensors{$type}->{denominator}
169
	unless $hcrit eq '';
170
171
      print "$sensor->{graphid}.critical $lcrit:$hcrit\n"
172
	unless $lcrit eq '' and $hcrit eq '';
173
    }
174
  }
175
176 5b22647d Diego Elio Pettenò
  unless ( ($ENV{MUNIN_CAP_DIRTYCONFIG} || 0) == 1 ) {
177 060ddd51 Diego Elio Pettenò
    exit 0;
178
  }
179 fd5126e0 Diego Elio Pettenò
}
180
181
foreach my $type (keys %sensors) {
182
  # don't print anything if no value is found
183
  next if scalar(@{$sensors{$type}->{inputs}}) == 0;
184
185
  print "multigraph hwmon_$type\n";
186
187
  foreach my $sensor (@{$sensors{$type}->{inputs}}) {
188
    my $val = readpath("$sensor->{path}_input") / $sensors{$type}->{denominator};
189
    print "$sensor->{graphid}.value $val\n";
190
  }
191
}
192
193
# vim:syntax=perl