LinHES Forums http://forum.linhes.org/ |
|
rrd_HDtemp.pl http://forum.linhes.org/viewtopic.php?f=3&t=15957 |
Page 1 of 1 |
Author: | bobmyth [ Tue Jul 24, 2007 9:50 pm ] |
Post subject: | rrd_HDtemp.pl |
I changed the HDtemp rrd script to allow logging more than one hard drive (I have 3). Instead of specifiying: Code: $dev = 'hda' you can now do Code: $dev = 'hda sda sdb' and get all the temperatures on the same graph.The script will only work with 6 hard drives because I hard wired the list of colors and only picked 6, this can be fixed. This list of colors could also be moved to the /etc/rrd.config file if desired. This script may not work well if you start with one hard drive, than add another one at a later time. The easiest way to deal with this situation is to erase the rrd database (rm -f /myth/rrd/log/HDtemp.rrd). Code: #!/usr/bin/perl
# # rrd_HDtemp.pl # Disk temperature data collection routine for KnoppMyth # ######################################################################## # Configuration: my $dev = 'hda sda sdb'; my $dbf = "HDtemp"; my $configfile = '/etc/rrd.config'; my @temps; my @colors = ('#0000FF', '#00FF00', '#FF0000', '#00FFFF', '#FF00FF', '#FFFF00'); ######################################################################## use RRDs; if (! -d "/myth") { $configfile = "./D_rrd.config"; } # DEBUG do $configfile; sub create { # $_[0] = filename if (! -e "$log/$_[0].rrd") { print "Create db for $_[0] => $log/$_[0].rrd\n"; push @args, "$log/$_[0].rrd"; push @args, "-s 300"; @devs = split /\s+/, $dev; for($i = 0; $i < scalar(@devs); $i++) { push @args, "DS:hdt" . ($i + 1) . ":GAUGE:600:0:U"; } push @args, "RRA:AVERAGE:0.5:1:576"; push @args, "RRA:AVERAGE:0.5:6:672"; push @args, "RRA:AVERAGE:0.5:24:732"; push @args, "RRA:AVERAGE:0.5:144:1460"; RRDs::create(@args); $ERROR = RRDs::error; print "Error: RRDs::create failed for '$_[0]' : $ERROR\n" if $ERROR; } } sub gather { my ($dev, $hdt1, $hdtT, $hdtD, $res); # device names in $_[0] $res = "$dbf:"; undef @temps; @devs = split /\s+/, $_[0]; foreach $_ (@devs) { $dev = "/dev/$_"; my $line = `/usr/sbin/hddtemp -q $dev`; chomp( $line ); my ( $devN, $devD, $devT ) = split( /\:\s+/, $line ); #print "HDtemp $_[0]: '$devN' '$devD' '$devT'\n"; my ( $dev1, $dev2 ) = split( /\s+or\s+/, $devT ); #print "HDtemp $_[0]: '$dev1' '$dev2'\n"; ( $hdt1, $hdtT ) = split( /\s+/, $dev1 ); #print "HDtemp $_[0]: '$hdt1' '$hdtT'\n"; if ($devN ne $dev) { $hdt1 = 0; $hdtT = '?'; $hdtD = ''; } else { $hdtD = $devD; } if ("$hdtT" eq "") {$hdt1 = "C"; } $out .= "$_: $hdt1, "; push @temps, $hdt1; } chop $out; # remove extra space chop $out; # remove extra comma print "$out\n"; } sub update { # $_[0] = filename my($str1, $str2); $str1 = ''; $str2 = 'N:'; for($i = 0; $i < scalar(@temps); $i++) { $str1 .= ("hdt" . ($i + 1) . ":"); $str2 .= ($temps[$i] . ":"); } chop $str1; # Get rid of last colon chop $str2; # Get rid of last colon RRDs::update("$log/$_[0].rrd", "-t", $str1, $str2); print "$str1\n$str2\n"; $ERROR = RRDs::error; print "Error: RRDs::update for '$_[0]' : $ERROR\n" if $ERROR; } sub graph { # $_[0] = time interval (ie: day...) # $_[1] = filename suffix. undef @args; @devs = split /\s+/, $dev; @args = ( "$png/$dbf-$_[1].png", "-s -1$_[0]", "-aPNG", "-w $Gwd", "-h $Ght", "-E", "-l 20", "-M", "--color", "SHADEA$color", "--color", "SHADEB$color", "--color", "BACK$color", "-t Disk temperature :: $_[0]"); for($i = 0; $i < scalar(@temps); $i++) { push @args, "DEF:hdt" . ($i + 1) . "=$log/$dbf.rrd:hdt" . ($i + 1) . ":A VERAGE"; push @args, "LINE1:hdt" . ($i+1) . "$colors[$i]: $devs[$i] degrees C\\:" , "GPRINT:hdt" . ($i + 1) . ":MIN:Minimum\\: %.0lf", "GPRINT:hdt" . ($i + 1) . ":MAX:Maximum\\: %.0lf", "GPRINT:hdt" . ($i + 1) . ":AVERAGE:Average\\: %.2lf", "GPRINT:hdt" . ($i + 1) . ":LAST:Current\\: %.1lf\\j"; } RRDs::graph(@args); $ERROR = RRDs::error; print "Error: RRDs::graph failed for '$_[0]' : $ERROR\n" if $ERROR; } ######################################################################## create "$dbf"; gather "$dev"; update "$dbf"; graph 'day', 'Daily'; graph 'week', 'Weekly'; graph 'month', 'Monthly'; graph 'year', 'Yearly'; ######################################################################## # vim: sw=4 ts=8 # End |
Author: | AggieEngineer2k [ Wed Jul 25, 2007 8:48 am ] |
Post subject: | |
Nifty script! Good on ya, mate! |
Author: | ghede [ Sat Aug 04, 2007 12:18 pm ] |
Post subject: | Error when running |
First off, thank you very much. I now see the temps for both drives... sweet!! For anyone else who might trip on this like I did... When I first tried this, I got this error: Error: RRDs::graph failed for 'day' : Cannot parse CF in 'DEF:hdt1=/myth/rrd/log/HDtemp.rrd:hdt1:A VERAGE' Being a newb, and after a lot of trial and error, I finally got it working. Three quarters of the way down the script, on this line: Code: push @args, "DEF:hdt" . ($i + 1) . "=$log/$dbf.rrd:hdt" . ($i + 1) . ":A VERAGE"; you'll notice that it's not all one line. Changing it to: Code: push @args, "DEF:hdt" . ($i + 1) . "=$log/$dbf.rrd:hdt" . ($i + 1) . ":AVERAGE";
makes it work. Again, a big thank you. Couldn't have done it myself. |
Page 1 of 1 | All times are UTC - 6 hours |
Powered by phpBB® Forum Software © phpBB Group http://www.phpbb.com/ |