~ubuntu-branches/ubuntu/oneiric/munin/oneiric-updates

« back to all changes in this revision

Viewing changes to node/node.d/hddtemp_smartctl.in

  • Committer: Bazaar Package Importer
  • Author(s): Chuck Short
  • Date: 2008-06-25 13:59:20 UTC
  • mfrom: (1.1.4 upstream)
  • Revision ID: james.westby@ubuntu.com-20080625135920-5to31uma3m4rf44n
Tags: 1.2.6-1ubuntu1
* Merge from debian unstable, remaining changes:
  + debian/munin-node.postinst:
    - Restart munin-node to load new plugins. (LP: #224428)
  + debian/control:
    - Suggest cron (LP: #220561)
    - Updated maintainer according to spec.
  + debian/changelog:
    - Corrected launch bug number.
  + Added debian/patches/220-honor-pid-file.patch:
    - Honor the pid file, thanks to Remi Broemeling. (LP: #107335)

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
#!@@PERL@@ -w
 
2
# -*- perl -*-
2
3
#
3
4
# Plugin to monitor harddrive temperatures through SMART.
4
5
#
5
6
# client-conf.d/-options:
6
 
#       
 
7
#
7
8
#       smartctl        -- path to smartctl executable
8
9
#       drives          -- List drives to monitor. E.g. "env.drives hda hdc".
9
10
#       type_$dev       -- device type for one drive, e.g. "env.type_sda 3ware,0"
12
13
#                          Use this to make the plugin use the --all or -a option
13
14
#                          if your disk will not return it's temperature when
14
15
#                          only the -A option is used.
15
 
#
16
 
# Note for users of RAID controllers (smartmontools currently only
17
 
# supports 3ware): you can specify the drives attached to your RAID
18
 
# controller(s) as raiddev_num (e.g. sda_0). Then you must specify the
19
 
# type like this: type_sda_0 3ware,0.
20
 
#
21
 
# $Log$
22
 
# Revision 1.1.2.5  2005/03/03 10:22:25  lupe
23
 
# Add feature to specify additional arguments to smartctl
24
 
#
25
 
# Revision 1.1.2.4  2005/02/17 10:59:33  lupe
26
 
# Support more than one drive on RAID controllers. Explain how to configure
27
 
# them.
28
 
#
29
 
# Revision 1.1.2.3  2005/01/29 22:14:36  jimmyo
30
 
# Make the plugin check all rdsks.
31
 
#
32
 
# Revision 1.1.2.2  2005/01/26 09:34:37  jimmyo
33
 
# Added license note.
34
 
#
35
 
# Revision 1.1.2.1  2005/01/25 21:00:05  jimmyo
36
 
# Added plugin generic/hddtemp_smartctl, made by Lupe Christoph. Made it the default hddtemp plugin.
37
 
#
38
 
# Revision 1.1  2004/11/10 16:11:27  jimmyo
39
 
# Added new plugin linux/hddtemp_smartctl, made by Peter Gervai (SF#1032727).
40
 
#
41
 
# Revision 1.0  2004/09/22 
42
 
# New plugin: Peter Gervai <grin(*)grin.hu>
43
 
#
 
16
#       dev_$dev        -- monitoring device for one drive, e.g. twe0
 
17
#
 
18
# Note for users of RAID controllers: you can specify the drives attached to
 
19
# your RAID controller(s) as raiddev_num (e.g. sda_0). Then you must specify
 
20
# the type like this: type_sda_0 3ware,0.
 
21
#
 
22
# For a cciss RAID controller use e.g.:
 
23
#   env.drives cciss6
 
24
#   env.type_cciss6 cciss,6
 
25
#   env.dev_cciss6 cciss/c0d0
 
26
#
 
27
# Recent versions of the kernel driver use a separate major device number
 
28
# for monitoring purposes, like /dev/twe<n> or /dev/twa<n>. This can be
 
29
# put in the e.g. dev_sda environment variable, to allow the user to keep
 
30
# sda as the name of the disk.
 
31
#
 
32
# To avoid spinning up sleeping disks, you need the hdparm command in your PATH
44
33
#
45
34
#%# family=auto
46
35
#%# capabilities=autoconf
76
65
# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
77
66
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
78
67
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
79
 
 
 
68
#
 
69
# $Id: hddtemp_smartctl.in 1629 2008-06-05 07:56:13Z matthias $
80
70
 
81
71
use strict;
82
72
 
102
92
 
103
93
# Try to get a default set of drives
104
94
if ($^O eq 'linux') {
105
 
  # On Linux, we know how to enumerate ide drives.
106
 
  # SCSI is not as easy
 
95
  # On Linux, we know how to enumerate ide drives. SCSI is not as easy
107
96
  if (-d '/proc/ide') {
108
97
    opendir(IDE, '/proc/ide');
109
98
    @drives = grep /hd[a-z]/, readdir IDE;
110
99
    closedir(IDE);
111
100
  }
 
101
  # "SCSI disks" could be both SCSI or SATA - we can't know which
 
102
  # without probing them.
 
103
} elsif ($^O eq 'freebsd') {
 
104
  opendir(DEV, '/dev');
 
105
  @drives = grep /^ad[0-9]+$/, readdir DEV;
 
106
  closedir(DEV);
112
107
} elsif ($^O eq 'solaris') {
113
108
  @drives = map { s@.*/@@ ; $_ } glob '/dev/rdsk/c*t*d*s2';
114
109
}
146
141
foreach (@drives) {
147
142
  my $dev;
148
143
  $dev = $_ =~ /(.*)(?:_\d+)/ ? $1 : $_;
 
144
 
 
145
  my $fulldev = '/dev/';
 
146
  $fulldev .= 'rdsk/' if $^O eq 'solaris';
 
147
  $fulldev .= exists $ENV{'dev_'.$_} ? $ENV{'dev_'.$_} : $dev;
 
148
 
 
149
  # Avoid spinning up sleeping disks
 
150
  next if `hdparm -C $fulldev 2>/dev/null` =~ /standby/;
 
151
 
149
152
  my $cmd = $smartctl.' -A ';
150
153
  $cmd .= $ENV{'args_'.$_}.' ' if exists $ENV{'args_'.$_};
151
154
  $cmd .= '-d '.$ENV{'type_'.$_}.' ' if exists $ENV{'type_'.$_};
152
 
  if ($^O eq 'solaris') {
153
 
    $cmd .= "/dev/rdsk/$dev";
154
 
  } else {
155
 
    $cmd .= "/dev/$dev";
156
 
  }
 
155
  $cmd .= $fulldev;
 
156
 
157
157
  my $output = `$cmd`;
158
158
  if ($output =~ /Current Drive Temperature:\s*(\d+)/) {
159
159
    print "$_.value $1\n";
160
160
  } elsif ($output =~ /^(194 Temperature_Celsius.*)/m) {
161
161
    my @F = split ' ', $1;
162
162
    print "$_.value $F[9]\n";
 
163
  } elsif ($output =~ /^(231 Temperature_Celsius.*)/m) {
 
164
    my @F = split ' ', $1;
 
165
    print "$_.value $F[9]\n";
163
166
  }
164
167
}