chiark / gitweb /
central timeranges
authorIan Jackson <ijackson@chiark.greenend.org.uk>
Sat, 26 Jun 2010 14:40:31 +0000 (15:40 +0100)
committerIan Jackson <ijackson@chiark.greenend.org.uk>
Sat, 26 Jun 2010 14:40:31 +0000 (15:40 +0100)
cgi

diff --git a/cgi b/cgi
index 85c2e5283537657217803c904f480f2a7974645c..3c0e124df4dffdba101d6a8b3c066f77d2c3f926 100755 (executable)
--- a/cgi
+++ b/cgi
@@ -18,12 +18,12 @@ my $self= url(-relative=>1);
 
 our (@sections, %sections, %graphs);
 
+our @timeranges= (3600, map { $_*86400 } qw(1 7 28), 13*7+1);
+
 sub graph ($$$$) {
     my ($section, $gname, $basis, $args) = @_;
     $basis->{Args}= $args;
-    $basis->{DefTimeRange} ||= 3600;
-    $basis->{MinTimeRange} ||= 3600;
-    $basis->{MaxTimeRange} ||= 28*86400;
+    $basis->{Slower}= 0 unless exists $basis->{Slower};
     $graphs{$section,$gname}= $basis;
     if (!exists $sections{$section}) {
        push @sections, $section;
@@ -76,9 +76,7 @@ foreach my $src (<$R/df/df-*.rrd>) {
     $vol =~ s,^df-,,;
     $vol =~ s,\.rrd$,,;
     graph('Disk space', $vol, {
-            MinTimeRange => 86400,
-            MaxTimeRange => (13*7+1)*86400,
-            DefTimeRange => 7*86400
+            Slower => 1,
           },
          [
           qw(-b 1024 -l 0),
@@ -144,9 +142,7 @@ if ($detail) {
     my $g= $graphs{$section,$detail};
     die unless $g;
     start_page("$detail graphs");
-    foreach my $end (qw(300 3600 86400 604800 2419200 7948800)) {
-       next if $end < $g->{MinTimeRange};
-       next if $end > $g->{MaxTimeRange};
+    foreach my $end (@timeranges[$g->{Slower}..$g->{Slower}+3]) {
         print "<img src=\"$self?graph=$detail&section=$section&end=$end\">\n";
     }
     print end_html();
@@ -163,7 +159,9 @@ 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&end=$g->{DefTimeRange}\"></a>\n";
+    print "<a href=\"$self?detail=$gname&section=$section\">";
+    my $end= $timeranges[$g->{Slower}+1];
+    my $imgurl= "$self?graph=$gname&section=$section&end=$end";
+    print "<img src=\"$imgurl\"></a>\n";
 }