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

Configuring rrdtool
http://forum.linhes.org/viewtopic.php?f=3&t=13190
Page 1 of 2

Author:  mlbuser [ Sat Dec 30, 2006 4:31 pm ]
Post subject:  Configuring rrdtool

If like me, you don't have an eth0 or an hda, it's nice to change the R5E50 rrdtool setup so it reflects your system.

The data collection files to change are in /usr/local/bin/rrdtool_*.pl
The web page files to change are in /var/www/rrdtool_*.html.

For me I have a wireless connection so I modified /usr/local/bin/rrdtool_traffic.pl to monitor /dev/ath0 instead of /dev/eth0.
Likewise you have to modify /var/www/rrdtool_daily.html and change eth0 to ath0. Do this for weekly, monthly, and yearly.

I changed hda to sda to monitor my actual HD as well.

Now the web display for rrdtool is correct for my system, very easy to change.

Author:  tjc [ Sat Dec 30, 2006 4:44 pm ]
Post subject: 

I think you mean: /usr/local/bin/rrd_*.pl

Author:  opel70 [ Tue Jan 09, 2007 5:27 pm ]
Post subject: 

OK, I got my RRDtool graphs updating by using the suggestion in the "Don't Panic" thread. However, my eth0 chart isn't updating. I actually do have an eth0 (I even double checked my ifconfig just to make sure it wasn't something strange). I am using an HDHomeRun device as my HD tuner, so I know that I should be having some network traffic, but it is not showing up on my charts.

Where should I begin my search to get this configured correctly for my system?

Thanks,

Author:  shade4 [ Tue Jan 09, 2007 6:30 pm ]
Post subject: 

A search of the forum on rrd_traffic should do it.

Author:  opel70 [ Tue Jan 09, 2007 7:35 pm ]
Post subject: 

Thanks, I had been searching for rrdtool, which doesn't exist anywhere in that thread.

Author:  tjc [ Tue Jan 09, 2007 9:00 pm ]
Post subject: 

For future reference the thread in question is here: "R5E50 upgrade and rrd_traffic doesn't update to mythweb"

Author:  Gnarl [ Wed Jan 10, 2007 12:07 pm ]
Post subject: 

I did a little modding also. I have many hard drives and I wanted it to report the temp for all the hard drives so I modded the script to get them all.

Code:
#!/usr/bin/perl
#
# copyright Martin Pot 2003
# http://martybugs.net/linux/hddtemp.cgi
#
# rrd_hddtemp.pl

use RRDs;

# define location of rrdtool databases
my $rrd = '/var/lib/rrd';
# define location of images
my $img = '/var/www/rrdtool';

#Define Drives
$hd1 = 'hda';
$hd2 = 'hdb';
$hd3 = 'sda';
$hd4 = 'sdb';
#define drive descriptions
$hd1des = 'Maxtor 120G';
$hd2des = 'Maxtor 160G';
$hd3des = 'WD 500G    ';
$hd4des = 'Maxtor 250G';

# process data for each specified HDD (add/delete as required)
&ProcessHDD($hd1, $hd1des);
&ProcessHDD($hd2, $hd2des);
&ProcessHDD($hd3, $hd3des);
&ProcessHDD($hd4, $hd4des);

sub ProcessHDD
{
# process HDD
# inputs: $_[0]: hdd (ie, hda, etc)
#         $_[1]: hdd description

        # get hdd temp for master drive on secondary IDE channel
        my $temp=`/usr/sbin/hddtemp -n /dev/$_[0]`;
        # remove eol chars and white space
        $temp =~ s/[\n ]//g;

        print "$_[1] (/dev/$_[0]) temp: $temp degrees C\n";

        # if rrdtool database doesn't exist, create it
        if (! -e "$rrd/$_[0].rrd")
        {
                print "creating rrd database for /dev/$_[0]...\n";
                RRDs::create "$rrd/$_[0].rrd",
                        "-s 300",
                        "DS:temp:GAUGE:600:0:100",
                        "RRA:AVERAGE:0.5:1:576",
                        "RRA:AVERAGE:0.5:6:672",
                        "RRA:AVERAGE:0.5:24:732",
                        "RRA:AVERAGE:0.5:144:1460";
        }

        # insert value into rrd
        RRDs::update "$rrd/$_[0].rrd",
                "-t", "temp",
                "N:$temp";

}
        &CreateGraph("", "day");
        &CreateGraph("", "week");
        &CreateGraph("", "month");
        &CreateGraph("", "year");

sub CreateGraph
{
# creates graph
# inputs: $_[0]: hdd name (ie, hda, etc)
#         $_[1]: interval (ie, day, week, month, year)
#         $_[2]: hdd description

        RRDs::graph "$img/hddtemp-$_[1].png",
                "--lazy",
                "-s -1$_[1]",
                "-t hdd temperature :: Hard Disk Drives",
                "-h", "80", "-w", "600",
                "-a", "PNG",
                "-v degrees C",
                "DEF:$hd1=$rrd/$hd1.rrd:temp:AVERAGE",
                "DEF:$hd2=$rrd/$hd2.rrd:temp:AVERAGE",
                "DEF:$hd3=$rrd/$hd3.rrd:temp:AVERAGE",
                "DEF:$hd4=$rrd/$hd4.rrd:temp:AVERAGE",
                "LINE2:$hd1#0000FF:$hd1des",
                "GPRINT:$hd1:MIN:  Min\\: %2.lf",
                "GPRINT:$hd1:MAX: Max\\: %2.lf",
                "GPRINT:$hd1:AVERAGE: Avg\\: %4.1lf",
                "GPRINT:$hd1:LAST: Current\\: %2.lf degrees C\\n",
                "LINE2:$hd2#CC00CC:$hd2des",
                "GPRINT:$hd2:MIN:  Min\\: %2.lf",
                "GPRINT:$hd2:MAX: Max\\: %2.lf",
                "GPRINT:$hd2:AVERAGE: Avg\\: %4.1lf",
                "GPRINT:$hd2:LAST: Current\\: %2.lf degrees C\\n",
                "LINE2:$hd3#339900:$hd3des",
                "GPRINT:$hd3:MIN:  Min\\: %2.lf",
                "GPRINT:$hd3:MAX: Max\\: %2.lf",
                "GPRINT:$hd3:AVERAGE: Avg\\: %4.1lf",
                "GPRINT:$hd3:LAST: Current\\: %2.lf degrees C\\n",
                "LINE2:$hd4#553388:$hd4des",
                "GPRINT:$hd4:MIN:  Min\\: %2.lf",
                "GPRINT:$hd4:MAX: Max\\: %2.lf",
                "GPRINT:$hd4:AVERAGE: Avg\\: %4.1lf",
                "GPRINT:$hd4:LAST: Current\\: %2.lf degrees C\\n";

        if ($ERROR = RRDs::error) { print "$0: unable to generate $_[1] graph: $ERROR\n"; }
}


To set it up for yourself, just modify
Code:
#Define Drives
$hd1 = 'hda';
$hd2 = 'hdb';
$hd3 = 'sda';
$hd4 = 'sdb';
#define drive descriptions
$hd1des = 'Maxtor 120G';
$hd2des = 'Maxtor 160G';
$hd3des = 'WD 500G    ';
$hd4des = 'Maxtor 250G';
to match your own setup, and if you don't have 4 hard drives you can comment out the lines necessary in
Code:
# process data for each specified HDD (add/delete as required)
&ProcessHDD($hd1, $hd1des);
&ProcessHDD($hd2, $hd2des);
&ProcessHDD($hd3, $hd3des);
&ProcessHDD($hd4, $hd4des);
and you will also need to comment out the lines at the bottom that involve the above commented lines eg:
Code:
"DEF:$hd4=$rrd/$hd4.rrd:temp:AVERAGE",
and
Code:
"LINE2:$hd4#553388:$hd4des",
"GPRINT:$hd4:MIN:  Min\\: %2.lf",
"GPRINT:$hd4:MAX: Max\\: %2.lf",
"GPRINT:$hd4:AVERAGE: Avg\\: %4.1lf",
"GPRINT:$hd4:LAST: Current\\: %2.lf degrees C\\n";
WARNING: if you do comment out the lines above you will need to move the ; to the last line of the last hard drive you are monitoring

You will also need to modify your /var/www/rrdtool_*.html so it picks up the correct graph. replace hda with hddtemp on the line
Code:
          <p align="center" class="style2 style1"><img src="rrdtool/hddtemp-day.png" alt="hddtemp_day" width="693" height="161">

Author:  tjc [ Wed Jan 10, 2007 8:03 pm ]
Post subject: 

The disk activity and temperature monitoring (and possibly other things) should really loop over multiple devices and process them. This avoids the need for most folks to tweak these things manually. Sadly I've made great strides in forgetting most of the Perl I ever learned, and really don't want to reverse the process for long enough to fix this. ;-) Can some helpful perlyte have a go at this?

- rrd_disk.pl Should either sum up the activity from all the drives matching "^[hs]d[a-h]" as listed by "/usr/bin/iostat -d", or draw a stack chart of activity for the various drives.

- rrd_hddtemp.pl should either draw a chart for each drive or plot a different colored line on the same chart for each drive detected via "hddtemp /dev/[hs]d[a-h]". Note that this will require filtering out lines like this:
Code:
/dev/hdc: _NEC DVD_RW ND-3520A: S.M.A.R.T. not available


(edit 1: Corrected the hddtemp command since the names would be needed.)

Author:  Gnarl [ Wed Jan 10, 2007 9:24 pm ]
Post subject: 

tjc wrote:
- rrd_hddtemp.pl should either draw a chart for each drive or plot a different colored line on the same chart for each drive detected via "hddtemp -n /dev/[hs]d[a-h]". Note that this will require filtering out lines like this:
Code:
/dev/hdc: _NEC DVD_RW ND-3520A: S.M.A.R.T. not available
The rrd_hddtemp.pl draws all the temps on one graph. Sadly my Perl Kung-fu does not extend much past "Hello World", so i am not able to filter and scan for the drives. If someone one is then please do.
I did manage to fix the rrd_mbtemp.pl script. The temps set up match my sensors.
Code:
#!/usr/bin/perl
#
# Modified from Martin Pot's 2003 script at
# http://martybugs.net/linux/hddtemp.cgi
#
# Graphs motherboard temperatures using mbmon
# rrd_mbtemp.pl

use RRDs;

# define location of rrdtool databases
my $rrd = '/var/lib/rrd';
# define location of images
my $img = '/var/www/rrdtool';
#define devices
$temp1 = 'cputemp';
$temp2 = 'ambtemp';
$temp3 = 'mbtemp';
#define device descriptions
$temp1des = 'CPU Temperature';
$temp2des = 'Case Temperature';
$temp3des = 'MB Temperature';

# process data for each temperature sensor (add/delete as required)
# run mbmon -r -c 1 to see what temps your mobo supports, then make
# an educated guess about which component corresponds to which temp
# Note TEMP0 = T 1, TEMP1 = T 2, TEMP2 = T 3
&ProcessHDD($temp1, "T 1", $temp1des);
&ProcessHDD($temp2, "T 2", $temp2des);
&ProcessHDD($temp3, "T 3", $temp3des);

sub ProcessHDD
{
# process HDD
# inputs: $_[0]: component being measured (used for graph filenames)
#          $_[1]: code (mbmon code)
#         $_[2]: description

        # get temp value from mbmon
        my $temp=`/usr/bin/mbmon -c 1 -$_[1]`;
        # remove eol chars and white space
        $temp =~ s/[\n ]//g;

        print "$_[2] temp: $temp degrees C\n";

        # if rrdtool database doesn't exist, create it
        if (! -e "$rrd/$_[0].rrd")
        {
                print "creating rrd database for $_[0]...\n";
                RRDs::create "$rrd/$_[0].rrd",
                        "-s 300",
                        "DS:temp:GAUGE:600:0:100",
                        "RRA:AVERAGE:0.5:1:576",
                        "RRA:AVERAGE:0.5:6:672",
                        "RRA:AVERAGE:0.5:24:732",
                        "RRA:AVERAGE:0.5:144:1460";
        }

        # insert value into rrd
        RRDs::update "$rrd/$_[0].rrd",
                "-t", "temp",
                "N:$temp";

}
        # create graphs
        &CreateGraph("", "day", $_[2]);
        &CreateGraph("", "week", $_[2]);
        &CreateGraph("", "month", $_[2]);
        &CreateGraph("", "year", $_[2]);

sub CreateGraph
{
# creates graph
# inputs: $_[0]: component being measured (used for graph filenames)
#         $_[1]: interval (ie, day, week, month, year)
#         $_[2]: description

        RRDs::graph "$img/mbmon-$_[1].png",
                "--lazy",
                "-s -1$_[1]",
#                "--color", "SHADEA#EAE9EE",
#                "--color", "SHADEB#EAE9EE",
#                "--color", "BACK#295990",
                "-t temperature from mbmon",
                "-h", "80", "-w", "600",
                "-a", "PNG",
                "-v degrees C",
                "DEF:$temp1=$rrd/$temp1.rrd:temp:AVERAGE",
                "DEF:$temp2=$rrd/$temp2.rrd:temp:AVERAGE",
                "DEF:$temp3=$rrd/$temp3.rrd:temp:AVERAGE",
                "LINE2:$temp1#0000FF:$temp1des",
                "GPRINT:$temp1:MIN:  Min\\: %2.lf",
                "GPRINT:$temp1:MAX: Max\\: %2.lf",
                "GPRINT:$temp1:AVERAGE: Avg\\: %4.1lf",
                "GPRINT:$temp1:LAST: Current\\: %2.lf degrees C\\n",
                "LINE2:$temp2#00FF00:$temp2des",
                "GPRINT:$temp2:MIN:  Min\\: %2.lf",
                "GPRINT:$temp2:MAX: Max\\: %2.lf",
                "GPRINT:$temp2:AVERAGE: Avg\\: %4.1lf",
                "GPRINT:$temp2:LAST: Current\\: %2.lf degrees C\\n",
                "LINE2:$temp3#FF0000:$temp3des",
                "GPRINT:$temp3:MIN:  Min\\: %2.lf",
                "GPRINT:$temp3:MAX: Max\\: %2.lf",
                "GPRINT:$temp3:AVERAGE: Avg\\: %4.1lf",
                "GPRINT:$temp3:LAST: Current\\: %2.lf degrees C\\n";
        if ($ERROR = RRDs::error) { print "$0: unable to generate $_[0] graph: $ERROR\n"; }
}

You will also want to add the line below to your /var/www/rrdtool_*.html files
Code:
<p align="center" class="style2 style1"><img src="rrdtool/mbmon-day.png" alt="mbmon_day">
and the this line to the /etc/cron.hourly/rrd_km
Code:
/usr/local/bin/rrd_mbtemp.pl > /dev/null

Author:  Gnarl [ Wed Jan 10, 2007 9:52 pm ]
Post subject: 

Is it possible to add the /var/lib/rrd directory to the backup and restore scripts?

Author:  md10md [ Wed Jan 10, 2007 10:16 pm ]
Post subject: 

Thanks Gnarl, the scripts work great. I was waiting for someone to put them together as my perl skills were just a little (very) rusty.

Author:  tjc [ Wed Jan 10, 2007 10:20 pm ]
Post subject: 

That is what the supplemental /myth/backup/backup.list and /myth/backup/restore.list files are for. See the "Taking advantage of the enhanced backup and restore scripts" posting for more details.

You probably want to add:
Code:
./var/lib/rrd
./var/www/rrdtool_daily.html
./var/www/rrdtool_monthly.html
./var/www/rrdtool_weekly.html
./var/www/rrdtool_yearly.html
./usr/local/bin/rrd_cpu.pl
./usr/local/bin/rrd_disk.pl
./usr/local/bin/rrd_hddtemp.pl
./usr/local/bin/rrd_mbtemp.pl
./usr/local/bin/rrd_mem.pl
./usr/local/bin/rrd_traffic.pl

Author:  tjc [ Wed Jan 10, 2007 10:31 pm ]
Post subject: 

OBTW - I changed the data collection bit of my rrd_disk.pl like this to give a simple summary:
Code:
        my @diskdata = `/usr/bin/iostat -d | awk '/[hs]d[a-h]/ {rd+=\$5;wr+=\$6;} END {print rd,wr}'`;
        my $temp = $diskdata[0];
        chomp($temp);

        my @tempa = split(/\s+/, $temp);

        $readsect= $tempa[0];
        $writesect= $tempa[1];

        print "Sectors read:$readsect Sectors written:$writesect\n";

Author:  mihanson [ Thu May 24, 2007 4:54 pm ]
Post subject: 

This seems like the appropriate thread for this...

I'm struggling with adding additional hard drive temps to the included perl script rrd_HDtemp.pl in R5F1. I used Gnarl's script above with R5E50, but I wanted to try to get it to work with the script in R5F1 and use only one rrd db (i.e. all data stored in HDtemp.rrd). Gnarl's requires a seperate db for each HDD. I have two HDD, both are SATA, so sda and sdb. I've been working on this for a few days and can't seem to make headway. Can anyone offer assistance?

Author:  mihanson [ Fri May 25, 2007 8:48 pm ]
Post subject: 

Ok, I figured it out... In case anyone needs to add a second hard drive for temperature monitoring, here's my script and associated section of the config file:
Code:
#!/usr/bin/perl
#
#  rrd_HDtemp.pl
#       Disk temperature data collection routine for KnoppMyth
#
# Edited to add second hard drive monitor
# Mike Hanson 05/25/2007
#
########################################################################
# Configuration:
my $dbf = 'HDtemp';
my $configfile = '/etc/rrd.config';
########################################################################
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";
        RRDs::create( "$log/$_[0].rrd", "-s 300",
            "DS:hdt1:GAUGE:600:0:U",
####################################
#### Added the second DS below #####
####################################
            "DS:hdt2:GAUGE:600:0:U",
            "RRA:AVERAGE:0.5:1:576",
            "RRA:AVERAGE:0.5:6:672",
            "RRA:AVERAGE:0.5:24:732",
            "RRA:AVERAGE:0.5:144:1460");
        $ERROR = RRDs::error;
        print "Error: RRDs::create failed for '$_[0]' : $ERROR\n" if $ERROR;
    }
}
##########################################
#### Added second set of $hdt?n below ####
##########################################
my ($hdt1, $hdt2, $hdtT1, $hdtT2, $hdtD1, $hdtD2);

###################################################################
#### I run the script in sub gather below one time per device. ####
#### There may be a more elegant way to do this, but it works. ####
###################################################################
sub gather {
  { #   $_[0] device name
    my $line1 = `/usr/sbin/hddtemp -q /dev/$_[0]`;
    chomp( $line1 );
    my ( $devN1, $devD1, $devT1 ) = split( /\:\s+/, $line1 );
    #print "HDtemp $_[0]: '$devN1' '$devD1' '$devT1'\n";
    my ( $dev11, $dev21 ) = split( /\s+or\s+/, $devT1 );
    #print "HDtemp $_[0]: '$dev11' '$dev21'\n";
    ( $hdt1, $hdtT1 ) = split( /\s+/, $dev11 );
    #print "HDtemp $_[0]: '$hdt1' '$hdtT1'\n";
    if ($devN1 ne "/dev/$_[0]") {
        $hdt1 = 0; $hdtT1 = '?'; $hdtD1 = '';
    } else {
        $hdtD1 = $devD1;
    }
    if ("$hdtT1" eq "") {$hdt1 = "C"; }
    print "HDtemp $_[0]: '$hdtD1' '$hdt1 $hdtT1'\n";
 }
 { #  $_[1] device name
    my $line2 = `/usr/sbin/hddtemp -q /dev/$_[1]`;
    chomp( $line2 );
    my ( $devN2, $devD2, $devT2 ) = split( /\:\s+/, $line2 );
    #print "HDtemp $_[1]: '$devN2' '$devD2' '$devT2'\n";
    my ( $dev12, $dev22 ) = split( /\s+or\s+/, $devT2 );
    #print "HDtemp $_[1]: '$dev12' '$dev22'\n";
    ( $hdt2, $hdtT2 ) = split( /\s+/, $dev12 );
    #print "HDtemp $_[1]: '$hdt2' '$hdtT2'\n";
    if ($devN2 ne "/dev/$_[1]") {
        $hdt2 = 0; $hdtT2 = '?'; $hdtD2 = '';
    } else {
        $hdtD2 = $devD2;
    }
    if ("$hdtT2" eq "") {$hdt2 = "C"; }
    print "HDtemp $_[1]: '$hdtD2' '$hdt2 $hdtT2'\n";
  }
}

################################################
#### Added hdt2 to the update routine below ####
################################################
sub update {
    #   $_[0] = filename
    RRDs::update( "$log/$_[0].rrd", "-t",
        "hdt1:hdt2",
        "N:$hdt1:$hdt2");
    $ERROR = RRDs::error;
    print "Error: RRDs::update for '$_[0]' : $ERROR\n" if $ERROR;
}

sub graph {
    #   $_[0] = time interval (ie: day...)
    #   $_[1] = filename suffix.
    RRDs::graph( "$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 $dev1/$dev2 ($hdtD1/$hdtD2) temp :: $_[0]",
        "DEF:hdt1=$log/$dbf.rrd:hdt1:AVERAGE",
############################################
#### Added second DEF for hdt2 below.   ####
#### Added second $color_hdt? variable. ####
#### Changed LINE1 to LINE2 for thicker ####
#### lines on the graphs.               ####
############################################
        "DEF:hdt2=$log/$dbf.rrd:hdt2:AVERAGE",
        "LINE2:hdt1$color_hdt1: $dev1 degrees $hdtT1\\:",
        "GPRINT:hdt1:MIN:Minimum\\: %.0lf",
        "GPRINT:hdt1:MAX:Maximum\\: %.0lf",
        "GPRINT:hdt1:AVERAGE:Average\\: %.2lf",
        "GPRINT:hdt1:LAST:Current\\: %.1lf\\j",
        "LINE2:hdt2$color_hdt2: $dev2 degrees $hdtT2\\:",
        "GPRINT:hdt2:MIN:Minimum\\: %.0lf",
        "GPRINT:hdt2:MAX:Maximum\\: %.0lf",
        "GPRINT:hdt2:AVERAGE:Average\\: %.2lf",
        "GPRINT:hdt2:LAST:Current\\: %.1lf\\j");
    $ERROR = RRDs::error;
    print "Error: RRDs::graph failed for '$_[0]' : $ERROR\n" if $ERROR;
}
########################################################################
create "$dbf";
#####################################################
#### Changed '$dev' to '$dev1' and added '$dev2' ####
#### to gather below.                            ####
#####################################################
gather "$dev1", "$dev2";
update "$dbf";
graph 'day',   'Daily';
graph 'week',  'Weekly';
graph 'month', 'Monthly';
graph 'year',  'Yearly';
########################################################################
# vim: sw=4 ts=8
# End


Code:
/etc/rrd.config
#=======================================================================
#  rrd_HDtemp.pl config:        # hard disk temperature
#-----------------------------------------------------------------------
$dev1 = 'sda';                  # Disk being measured
$dev2 = 'sdb';                  # Disk being measured
$color_hdt1 = '#0000FF';        # color of temperature graph line
$color_hdt2 = '#00FF00';        # color of temperature graph line
#=======================================================================

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