return \@args;
}
+sub cfgToGraphDef {
+ my $cfg = shift;
+ my $varname = shift;
+ my $dpPerDay= shift;
+ my @graphDef = ();
+ foreach my $subGraph (@$cfg) {
+ if ($subGraph eq 'avg') {
+ push @graphDef, "LINE1:${varname}-avg#FF0000";
+ } elsif ($subGraph eq 'day-min') {
+ push @graphDef, @{dayGraphFunc("${varname}-min", 'MIN', '0000ff', 'Day Minimum Temperature', $dpPerDay)};
+ } elsif ($subGraph eq 'day-max') {
+ push @graphDef, @{dayGraphFunc("${varname}-max", 'MAX', '00ff00', 'Day Maximum Temperature', $dpPerDay)};
+ }
+ }
+ return \@graphDef;
+}
+
if ($> == 0) {
if (@ARGV != 2) {
print STDERR "Running as root, please provide UID as 2th argument!\n";
}
foreach my $var (@{$host->{'fields'}}) {
- my @graphdef = ('-P', "--lazy", "-t", $hostname." - ".$vars->{$var}->{'name'}, "DEF:${var}=${rrdfile}.${var}:${var}:AVERAGE", "LINE1:${var}#FF0000");
-
- push @graphdef, "DEF:${var}-min=${rrdfile}.${var}:${var}:MIN", "LINE1:${var}-min#0000FF";
- push @graphdef, "DEF:${var}-max=${rrdfile}.${var}:${var}:MAX", "LINE1:${var}-max#00FF00";
- push @graphdef, "VDEF:cur=${var},LAST";
+ my $graphWidth = 365 * 3;
+ my $graphConfig;
+ if (defined $vars->{$var}->{'graph'}) {
+ $graphConfig = $vars->{$var}->{'graph'};
+ foreach my $subGraph (qw(day week year)) {
+ if (!defined($graphConfig->{$subGraph})) {
+ $graphConfig->{$subGraph} = [ 'avg'];
+ }
+ }
+ } else {
+ $graphConfig = {
+ 'day' => [ 'avg' ],
+ 'week' => [ 'avg' ],
+ 'year' => [ 'avg' ],
+ };
+ }
+
+ my @graphdef = ('-P', "--lazy", "-t", $hostname." - ".$vars->{$var}->{'name'});
+
+ push @graphdef, "DEF:${var}-avg=${rrdfile}.${var}:${var}:AVERAGE";
+ push @graphdef, "DEF:${var}-min=${rrdfile}.${var}:${var}:MIN";
+ push @graphdef, "DEF:${var}-max=${rrdfile}.${var}:${var}:MAX";
+ push @graphdef, "LINE1:${var}-avg#FF0000";
+ push @graphdef, "VDEF:cur=${var}-avg,LAST";
push @graphdef, 'GPRINT:cur:Current\\: <span foreground="#FF0000">%.2lf</span>\\r';
my $mtime;
pop @graphdef;
pop @graphdef;
+ pop @graphdef;
if ($rrd_result) {
print "Error while graphing: " . $rrd_result . "\n";
push @graphdef, "VDEF:min=${var}-min,MINIMUM";
push @graphdef, "GPRINT:min:Minimum\\: %.2lf";
- push @graphdef, "VDEF:avg=${var},AVERAGE";
+ push @graphdef, "VDEF:avg=${var}-avg,AVERAGE";
push @graphdef, "GPRINT:avg:Average\\: %.2lf";
push @graphdef, "VDEF:max=${var}-max,MAXIMUM";
push @graphdef, "GPRINT:max:Maximum\\: %.2lf";
- push @graphdef, "VDEF:cur=${var},LAST";
+ push @graphdef, "VDEF:cur=${var}-avg,LAST";
push @graphdef, "GPRINT:cur:Current\\: %.2lf";
+ my @dayGraphDef = @graphdef;
+ push @dayGraphDef, @{cfgToGraphDef($graphConfig->{'day'}, ${var}, 24)};
+
$mtime=(stat("${outdir}/${hostname}.${var}.long.png.work"))[9];
($averages, $width, $height) =
rrd_graph("${outdir}/${hostname}.${var}.long.png.work",
- "-w", "1008", @graphdef);
+ "-w", $graphWidth, @dayGraphDef);
if ($rrd_result) {
print "Error while graphing: " . $rrd_result . "\n";
print HTML2 "<img src=\"${hostname}.${var}.long.png\" width=\"${width}\" height=\"${height}\"><br>\n";
$mtime=(stat("${outdir}/${hostname}.${var}.week.png.work"))[9];
+
+ my @weekGraphDef = @graphdef;
+ push @weekGraphDef, @{cfgToGraphDef($graphConfig->{'week'}, ${var}, 24)};
+
($averages, $width, $height) =
rrd_graph("${outdir}/${hostname}.${var}.week.png.work",
- "-w", "1008", "-e", "now", "-s", "end-1w", @graphdef);
+ "-w", "$graphWidth", "-e", "now", "-s", "00:00-8d", @weekGraphDef);
if ($rrd_result) {
print "Error while graphing: " . $rrd_result . "\n";
print HTML2 "<img src=\"${hostname}.${var}.week.png\" width=\"${width}\" height=\"${height}\"><br>\n";
$mtime=(stat("${outdir}/${hostname}.${var}.year.png.work"))[9];
+
+ my @yearGraphDef = @graphdef;
+ push @yearGraphDef, @{cfgToGraphDef($graphConfig->{'year'}, ${var}, 3)};
+
($averages, $width, $height) =
rrd_graph("${outdir}/${hostname}.${var}.year.png.work",
- "-w", "1008", "-e", "now", "-s", "end-1y", @graphdef);
+ "-w", "$graphWidth", "-e", "00:00", "-s", "end-365d", @yearGraphDef);
if ($rrd_result) {
print "Error while graphing: " . $rrd_result . "\n";