Add total upload/download to network usage graph master
authorQuentin Smith <quentin@mit.edu>
Thu, 16 Jan 2020 04:05:38 +0000 (23:05 -0500)
committerroot <root@christmas-tree.mit.edu>
Thu, 16 Jan 2020 04:05:38 +0000 (23:05 -0500)
web/usage.cgi

index fe32b46..92ea122 100755 (executable)
@@ -29,12 +29,12 @@ our %graph_types =
     args => ["--title", "Domain network usage",
             qw(
                 --base 1000
     args => ["--title", "Domain network usage",
             qw(
                 --base 1000
-                --vertical-label), "bits in (-) / out (+) per ${graph_period}",
+                --vertical-label), "bits in (-) / out (+) per second",
            ],
            ],
-    cdef => "8,*",
     draw => "LINE",
     draw => "LINE",
-    sub_types => [{suffix => "_up", cdef => "8,*"},
-                 {suffix => "_down", cdef => "-8,*"},
+    total_unit => "B",
+    sub_types => [{suffix => "_up", cdef => "8,*", total_name => "Total upload"},
+                 {suffix => "_down", cdef => "-8,*", total_name => "Total download"},
                 ]
    },
                   );
                 ]
    },
                   );
@@ -98,10 +98,15 @@ foreach my $sub_type (@sub_types) {
     $files[$i] =~ m|^([^:]+)$|;
     my $data = "data$suffix$i";
     push @args, "DEF:o$data=$1:42:AVERAGE";
     $files[$i] =~ m|^([^:]+)$|;
     my $data = "data$suffix$i";
     push @args, "DEF:o$data=$1:42:AVERAGE";
-    push @args, "CDEF:$data=o$data,UN,0,o$data,IF".($cdef ? ",$cdef" : "");
+    push @args, "CDEF:$data=o$data,UN,0,o$data,IF";
   }
   push @args, "CDEF:total$suffix=0,".join(",+,", map {"data$suffix$_"} 0..$#files).",+";
   }
   push @args, "CDEF:total$suffix=0,".join(",+,", map {"data$suffix$_"} 0..$#files).",+";
-  push @args, "$type{draw}:total$suffix#0000FF";
+  push @args, "CDEF:graph$suffix=total$suffix".($cdef ? ",$cdef" : "");
+  push @args, "$type{draw}:graph$suffix#0000FF";
+  if (my $total_name = $sub_type->{"total_name"}) {
+    push @args, "VDEF:t$suffix=total$suffix,TOTAL";
+    push @args, "GPRINT:t$suffix:$total_name %6.2lf %S".$type{"total_unit"};
+  }
 }
 
 $ENV{"PATH"} = "/usr/local/bin:/usr/bin:/bin";
 }
 
 $ENV{"PATH"} = "/usr/local/bin:/usr/bin:/bin";