Kod: Markera allt
#!/usr/bin/perl
use RRDs;
my $path_24h = "/var/www/ha/graphs/temp_day.png";
my $path_week = "/var/www/ha/graphs/temp_week.png";
my $path_month = "/var/www/ha/graphs/temp_month.png";
my $path_year = "/var/www/ha/graphs/temp_year.png";
my $path_10y = "/var/www/ha/graphs/temp_10y.png";
my $rrd_garage = "/var/ha/rrddata/garage_outside_temp.rrd";
my $rrd_storage = "/var/ha/rrddata/garage_inside_temp.rrd";
my $rrd_grund = "/var/ha/rrddata/basement_temp.rrd";
my $rrd_playroom = "/var/ha/rrddata/playroom_temp.rrd";
my $time_curr = time();
my $time_day = $time_curr - 86400; # set end time to 24 hours ago
my $time_week = $time_curr - 604800; # 1 week ago
my $time_month = $time_curr - 2419200; # 1 month ago
my $time_year = $time_curr - 29030400; # 1 year ago
my $time_10y = $time_curr - 290304000; # 10 years ago
////////////////////////////////////////////////////////////////////////
generate_graph ($path_24h, $time_curr, $time_day);
generate_graph ($path_24h, $time_curr, $time_day);
generate_graph ($path_week, $time_curr, $time_week);
generate_graph ($path_month, $time_curr, $time_month);
generate_graph ($path_year, $time_curr, $time_year);
generate_graph ($path_10y, $time_curr, $time_10y);
sub generate_graph
{
my $path = shift; # Path to the generated graph
my $time_end = shift; # End time
my $time_start = shift; # Start time
RRDs::graph "$path",
"--start= $time_start",
"--end= $time_end",
"--title= Temperaturer",
"--height= 300",
"--width= 500",
"--vertical-label= °C",
"-E",
"DEF:Garage=$rrd_garage:garage_outside_temp:AVERAGE",
"COMMENT:\t\t\t\t\tNu Medel Max Min\\n",
"HRULE:0#00FF00",
"LINE2:Garage#00FF00:Garage, utomhus\t\t",
"GPRINT:Garage:LAST:%6.1lf",
"GPRINT:Garage:AVERAGE:%6.1lf",
"GPRINT:Garage:MAX:%6.1lf",
"GPRINT:Garage:MIN:%6.1lf\\n",
"DEF:Storage=$rrd_storage:garage_inside_temp:AVERAGE",
"HRULE:0#0000FF",
"LINE2:Storage#0000FF:Forradet\t\t\t",
"GPRINT:Storage:LAST:%6.1lf",
"GPRINT:Storage:AVERAGE:%6.1lf",
"GPRINT:Storage:MAX:%6.1lf",
"GPRINT:Storage:MIN:%6.1lf\\n",
"DEF:Playroom=$rrd_playroom:playroom_temp:AVERAGE",
"HRULE:0#0F0F0F",
"LINE2:Playroom#0F0F0F:Lekrummet\t\t\t",
"GPRINT:Playroom:LAST:%6.1lf",
"GPRINT:Playroom:AVERAGE:%6.1lf",
"GPRINT:Playroom:MAX:%6.1lf",
"GPRINT:Playroom:MIN:%6.1lf\\n",
"DEF:BasementTemp=$rrd_grund:basement_temp:AVERAGE",
"HRULE:0#FF0000",
"LINE1:BasementTemp#FF0000:Krypgrund\t\t\t",
"GPRINT:BasementTemp:LAST:%6.1lf",
"GPRINT:BasementTemp:AVERAGE:%6.1lf",
"GPRINT:BasementTemp:MAX:%6.1lf",
"GPRINT:BasementTemp:MIN:%6.1lf\\n";
my $err=RRDs::error;
if ($err) {print "problem generating the graph: $err\n";}
}
Kod: Markera allt
RRDs::graph "/var/www/graph_temp.png",
"--start= $start_time",
"--end= $cur_time",
"--title= Temp ute",
"--height= 300",
"--width= 500",
"--vertical-label= °C",
"DEF:OutsideTemp=/home/anders/rrddata/outside_temp.rrd:outsidetemp:AVERAGE",
"COMMENT:\t\t\t\tNu Medel Max Min\\n",
"HRULE:0#0000FF",
"LINE2:OutsideTemp#0000FF:Ute\t\t\t",
"GPRINT:OutsideTemp:LAST:%6.1lf",
"GPRINT:OutsideTemp:AVERAGE:%6.1lf",
"GPRINT:OutsideTemp:MAX:%6.1lf",
"GPRINT:OutsideTemp:MIN:%6.1lf\\n";
Kod: Markera allt
RRDs::graph "/var/www/graph_temp.png",
"--start= $start_time",
"--end= $cur_time",
"--title= Temp ute",
"--height= 300",
"--width= 500",
"--vertical-label= °C",
"DEF:OutsideTemp=/home/anders/rrddata/outside_temp.rrd:outsidetemp:AVERAGE",
"DEF:InsideTemp=/home/anders/rrddata/inside_temp.rrd:insidetemp:AVERAGE",
"COMMENT:\t\t\t\tNu Medel Max Min\\n",
"HRULE:0#0000FF",
"LINE2:OutsideTemp#0000FF:Ute\t\t\t",
"GPRINT:OutsideTemp:LAST:%6.1lf",
"GPRINT:OutsideTemp:AVERAGE:%6.1lf",
"GPRINT:OutsideTemp:MAX:%6.1lf",
"GPRINT:OutsideTemp:MIN:%6.1lf ,
"LINE2:InsideTemp#FF00FF:Ute\t\t\t",
"GPRINT:InsideTemp:LAST:%6.1lf",
"GPRINT:InsideTemp:AVERAGE:%6.1lf",
"GPRINT:InsideTemp:MAX:%6.1lf",
"GPRINT:InsideTemp:MIN:%6.1lf\\n";