LinHES Forums
http://forums.linhes.org/

rrd_MBfan.pl
http://forums.linhes.org/viewtopic.php?f=3&t=16001
Page 1 of 1

Author:  bobmyth [ Mon Jul 30, 2007 9:22 pm ]
Post subject:  rrd_MBfan.pl

The version of rrd_MBfan.pl in R5F1 does not appear to work, however this one does. There are two items that may have to be changed, depending on your system:
Code:
my @dev = ('FAN0', 'FAN1', 'FAN2');
my @label = ("CPU Fan", "PS Fan", "Chip Fan");


If you only have two fans, remove the appropriate item from @dev and from @label to ignore that item. You may also need to change the order of the labels to get them to match your system.

If you have existing files you may need to erase them to get this working properly:
Code:
rm -f /myth/rrd/log/MBfan.rrd
rm -f /myth/rrd/png/MBfan-*.png


Code:
#!/usr/bin/perl
#
# Modified from Martin Pot's 2003 script at
# http://martybugs.net/linux/hddtemp.cgi
#
# Graphs motherboard fan speed using mbmon
# rrd_MBfan.pl

########################################################################
# Configuration:
# run mbmon -r -c 1 to see what temps your mobo supports, then change @dev
my @dev = ('FAN0', 'FAN1', 'FAN2');
my @label = ("CPU Fan", "PS Fan", "Chip Fan");
my $dbf = 'MBfan';
my @rdgs;
my $configfile = '/etc/rrd.config';
my @colors = ('#0000FF', '#00FF00', '#FF0000');
########################################################################
use RRDs;

if (! -d "/myth") { $configfile = "./D_rrd.config"; }   # DEBUG
do $configfile;

sub create {
        my $filename = shift;
        my @args;
        undef @args;
        if(! -e "$log/$filename.rrd") {
                print "Create db for $filename => $log/$filename.rrd\n";
                push @args, "$log/$filename.rrd";
                push @args, "-s 300";
                for(my $i = 0; $i < scalar(@dev); $i++) {
                       push @args, "DS:spd" . $i . ":GAUGE:600:0:10000";
                }
                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 '$filename' : $ERROR\n" if
 $ERROR;
        }
}

sub gather {
        my ($line, $r, @list);
        if(open P, "mbmon -r -c 1 |") {
                while($line = <P>) {
                        chomp $line;
                        foreach $r (@dev) {
                                next if($line !~ m/^$r/);
                                @list = split /\s*:\s*/, $line;
                                push @rdgs, $list[1];
                        }
                }
                close P;
        }
}

sub update {
        # $_[0] = filename
        my($str1, $str2);
        $str1 = '';
        $str2 = 'N:';
        for($i = 0; $i < scalar(@dev); $i++) {
                $str1 .= ("spd" . $i . ":");
                $str2 .= ($rdgs[$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;
    @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 Fan Speed:: $_[0]");
    for($i = 0; $i < scalar(@dev); $i++) {
        push @args, "DEF:spd" . $i . "=$log/$dbf.rrd:spd" . $i . ":AVERAGE";
        push @args, "LINE1:spd" . $i . "$colors[$i]: $label[$i] RPM\\:",
        "GPRINT:spd" . $i . ":MIN:Minimum\\: %.0lf",
        "GPRINT:spd" . $i . ":MAX:Maximum\\: %.0lf",
        "GPRINT:spd" . $i . ":AVERAGE:Average\\: %.2lf",
        "GPRINT:spd" . $i . ":LAST:Current\\: %.1lf\\j";
    }
    RRDs::graph(@args);
    $ERROR = RRDs::error;
    $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

Page 1 of 1 All times are UTC - 6 hours
Powered by phpBB® Forum Software © phpBB Group
http://www.phpbb.com/