3
4
# Plugin to monitor harddrive temperatures through SMART.
5
6
# client-conf.d/-options:
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.
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.
22
# Revision 1.1.2.5 2005/03/03 10:22:25 lupe
23
# Add feature to specify additional arguments to smartctl
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
29
# Revision 1.1.2.3 2005/01/29 22:14:36 jimmyo
30
# Make the plugin check all rdsks.
32
# Revision 1.1.2.2 2005/01/26 09:34:37 jimmyo
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.
38
# Revision 1.1 2004/11/10 16:11:27 jimmyo
39
# Added new plugin linux/hddtemp_smartctl, made by Peter Gervai (SF#1032727).
41
# Revision 1.0 2004/09/22
42
# New plugin: Peter Gervai <grin(*)grin.hu>
16
# dev_$dev -- monitoring device for one drive, e.g. twe0
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.
22
# For a cciss RAID controller use e.g.:
24
# env.type_cciss6 cciss,6
25
# env.dev_cciss6 cciss/c0d0
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.
32
# To avoid spinning up sleeping disks, you need the hdparm command in your PATH
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.
69
# $Id: hddtemp_smartctl.in 1629 2008-06-05 07:56:13Z matthias $
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;
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;
112
107
} elsif ($^O eq 'solaris') {
113
108
@drives = map { s@.*/@@ ; $_ } glob '/dev/rdsk/c*t*d*s2';
146
141
foreach (@drives) {
148
143
$dev = $_ =~ /(.*)(?:_\d+)/ ? $1 : $_;
145
my $fulldev = '/dev/';
146
$fulldev .= 'rdsk/' if $^O eq 'solaris';
147
$fulldev .= exists $ENV{'dev_'.$_} ? $ENV{'dev_'.$_} : $dev;
149
# Avoid spinning up sleeping disks
150
next if `hdparm -C $fulldev 2>/dev/null` =~ /standby/;
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";
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";