| 1 |
#!/usr/bin/perl -w |
|---|
| 2 |
# -*- perl -*- |
|---|
| 3 |
# Wildcard plugin to monitor sensors. |
|---|
| 4 |
# |
|---|
| 5 |
# Requirements: |
|---|
| 6 |
# - mbmon program installed and in path |
|---|
| 7 |
# |
|---|
| 8 |
# Parameters supported: |
|---|
| 9 |
# |
|---|
| 10 |
# config |
|---|
| 11 |
# autoconf |
|---|
| 12 |
# suggest |
|---|
| 13 |
# |
|---|
| 14 |
# Configurable variables |
|---|
| 15 |
# |
|---|
| 16 |
# mbmon - Override default program |
|---|
| 17 |
# ignore_temp<n> - Temperature <n> will not be plotted |
|---|
| 18 |
# ignore_fan<n> - Fan <n> will not be plotted |
|---|
| 19 |
# ignore_volt<n> - Voltage <n> will not be plotted |
|---|
| 20 |
# |
|---|
| 21 |
# $Log$ |
|---|
| 22 |
# Revision 1.1 2006/03/02 09:30:00 fra519 |
|---|
| 23 |
# Modify script sensors_ for use mbmon program |
|---|
| 24 |
# |
|---|
| 25 |
# |
|---|
| 26 |
# |
|---|
| 27 |
# Magic markers: |
|---|
| 28 |
#%# family=manual |
|---|
| 29 |
#%# capabilities=autoconf suggest |
|---|
| 30 |
|
|---|
| 31 |
use strict; |
|---|
| 32 |
|
|---|
| 33 |
my $SENSORS = $ENV{'mbmon'} || 'mbmon -c1 -r'; |
|---|
| 34 |
my %config = ( |
|---|
| 35 |
fan => { |
|---|
| 36 |
regex => qr/^(F\S[^ ]*)\s*:\s+\+?(-?\d+(?:\.\d+)?)/m, |
|---|
| 37 |
title => 'Fans', |
|---|
| 38 |
vtitle => 'RPM', |
|---|
| 39 |
graph_args => '--base 1000 -l 0' |
|---|
| 40 |
}, |
|---|
| 41 |
temp => { |
|---|
| 42 |
regex => qr/^(T\S[^ ]*)\s*:\s+\+?(-?\d+(?:\.\d+)?)/m, |
|---|
| 43 |
title => 'Temperatures', |
|---|
| 44 |
vtitle => 'Celsius', |
|---|
| 45 |
graph_args => '--base 1000 -l 0' |
|---|
| 46 |
}, |
|---|
| 47 |
volt => { |
|---|
| 48 |
regex => qr/^(V\S[^ ]*)\s*:\s+\+?(-?\d+(?:\.\d+)?)/m, |
|---|
| 49 |
title => 'Voltages', |
|---|
| 50 |
vtitle => 'Volt', |
|---|
| 51 |
graph_args => '--base 1000 --logarithmic' |
|---|
| 52 |
}, |
|---|
| 53 |
); |
|---|
| 54 |
|
|---|
| 55 |
if ( exists $ARGV[0] and $ARGV[0] eq 'autoconf' ) { |
|---|
| 56 |
# Now see if "sensors" can run |
|---|
| 57 |
my $text = `$SENSORS`; |
|---|
| 58 |
if ($?) { |
|---|
| 59 |
if ($? == -1) { |
|---|
| 60 |
print "no (program $SENSORS not found)\n"; |
|---|
| 61 |
} else { |
|---|
| 62 |
print "no (program $SENSORS died)\n"; |
|---|
| 63 |
} |
|---|
| 64 |
exit 1; |
|---|
| 65 |
} |
|---|
| 66 |
|
|---|
| 67 |
unless ($text =~ /[:word:No]/) { |
|---|
| 68 |
print "no (no readings)\n"; |
|---|
| 69 |
exit 1; |
|---|
| 70 |
} |
|---|
| 71 |
|
|---|
| 72 |
print "yes\n"; |
|---|
| 73 |
exit 0; |
|---|
| 74 |
} |
|---|
| 75 |
|
|---|
| 76 |
if ($ARGV[0] and $ARGV[0] eq 'suggest') { |
|---|
| 77 |
my $text = `$SENSORS`; |
|---|
| 78 |
foreach my $func (keys %config) { |
|---|
| 79 |
print $func, "\n" if $text =~ $config{$func}->{regex}; |
|---|
| 80 |
} |
|---|
| 81 |
exit; |
|---|
| 82 |
} |
|---|
| 83 |
|
|---|
| 84 |
$0 =~ /mbmon_(.+)*$/; |
|---|
| 85 |
my $func = $1; |
|---|
| 86 |
exit 2 unless defined $func; |
|---|
| 87 |
|
|---|
| 88 |
if ( exists $ARGV[0] and $ARGV[0] eq 'config' ) { |
|---|
| 89 |
print "graph_title $config{$func}->{title}\n"; |
|---|
| 90 |
print "graph_vtitle $config{$func}->{vtitle}\n"; |
|---|
| 91 |
print "graph_args $config{$func}->{graph_args}\n"; |
|---|
| 92 |
print "graph_category sensors\n"; |
|---|
| 93 |
my $text = `$SENSORS`; |
|---|
| 94 |
my $sensor = 1; |
|---|
| 95 |
while ($text =~ /$config{$func}->{regex}/g) { |
|---|
| 96 |
my $label = "$1"; |
|---|
| 97 |
print "$func$sensor.label $label\n"; |
|---|
| 98 |
print "$func$sensor.graph no\n" if exists $ENV{"ignore_$func$sensor"}; |
|---|
| 99 |
$sensor++; |
|---|
| 100 |
} |
|---|
| 101 |
exit 0; |
|---|
| 102 |
} |
|---|
| 103 |
|
|---|
| 104 |
my $text = `$SENSORS`; |
|---|
| 105 |
my $sensor = 1; |
|---|
| 106 |
while ($text =~ /$config{$func}->{regex}/g) { |
|---|
| 107 |
print "$func$sensor.value $2\n"; |
|---|
| 108 |
$sensor++; |
|---|
| 109 |
} |
|---|
| 110 |
|
|---|
| 111 |
# vim:syntax=perl |
|---|