1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180
|
#!@@PERL@@ -w
# -*- perl -*-
# Wildcard plugin to monitor sensors.
#
# Requirements:
# - i2c and lm_sensors modules installed and loaded
# - sensors program installed and in path
#
# Note:
# - Sensor names are read from the output of the sensors program.
# Change them in /etc/sensors.conf if you don't like them.
#
# Parameters supported:
#
# config
# autoconf
# suggest
#
# Configurable variables
#
# sensors - Override default program
# ignore_temp<n> - Temperature <n> will not be plotted
# ignore_fan<n> - Fan <n> will not be plotted
# ignore_volt<n> - Voltage <n> will not be plotted
# fan_warn_percent - Percentage over mininum for warning
# volt_warn_percent - Percentage over mininum/under maximum for warning
# Narrow the voltage bracket by this.
#
# $Log$
# Revision 1.10 2004/12/15 15:40:12 jimmyo
# Fixed typo in graph_category.
#
# Revision 1.9 2004/11/23 17:08:25 ilmari
# Fixed linux/sensors_ plugin to report warning and critical values for temperatures and voltages if sensors reports them.
#
# Revision 1.3.2.3 2004/08/18 17:27:15 jimmyo
# Made linux/sensors_volt work with negative voltages (Deb#256734).
#
# Revision 1.3.2.2 2004/08/18 17:20:29 jimmyo
# linux/sensors_temp now understand temp lines without hyst or max settings (Deb#256380).
#
# Revision 1.3.2.1 2004/08/18 17:01:01 jimmyo
# Force LANG/LC_ALL=C in linux/sensors_ and generic/hddtemp2, to remove problems in parsing of sensors output (SF#972749, SF#972748, Deb#255312)
#
# Revision 1.3 2004/04/28 21:46:41 jimmyo
# Sensors-* patch from SF#906868.
#
# Revision 1.2 2004/04/27 21:55:43 jimmyo
# Patched temp-part of linux-pugin sensors_* with better regexp (Deb#245289).
#
# Revision 1.1 2004/02/05 16:47:02 jimmyo
# Added new wildcard plugin linux/sensors_ that replaces the i2c plugins (SF#890952).
#
#
#
# Magic markers:
#%# family=manual
#%# capabilities=autoconf suggest
use strict;
$ENV{'LANG'} = "C"; # Force parseable output from sensors.
$ENV{'LC_ALL'} = "C"; # Force parseable output from sensors.
my $SENSORS = $ENV{'sensors'} || 'sensors';
my %config = (
fan => {
regex => qr/^(\S[^:]*)\s*:\s+\+?(\d+) RPM.*?(\d+) RPM/m,
title => 'Fans',
vtitle => 'RPM',
print_threshold => \&fan_threshold,
graph_args => '--base 1000 -l 0'
},
temp => {
regex => qr/^(\S[^:]*)\s*:\s+\+?(\d+(?:\.\d+)?)[ ]C(?:\s+\((?:high|limit)\s*=\s*\+?(\d+(?:\.\d+)?)[ ]C,\s*hyst(?:eresis)?\s*=\s*\+?(\d+(?:\.\d+)?)[ ]C\))?/m,
title => 'Temperatures',
vtitle => 'Celsius',
print_threshold => \&temp_threshold,
graph_args => '--base 1000 -l 0'
},
volt => {
regex => qr/^(\S[^:]*)\s*:\s+\+?(-?\d+(?:\.\d+)?) V(?:\s+\(min\s*=\s*\+?(-?\d+(?:\.\d+)?) V,\s*max\s*=\s*\+?(-?\d+(?:\.\d+)?) V\))/m,
title => 'Voltages',
vtitle => 'Volt',
print_threshold => \&volt_threshold,
graph_args => '--base 1000 --logarithmic'
},
);
if ( exists $ARGV[0] and $ARGV[0] eq 'autoconf' ) {
# Now see if "sensors" can run
my $text = `$SENSORS`;
if ($?) {
if ($? == -1) {
print "no (program $SENSORS not found)\n";
} else {
print "no (program $SENSORS died)\n";
}
exit 1;
}
unless ($text =~ /[ ]C/) {
print "no (no temperature readings)\n";
exit 1;
}
print "yes\n";
exit 0;
}
if ($ARGV[0] and $ARGV[0] eq 'suggest') {
my $text = `$SENSORS`;
foreach my $func (keys %config) {
print $func, "\n" if $text =~ $config{$func}->{regex};
}
exit;
}
$0 =~ /sensors_(.+)*$/;
my $func = $1;
exit 2 unless defined $func;
if ( exists $ARGV[0] and $ARGV[0] eq 'config' ) {
print "graph_title $config{$func}->{title}\n";
print "graph_vtitle $config{$func}->{vtitle}\n";
print "graph_args $config{$func}->{graph_args}\n";
print "graph_category sensors\n";
my $text = `$SENSORS`;
my $sensor = 1;
while ($text =~ /$config{$func}->{regex}/g) {
my ($label, undef, $max, $min) = ($1, $2, $3, $4);
print "$func$sensor.label $label\n";
$config{$func}->{print_threshold}->($func.$sensor, $3, $4);
print "$func$sensor.graph no\n" if exists $ENV{"ignore_$func$sensor"};
$sensor++;
}
exit 0;
}
my $text = `$SENSORS`;
my $sensor = 1;
while ($text =~ /$config{$func}->{regex}/g) {
print "$func$sensor.value $2\n";
$sensor++;
}
sub fan_threshold {
my $name = shift;
my $min = shift;
my $warn_percent = exists $ENV{fan_warn_percent} ? $ENV{fan_warn_percent} : 5;
return unless defined $min;
printf "$name.warning %d:\n", $min * (100 + $warn_percent) / 100;
printf "$name.critical %d:\n", $min;
}
sub temp_threshold {
my $name = shift;
my $max = shift;
my $min = shift;
printf "$name.warning $min\n" if $min;
printf "$name.critical $max\n" if $max;
}
sub volt_threshold {
my $name = shift;
my $min = shift;
my $max = shift;
my $warn_percent = exists $ENV{volt_warn_percent} ? $ENV{volt_warn_percent} : 20;
return unless defined ($min && $max);
my $diff = $max - $min;
my $dist = $diff * $warn_percent / 100;
printf "$name.warning %.2f:%.2f\n", $min + $dist, $max - $dist;
printf "$name.critical $min:$max\n";
}
# vim:syntax=perl
|