rendered paste body#!/opt/local/bin/perl
use RRDs;
# define location of rrdtool databases
my $rrd = '/Users/madison';
# define location of images
my $img = '/Users/madison/Sites';
my $temp =`/usr/bin/tempmonitor -tv`;
# remove eol chars and white space
$temp =~ s/[\n ]//g;
# split data
($time,$c1,$c2,$c3,$c4,$d1,$d2,$d3,$d4) = split(/,/, $temp);
#print "temp c1: $c1 degrees C\n";
#print "temp c2: $c2 degrees C\n";
#print "temp c3: $c3 degrees C\n";
#print "temp c4: $c4 degrees C\n";
#print "temp d1: $d1 degrees C\n";
#print "temp d2: $d2 degrees C\n";
#print "temp d3: $d3 degrees C\n";
#print "temp d4: $d4 degrees C\n";
# if rrdtool database doesn't exist, create it
if (! -e "$rrd/temperature.rrd")
{
RRDs::create "$rrd/temperature.rrd",
"-s 60",
"DS:core1:GAUGE:600:-273:5000",
"DS:core2:GAUGE:600:-273:5000",
"DS:core3:GAUGE:600:-273:5000",
"DS:core4:GAUGE:600:-273:5000",
"DS:disk1:GAUGE:600:-273:5000",
"DS:disk2:GAUGE:600:-273:5000",
"DS:disk3:GAUGE:600:-273:5000",
"DS:disk4:GAUGE:600:-273:5000",
"RRA:AVERAGE:0.5:1:1200",
"RRA:MIN:0.5:12:2400",
"RRA:MAX:0.5:12:2400",
"RRA:AVERAGE:0.5:12:2400";
}
# insert values into rrd
RRDs::update "$rrd/temperature.rrd", "N:$c1:$c2:$c3:$c4:$d1:$d2:$d3:$d4";
if ($ERROR = RRDs::error) { print "$0: unable to update database: $ERROR\n"; }
# make graphs
RRDs::graph "Desktop/core.png",
"-t", "CPU Core Temperatures",
"-h", "200", "-w", "600",
"-a", "PNG",
"-e", "now",
"-x", "HOUR:1:DAY:1:HOUR:2:0:%H",
"-v", "Temperature",
"DEF:core1=$rrd/temperature.rrd:core1:AVERAGE",
"DEF:core2=$rrd/temperature.rrd:core2:AVERAGE",
"DEF:core3=$rrd/temperature.rrd:core3:AVERAGE",
"DEF:core4=$rrd/temperature.rrd:core4:AVERAGE",
"LINE1:core1#0000ff:Core 1",
"LINE1:core2#00aa00:Core 2",
"LINE1:core3#ff0000:Core 3",
"LINE1:core4#000000:Core 4";
#"GPRINT:core1:LAST:Core 1\: %2.1lfC",
#"GPRINT:core2:LAST:Core 2\: %2.1lfC",
#"GPRINT:core3:LAST:Core 3\: %2.1lfC",
#"GPRINT:core4:LAST:Core 4\: %2.1lfC";
if ($ERROR = RRDs::error) { print "$0: unable to generate graph: $ERROR\n"; }