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

help creating rrd_GPUTemp.pl (SOLVED)
http://forum.linhes.org/viewtopic.php?f=6&t=18852
Page 1 of 1

Author:  graysky [ Sat Aug 23, 2008 10:25 am ]
Post subject:  help creating rrd_GPUTemp.pl (SOLVED)

Can someone help me create an rrd monitor for my GPU temp? The key data gathering script is simply:

Code:
/usr/bin/nvclock -T | grep GPU | cut -c 21-22


Which on my machine will return the GPU temp as a two digit number.

I can't for the life of me adapt one of my rrd_x.pl scripts to work with this. I tried using my rrd_HDDTemp.pl and making what I thought were the correct changes. Anyway, I don't know perl :)

Can anyone with some perl skills have a crack at it for me?

Author:  graysky [ Sun Aug 24, 2008 2:33 pm ]
Post subject: 

I think I got it!

Image

I adapted the rrd_MBtemp.pl to work for GPU core temp. My only problem with it now is that I can't remove the green CPU Temp portion from the graph without causing errors when the script runs.

If I comment out any of the mbt2 lines, I get errors. Here is the modified script:
Code:
#!/usr/bin/perl
#
#  rrd_GPUtemp.pl
#   GPU Core temp for KnoppMyth
#
########################################################################
# Configuration:
my $dbf = 'GPUtemp';
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:mbt1:GAUGE:600:0:U",
       "DS:mbt2:GAUGE:600:0:U",
       "DS:mbt3: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;
    }
}

#my ($mbt1, $mbt2);
my $mbt1;

sub gather {
    $mbt1 = `/usr/bin/nvclock -T | grep GPU | cut -c 21-22`;
#    $mbt2 = `$MBT_prog 2`;
#    $mbt3 = `$MBT_prog 3`;
    $mbt1 =~ s/[\n ]//g;
#    $mbt2 =~ s/[\n ]//g;
#    $mbt3 =~ s/[\n ]//g;
    print "$dbf: gpu $mbt1, °C\n";
    # The motherboard sensor occasionally returns nonsense values.
    # This should keep the spurious peaks from roaching the graph...
#    if ($mbt1 > 100.0) { $mbt1 = $mbt2 }
#    print "$dbf: motherboard $mbt1, CPU $mbt2, case $mbt3, °C\n";
}

sub update {
    #   $_[0] = filename
    RRDs::update( "$log/$_[0].rrd", "-t",
   "mbt1",
   "N:$mbt1");
    $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", "SHADEB$color",
   "--color", "SHADEA$color",
   "--color", "BACK$color",
   "-t nVidia GeForce 6200 Core temperature degrees C :: $_[0]",
   "DEF:mbt1=$log/$dbf.rrd:mbt1:AVERAGE",
   "DEF:mbt2=$log/$dbf.rrd:mbt2:AVERAGE",
   "LINE1:mbt1$color_mbt1:GPU Core temp\\:",
   "GPRINT:mbt1:MIN:Minimum\\: % 5.1lf",
   "GPRINT:mbt1:MAX:Maximum\\: % 5.1lf",
   "GPRINT:mbt1:AVERAGE:Average\\: % 5.1lf",
   "GPRINT:mbt1:LAST:Current\\: % 5.1lf °C\\j",
   "LINE1:mbt2$color_mbt2:CPU temp\\:",
   "GPRINT:mbt2:MIN:Minimum\\: % 5.1lf",
   "GPRINT:mbt2:MAX:Maximum\\: % 5.1lf",
   "GPRINT:mbt2:AVERAGE:Average\\: % 5.1lf",
   "GPRINT:mbt2:LAST:Current\\: % 5.1lf °C\\j");
    $ERROR = RRDs::error;
    print "Error: RRDs::graph failed for '$_[0]' : $ERROR\n" if $ERROR;
}
########################################################################
create "$dbf";
gather;
update "$dbf";
graph '2hour', '12hourly';
graph 'day',   'Daily';
graph 'week',  'Weekly';
graph 'month', 'Monthly';
graph 'year',  'Yearly';
########################################################################
# vim: sw=4 ts=8
# End


If anyone can tell me what I need to do to it to remove the green CPU Temp, I'd really appreciate it :)

Author:  md10md [ Sun Aug 24, 2008 3:16 pm ]
Post subject: 

Great work! I've added it to my config. Thanks again.

Author:  graysky [ Sun Aug 24, 2008 4:23 pm ]
Post subject: 

Hehe, is it working? You might have rm -rf .nvclock and then touch .nvclock in your /home/mythtv for it to work. It worked out-of-the-box on one machine, but I had to do as I described above on two other machines.

It's also pretty crude and not very elegant at the moment... I'm still hoping someone out there will help out by cleaning it up :)

Author:  md10md [ Sun Aug 24, 2008 4:25 pm ]
Post subject: 

Yeah, worked OOTB for me. I've used nvclock in the past though and I think I remember having to mess around with that file. When (If) I get around to it I'll try changing the file to see if I can get that defunct CPU temp out of their.

Author:  graysky [ Sun Aug 24, 2008 4:28 pm ]
Post subject: 

Cool man, I'm always glad to share with the community.

You do know to edit your /usr/local/bin/rrd_Config.sh and add a line for the GPUTemp right? That way, the cgi script will make your GPUTemp.html automatically.

Here is the relevant section of mine for your reference:
Code:
    # Establish the checklist:
    TYPARY=( \
    Net         "Network In/Out Traffic"        on \
    Disk        "Disk reads/writes"             on \
    Count       "Count of files in /myth/tv"    on \
    MythFS      "/myth Space & Inode usage"     on \
    HDtemp      "Disk temperature"              on \
    GPUtemp     "GPU temperature"               off \
    MBtemp      "MB and CPU temperature"        off \
    MBfan       "MB fan speeds"                 off \
    UPS         "UPS information"               off \

Author:  graysky [ Sun Aug 24, 2008 11:05 pm ]
Post subject: 

Figured it out! It's all about the grammar of the perl script.

Original code (relevant section):
Code:
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", "SHADEB$color",
   "--color", "SHADEA$color",
   "--color", "BACK$color",
   "-t nVidia GeForce 6200 Core temperature degrees C :: $_[0]",
   "DEF:mbt1=$log/$dbf.rrd:mbt1:AVERAGE",
   "DEF:mbt2=$log/$dbf.rrd:mbt2:AVERAGE",
   "LINE1:mbt1$color_mbt1:GPU Core temp\\:",
   "GPRINT:mbt1:MIN:Minimum\\: % 5.1lf",
   "GPRINT:mbt1:MAX:Maximum\\: % 5.1lf",
   "GPRINT:mbt1:AVERAGE:Average\\: % 5.1lf",
   "GPRINT:mbt1:LAST:Current\\: % 5.1lf °C\\j",
   "LINE1:mbt2$color_mbt2:CPU temp\\:",
   "GPRINT:mbt2:MIN:Minimum\\: % 5.1lf",
   "GPRINT:mbt2:MAX:Maximum\\: % 5.1lf",
   "GPRINT:mbt2:AVERAGE:Average\\: % 5.1lf",
   "GPRINT:mbt2:LAST:Current\\: % 5.1lf °C\\j");


Functional code (relevant section):
Code:
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 40", "-r", "-v temp. (°C)", "-M",
        "--color", "SHADEB$color",
        "--color", "SHADEA$color",
        "--color", "BACK$color",
        "-t nVidia GeForce 6200 Core temperature :: $_[0]",
        "DEF:mbt1=$log/$dbf.rrd:mbt1:AVERAGE",
#       "DEF:mbt2=$log/$dbf.rrd:mbt2:AVERAGE",
        "LINE1:mbt1$color_mbt1:GPU Core temp\\:",
        "GPRINT:mbt1:MIN:Minimum\\: % 5.1lf",
        "GPRINT:mbt1:MAX:Maximum\\: % 5.1lf",
        "GPRINT:mbt1:AVERAGE:Average\\: % 5.1lf",
        "GPRINT:mbt1:LAST:Current\\: % 5.1lf °C\\j");
#       "LINE1:mbt2$color_mbt2:CPU temp\\:",
#       "GPRINT:mbt2:MIN:Minimum\\: % 5.1lf",
#       "GPRINT:mbt2:MAX:Maximum\\: % 5.1lf",
#       "GPRINT:mbt2:AVERAGE:Average\\: % 5.1lf",
#       "GPRINT:mbt2:LAST:Current\\: % 5.1lf °C\\j");


See the difference? No? It was all about the position of the ending ) mark. You have to move it up to the the end of the mbt1 lines and end with a ; (see the "GPRINT:mbt1:LAST:Current\\: % 5.1lf °C\\j"); line).

Anyway, now it works just fine:

Before
Image

After
Image

Oh, the other thing I did was to add the following to the line that defines the graph:

"-l 40",
"-r",
"-v temp. (°C)",

The "-l 40" limits to lower axis to 40 when you invoke the "-r" switch that rigidly enforces the limit. The "-v temp. (°C)" switch adds the text to the vertical axis. BTW, you get the ° sign by typing alt+0176. For more, see the rrdgraph docs.

Author:  graysky [ Sun Aug 24, 2008 11:58 pm ]
Post subject: 

I also combined the video card and hdd temps into one graph. Why not add the mb and cpu temp? I wrote this for a machine that's from 1997 and doesn't have mb and cpu logging!

Image

If you're interested, here is the modified /usr/local/bin/rrd_GPUtemp.pl:
Code:
#!/usr/bin/perl
#
#  rrd_MBtemp.pl
#   Motherboard Temperature data collection routine for KnoppMyth
#
########################################################################
# Configuration:
my $dbf = 'GPUtemp';
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:mbt1:GAUGE:600:0:U",
       "DS:mbt2:GAUGE:600:0:U",
       "DS:mbt3: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;
    }
}

my ($mbt1, $mbt2);

sub gather {
    $mbt1 = `/usr/bin/nvclock -T | grep GPU | cut -c 21-22`;
    $mbt2 = `/usr/sbin/hddtemp -n /dev/hda`;
#    $mbt3 = `$MBT_prog 3`;
    $mbt1 =~ s/[\n ]//g;
    $mbt2 =~ s/[\n ]//g;
#    $mbt3 =~ s/[\n ]//g;

    print "$dbf: gpu temp $mbt1, hdd temp $mbt2, °C\n";

    # The motherboard sensor occasionally returns nonsense values.
    # This should keep the spurious peaks from roaching the graph...
    if ($mbt1 > 100.0) { $mbt1 = $mbt2 }
#    print "$dbf: GPU Core temp $mbt1, $mbt2, HDD temp $mbt3, °C\n";
    print "$dbf: gpu temp $mbt1, hdd temp $mbt2, °C\n";
}

sub update {
    #   $_[0] = filename
    RRDs::update( "$log/$_[0].rrd", "-t",
   "mbt1:mbt2",
   "N:$mbt1:$mbt2");
    $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", "-A",
   "--color", "SHADEB$color",
   "--color", "SHADEA$color",
   "--color", "BACK$color",
   "-t Video Card and HDD Core Temperature (° C) :: $_[0]",
   "DEF:mbt1=$log/$dbf.rrd:mbt1:AVERAGE",
   "DEF:mbt2=$log/$dbf.rrd:mbt2:AVERAGE",
   "LINE1:mbt1$color_mbt1:GPU\\:",
   "GPRINT:mbt1:MIN:Minimum\\: % 5.1lf",
   "GPRINT:mbt1:MAX:Maximum\\: % 5.1lf",
   "GPRINT:mbt1:AVERAGE:Average\\: % 5.1lf",
   "GPRINT:mbt1:LAST:Current\\: % 5.1lf °C\\j",
   "LINE1:mbt2$color_mbt3:HDD\\:",
   "GPRINT:mbt2:MIN:Minimum\\: % 5.1lf",
   "GPRINT:mbt2:MAX:Maximum\\: % 5.1lf",
   "GPRINT:mbt2:AVERAGE:Average\\: % 5.1lf",
   "GPRINT:mbt2:LAST:Current\\: % 5.1lf °C\\j");
    $ERROR = RRDs::error;
    print "Error: RRDs::graph failed for '$_[0]' : $ERROR\n" if $ERROR;
}
########################################################################
create "$dbf";
gather;
update "$dbf";
graph '2hour', '12hourly';
graph 'day',   'Daily';
graph 'week',  'Weekly';
graph 'month', 'Monthly';
graph 'year',  'Yearly';
########################################################################
# vim: sw=4 ts=8
# End


Oh, and I removed the -v stuff from the last post because it resized the output png making it slightly larger than the others. I also took away some of the graphing options and replaced them with the -A for auto scaling.

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