root / plugins / other / hddtemp_smartctl @ e908d2d2
Historique | Voir | Annoter | Télécharger (5,33 ko)
| 1 | 5bb0fbb6 | Previous, G. Stewart | #!/usr/bin/perl -w |
|---|---|---|---|
| 2 | # |
||
| 3 | # Plugin to monitor harddrive temperatures through SMART. |
||
| 4 | # |
||
| 5 | # client-conf.d/-options: |
||
| 6 | # |
||
| 7 | # smartctl -- path to smartctl executable |
||
| 8 | # drives -- List drives to monitor. E.g. "env.drives hda hdc". |
||
| 9 | # type_$dev -- device type for one drive, e.g. "env.type_sda 3ware,0" |
||
| 10 | # args_$dev -- additional arguments to smartctl for one drive, |
||
| 11 | # e.g. "env.args_hda -v 194,10xCelsius" |
||
| 12 | # Use this to make the plugin use the --all or -a option |
||
| 13 | # if your disk will not return it's temperature when |
||
| 14 | # 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 | # |
||
| 44 | # |
||
| 45 | #%# family=auto |
||
| 46 | #%# capabilities=autoconf |
||
| 47 | # |
||
| 48 | # Copyright (c) 2005, Lutz Peter Christoph |
||
| 49 | # All rights reserved. |
||
| 50 | # |
||
| 51 | # Redistribution and use in source and binary forms, with or without |
||
| 52 | # modification, are permitted provided that the following conditions |
||
| 53 | # are met: |
||
| 54 | # |
||
| 55 | # * Redistributions of source code must retain the above copyright |
||
| 56 | # notice, this list of conditions and the following disclaimer. |
||
| 57 | # |
||
| 58 | # * Redistributions in binary form must reproduce the above copyright |
||
| 59 | # notice, this list of conditions and the following disclaimer in |
||
| 60 | # the documentation and/or other materials provided with the |
||
| 61 | # distribution. |
||
| 62 | # |
||
| 63 | # * The name and aliases of Lutz Peter Christoph ("Lupe Christoph",
|
||
| 64 | # "Lutz Christoph") may not be used to endorse or promote products |
||
| 65 | # derived from this software without specific prior written |
||
| 66 | # permission. |
||
| 67 | # |
||
| 68 | # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
||
| 69 | # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
||
| 70 | # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
||
| 71 | # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
||
| 72 | # OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
||
| 73 | # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
||
| 74 | # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
||
| 75 | # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
||
| 76 | # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
||
| 77 | # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
||
| 78 | # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
||
| 79 | |||
| 80 | |||
| 81 | use strict; |
||
| 82 | |||
| 83 | my $smartctl = exists $ENV{smartctl} ? $ENV{smartctl} : undef;
|
||
| 84 | |||
| 85 | # If the envvar is not set, look for smartctl |
||
| 86 | # first, try $PATH |
||
| 87 | $smartctl = `which smartctl` unless $smartctl; |
||
| 88 | chomp $smartctl; |
||
| 89 | $smartctl = undef unless -x $smartctl; |
||
| 90 | |||
| 91 | # Still not found? Check obvious places |
||
| 92 | my @dirs = qw(/usr/bin /usr/sbin /usr/local/bin /usr/local/sbin); |
||
| 93 | until ($smartctl or @dirs == 0) {
|
||
| 94 | my $dir = shift @dirs; |
||
| 95 | my $path = $dir.'/smartctl'; |
||
| 96 | $smartctl = $path if -x $path; |
||
| 97 | } |
||
| 98 | |||
| 99 | $ENV{LANG} = 'C';
|
||
| 100 | $ENV{LC_ALL} = 'C';
|
||
| 101 | my @drives; |
||
| 102 | |||
| 103 | # Try to get a default set of drives |
||
| 104 | if ($^O eq 'linux') {
|
||
| 105 | # On Linux, we know how to enumerate ide drives. |
||
| 106 | # SCSI is not as easy |
||
| 107 | if (-d '/dev') {
|
||
| 108 | opendir(IDE, '/dev'); |
||
| 109 | @drives = grep /sd[a-z]$/, readdir IDE; |
||
| 110 | closedir(IDE); |
||
| 111 | } |
||
| 112 | } elsif ($^O eq 'solaris') {
|
||
| 113 | @drives = map { s@.*/@@ ; $_ } glob '/dev/rdsk/c*t*d*s2';
|
||
| 114 | } |
||
| 115 | |||
| 116 | @drives = split ' ', $ENV{drives} if exists $ENV{drives};
|
||
| 117 | |||
| 118 | # Sort list of drives |
||
| 119 | @drives = sort @drives; |
||
| 120 | |||
| 121 | if (defined $ARGV[0]) {
|
||
| 122 | if ($ARGV[0] eq 'autoconf') {
|
||
| 123 | if ($smartctl and -x $smartctl) {
|
||
| 124 | if (@drives) {
|
||
| 125 | print "yes\n"; |
||
| 126 | exit 0; |
||
| 127 | } else {
|
||
| 128 | print "no (no drives known)\n"; |
||
| 129 | exit 1; |
||
| 130 | } |
||
| 131 | } else {
|
||
| 132 | print "no (smartctl not found)\n"; |
||
| 133 | exit 1; |
||
| 134 | } |
||
| 135 | } elsif ($ARGV[0] eq 'config') {
|
||
| 136 | print "graph_title HDD temperature\n"; |
||
| 137 | print "graph_args --base 1000 -l 0\n"; |
||
| 138 | print "graph_vlabel temp in �C\n"; |
||
| 139 | print "graph_category sensors\n"; |
||
| 140 | print "graph_info This graph shows the temperature in degrees Celsius of the hard drives in the machine.\n"; |
||
| 141 | print "$_.label $_\n" foreach @drives; |
||
| 142 | exit 0; |
||
| 143 | } |
||
| 144 | } |
||
| 145 | |||
| 146 | foreach (@drives) {
|
||
| 147 | my $dev; |
||
| 148 | $dev = $_ =~ /(.*)(?:_\d+)/ ? $1 : $_; |
||
| 149 | my $cmd = $smartctl.' -A '; |
||
| 150 | $cmd .= $ENV{'args_'.$_}.' ' if exists $ENV{'args_'.$_};
|
||
| 151 | $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 | } |
||
| 157 | my $output = `$cmd`; |
||
| 158 | if ($output =~ /Current Drive Temperature:\s*(\d+)/) {
|
||
| 159 | print "$_.value $1\n"; |
||
| 160 | } elsif ($output =~ /^(194 Temperature_Celsius.*)/m) {
|
||
| 161 | my @F = split ' ', $1; |
||
| 162 | print "$_.value $F[9]\n"; |
||
| 163 | } |
||
| 164 | } |
