Kod: Markera allt
#!/usr/bin/perl
use lib qw(/usr/local/rrdtool-1.2.27/lib/perl);
use RRDs;
use Time::localtime;
my $cur_time = time();
my $start_time = $cur_time - 86400; # set end time to 24 hours ago
$tm = localtime;
($DAY, $MONTH, $YEAR, $HOUR, $MINUTES, $SECONDS) = ($tm->mday, $tm->mon+1, $tm->year+1900, $tm->hour, $tm->min, $tm->sec);
$DAY = sprintf("%02d", $DAY);#%02d formats the string $DAY to always contain 2 digits.
$MONTH = sprintf("%02d", $MONTH);
$YEAR = sprintf("%04d", $YEAR);#%02d formats the string $YEAR to always contain 4 digits.
$HOUR = sprintf("%02d", $HOUR);
$MINUTES = sprintf("%02d", $MINUTES);
$SECONDS = sprintf("%02d", $SECONDS);
$now = $YEAR."-".$MONTH."-".$DAY." kl ".$HOUR."\\:".$MINUTES;
RRDs::graph "/var/www/hemkoll.nu/graph_temp.png",
"--start= $start_time",
"--end= $cur_time",
"--title= Temp ute/inne",
"--height= 400",
"--width= 1000",
"--vertical-label= °C",
"DEF:temp0=/home/niklas/rrd/RRD_DB/temp0.rrd:temp:AVERAGE",
"DEF:temp1=/home/niklas/rrd/RRD_DB/temp1.rrd:temp:AVERAGE",
"DEF:temp2=/home/niklas/rrd/RRD_DB/temp2.rrd:temp:AVERAGE",
"DEF:temp3=/home/niklas/rrd/RRD_DB/temp3.rrd:temp:AVERAGE",
"DEF:temp4=/home/niklas/rrd/RRD_DB/temp4.rrd:temp:AVERAGE",
"DEF:temp5=/home/niklas/rrd/RRD_DB/temp5.rrd:temp:AVERAGE",
#"DEF:energi=/home/niklas/rrd/energi.rrd:energi:AVERAGE",
#"COMMENT:\t\t\t\tNu Med Max Min\\n",
"LINE2:temp0#000000:Serverrum ",
"GPRINT:temp0:LAST:Senast\\:%6.1lf\x{00B0}C",
"GPRINT:temp0:MIN:Min\\:%6.1lf\x{00B0}C",
"GPRINT:temp0:AVERAGE:Med\\:%6.1lf\x{00B0}C",
"GPRINT:temp0:MAX:Max\\:%6.1lf\x{00B0}C",
"HRULE:0#0000FF",
"LINE2:temp1#FF0000:Ute\t",
"GPRINT:temp1:LAST:Senast\\:%6.1lf\x{00B0}C",
"GPRINT:temp1:MIN:Min\\:%6.1lf\x{00B0}C",
"GPRINT:temp1:AVERAGE:Med\\:%6.1lf\x{00B0}C",
"GPRINT:temp1:MAX:Max\\:%6.1lf\x{00B0}C\\n",
"LINE2:temp2#00FF00:Kylskåp ",
"GPRINT:temp2:LAST:Senast\\:%6.1lf\x{00B0}C",
"GPRINT:temp2:MIN:Min\\:%6.1lf\x{00B0}C",
"GPRINT:temp2:AVERAGE:Med\\:%6.1lf\x{00B0}C",
"GPRINT:temp2:MAX:Max\\:%6.1lf\x{00B0}C",
"LINE2:temp3#0000FF:Kök\t",
"GPRINT:temp3:LAST:Senast\\:%6.1lf\x{00B0}C",
"GPRINT:temp3:MIN:Min\\:%6.1lf\x{00B0}C",
"GPRINT:temp3:AVERAGE:Med\\:%6.1lf\x{00B0}C",
"GPRINT:temp3:MAX:Max\\:%6.1lf\x{00B0}C\\n",
"LINE2:temp4#C0C0C0:Vardagsrum",
"GPRINT:temp4:LAST:Senast\\:%6.1lf\x{00B0}C",
"GPRINT:temp4:MIN:Min\\:%6.1lf\x{00B0}C",
"GPRINT:temp4:AVERAGE:Med\\:%6.1lf\x{00B0}C",
"GPRINT:temp4:MAX:Max\\:%6.1lf\x{00B0}C",
"LINE2:temp5#FF00FF:Sov\t",
"GPRINT:temp5:LAST:Senast\\:%6.1lf\x{00B0}C",
"GPRINT:temp5:MIN:Min\\:%6.1lf\x{00B0}C",
"GPRINT:temp5:AVERAGE:Med\\:%6.1lf\x{00B0}C",
"GPRINT:temp5:MAX:Max\\:%6.1lf\x{00B0}C\\n",
"COMMENT:Data hämtad $now";
my $err=RRDs::error;
if ($err) {print "problem generating the graph: $err\n";}