chiark / gitweb /
different ranges
[rrd-graphs.git] / cgi
diff --git a/cgi b/cgi
index 998041a0d6aaf192b24a494f0bac4f9b222cbf49..85c2e5283537657217803c904f480f2a7974645c 100755 (executable)
--- a/cgi
+++ b/cgi
@@ -21,6 +21,9 @@ our (@sections, %sections, %graphs);
 sub graph ($$$$) {
     my ($section, $gname, $basis, $args) = @_;
     $basis->{Args}= $args;
+    $basis->{DefTimeRange} ||= 3600;
+    $basis->{MinTimeRange} ||= 3600;
+    $basis->{MaxTimeRange} ||= 28*86400;
     $graphs{$section,$gname}= $basis;
     if (!exists $sections{$section}) {
        push @sections, $section;
@@ -72,7 +75,11 @@ foreach my $src (<$R/df/df-*.rrd>) {
     $vol =~ s,.*/,,;
     $vol =~ s,^df-,,;
     $vol =~ s,\.rrd$,,;
-    graph('Disk space', $vol, { },
+    graph('Disk space', $vol, {
+            MinTimeRange => 86400,
+            MaxTimeRange => (13*7+1)*86400,
+            DefTimeRange => 7*86400
+          },
          [
           qw(-b 1024 -l 0),
           (map { "DEF:$_=$src:$_:AVERAGE" } qw(free used)),
@@ -134,9 +141,12 @@ sub start_page ($) {
 
 my $detail= param('detail');
 if ($detail) {
-    die unless $graphs{$section,$detail};
+    my $g= $graphs{$section,$detail};
+    die unless $g;
     start_page("$detail graphs");
-    foreach my $end (qw(3600 86400 604800 2419200)) {
+    foreach my $end (qw(300 3600 86400 604800 2419200 7948800)) {
+       next if $end < $g->{MinTimeRange};
+       next if $end > $g->{MaxTimeRange};
         print "<img src=\"$self?graph=$detail&section=$section&end=$end\">\n";
     }
     print end_html();
@@ -152,7 +162,8 @@ if (param('debug')) {
 start_page("$section graphs");
 
 foreach my $gname (@{ $sections{$section} }) {
+    my $g= $graphs{$section,$gname};
     print "<a href=\"$self?detail=$gname&section=$section\">"; #,h2($gname),"</a>";
-    print "<img src=\"$self?graph=$gname&section=$section\"></a>\n";
+    print "<img src=\"$self?graph=$gname&section=$section&end=$g->{DefTimeRange}\"></a>\n";
 }