]> git.sur5r.net Git - bacula/bacula/blobdiff - gui/bweb/cgi/bgraph.pl
bweb: Update some GPL2 notice to AGPL
[bacula/bacula] / gui / bweb / cgi / bgraph.pl
index bbf61e33fc39b3c1d22babe9f67f99a6759c97fe..7407322dba4a5c3925973299c55d9a6b020ac373 100755 (executable)
@@ -11,25 +11,24 @@ use strict;
    The main author of Bweb is Eric Bollengier.
    The main author of Bacula is Kern Sibbald, with contributions from
    many others, a complete list can be found in the file AUTHORS.
-
    This program is Free Software; you can redistribute it and/or
-   modify it under the terms of version two of the GNU General Public
-   License as published by the Free Software Foundation plus additions
-   that are listed in the file LICENSE.
+   modify it under the terms of version three of the GNU Affero General Public
+   License as published by the Free Software Foundation and included
+   in the file LICENSE.
 
    This program is distributed in the hope that it will be useful, but
    WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-   General Public License for more details.
+   Affero General Public License for more details.
 
-   You should have received a copy of the GNU General Public License
+   You should have received a copy of the GNU Affero General Public License
    along with this program; if not, write to the Free Software
    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
    02110-1301, USA.
 
-   Bacula® is a registered trademark of John Walker.
+   Bacula® is a registered trademark of Kern Sibbald.
    The licensor of Bacula is the Free Software Foundation Europe
-   (FSFE), Fiduciary Program, Sumatrastrasse 25, 8006 Zurich,
+   (FSFE), Fiduciary Program, Sumatrastrasse 25, 8006 Zürich,
    Switzerland, email:ftf@fsfeurope.org.
 
 =head1 VERSION
@@ -55,10 +54,10 @@ my $debug = $bweb->{debug};
 
 # Job table keep use Media or Job retention, so it's quite enought
 # for good statistics
-# CREATE TABLE job_old (LIKE Job);
-# INSERT INTO job_old
-#    (SELECT * FROM Job WHERE JobId NOT IN (SELECT JobId FROM job_old) );
-my $jobt = $conf->{stat_job_table} || 'Job';
+# CREATE TABLE JobHistory (LIKE Job);
+# INSERT INTO JobHistory
+#    (SELECT * FROM Job WHERE JobId NOT IN (SELECT JobId FROM JobHistory) );
+my $jobt = $bweb->get_stat_table();
 
 my $graph = CGI::param('graph') || 'job_size';
 my $legend = CGI::param('legend') || 'on' ;
@@ -70,17 +69,17 @@ my $arg = $bweb->get_form(qw/width height limit offset age where jobid
 my ($limitq, $label) = $bweb->get_limit(age   => $arg->{age},
                                        limit => $arg->{limit},
                                        offset=> $arg->{offset},
-                                       order => "$jobt.StartTime ASC",
+                                       order => "Job.StartTime ASC",
                                        );
 
 my $statusq='';
 if ($arg->{status} and $arg->{status} ne 'Any') {
-    $statusq = " AND $jobt.JobStatus = '$arg->{status}' ";
+    $statusq = " AND Job.JobStatus = '$arg->{status}' ";
 }
     
 my $levelq='';
-if ($arg->{level} and $arg->{level} ne 'Any') {
-    $levelq = " AND $jobt.Level = '$arg->{level}' ";
+if ($arg->{level} and $arg->{level} !~ 'All|Any') {
+    $levelq = " AND Job.Level = '$arg->{level}' ";
 } 
 
 my $filesetq='';
@@ -90,7 +89,7 @@ if ($arg->{jfilesets}) {
 
 my $jobnameq='';
 if ($arg->{jjobnames}) {
-    $jobnameq = " AND $jobt.Name IN ($arg->{jjobnames}) ";
+    $jobnameq = " AND Job.Name IN ($arg->{jjobnames}) ";
 } else {
     $arg->{jjobnames} = 'all'; # skip warning
 } 
@@ -103,7 +102,7 @@ if ($arg->{jclients}) {
 }
 
 my $groupf='';                 # from clause
-my $groupq='';                 # whre clause
+my $groupq='';                 # where clause
 if ($arg->{jclient_groups}) {
     $groupf = " JOIN client_group_member ON (Client.ClientId = client_group_member.clientid) 
                 JOIN client_group USING (client_group_id)";
@@ -121,14 +120,41 @@ if ($gtype eq 'balloon') {
     use Digest::MD5 qw(md5_hex);
     use GBalloon;
 
+    my $b = new GBalloon(width=>$arg->{width}, 
+                        height =>$arg->{height});
+
+    my $order;
+    my %legend = (x_title => 'Time', 
+                 x_func => sub { 
+                     POSIX::strftime('%H:%M', gmtime($_[0])) 
+                     }
+                 ) ;
+    if ($graph eq 'job_time_size') {
+       $order = 'JobFiles,JobBytes';
+
+       $legend{y_title} = 'Nb files';
+       $legend{y_func} = sub { int(shift)};
+       $legend{z_title} = 'Size';
+       $legend{z_func} = \&Bweb::human_size;
+    } else {
+       $order = 'JobBytes,JobFiles';
+
+       $legend{y_title} = 'Size';
+       $legend{y_func} = \&Bweb::human_size;
+       $legend{z_title} = 'Nb files';
+       $legend{z_func} = sub { int(shift)};
+    }
+
+    $b->set_legend_axis(%legend);
+
     my $all = $dbh->selectall_arrayref("
 SELECT $bweb->{sql}->{SEC_TO_INT}(  $bweb->{sql}->{UNIX_TIMESTAMP}(EndTime)
                                   - $bweb->{sql}->{UNIX_TIMESTAMP}(StartTime))
-         AS duration, JobBytes, JobFiles, JobId, $jobt.Name
+         AS duration, $order, JobId, Job.Name
        
- FROM $jobt, Client $filter $groupf
-WHERE $jobt.ClientId = Client.ClientId
-  AND $jobt.Type = 'B'
+ FROM $jobt AS Job, Client $filter $groupf
+WHERE Job.ClientId = Client.ClientId
+  AND Job.Type = 'B'
   $clientq
   $statusq
   $levelq
@@ -137,19 +163,10 @@ WHERE $jobt.ClientId = Client.ClientId
 $limitq
 ");
 
-    my $b = new GBalloon(width=>$arg->{width}, 
-                        height =>$arg->{height});
-    $b->set_legend_axis(x_title => 'Time', 
-                       x_func => sub { 
-                           POSIX::strftime('%H:%M', gmtime($_[0])) 
-                           },
-                       y_title => 'Size', y_func => \&Bweb::human_size,
-                       z_title => 'Nb files');
-
     foreach my $a (@$all) {
        $b->add_point($a->[0], $a->[1], $a->[2], 
                      "?action=job_zoom;jobid=$a->[3]",
-                     "$a->[4] $a->[2] files");
+                     "$a->[4] $legend{z_title} " . $legend{z_func}($a->[2]));
     }
     
     $b->init_gd();
@@ -173,6 +190,8 @@ sub get_graph
 {
     my (@options) = @_;
     my $graph;
+    use GD::Graph::colour qw(:colours);
+
     if ($gtype eq 'lines') {
        use GD::Graph::lines;
        $graph = GD::Graph::lines->new ( $arg->{width}, $arg->{height} );
@@ -196,10 +215,22 @@ sub get_graph
 
     $graph->set('x_label' => 'Time',
                'x_number_format' => sub { strftime('%D', localtime($_[0])) },
-               'x_tick_number' => 1,
+               'x_tick_number' => 5*$arg->{width}/800,
+                'overwrite' => 1,
+                dclrs => [ "lred", add_colour("#008e8e"), 
+                           add_colour("#afd8f8"), add_colour("#f6bd0f"),
+                           add_colour("#8bba00"), add_colour("#ff8e46"),
+                           add_colour("#d64646"),
+                           add_colour("#8e468e"), add_colour("#588526"),
+                           add_colour("#b3aa00"), add_colour("#008ed6"),
+                           add_colour("#9d080d"), add_colour("#a186be"),
+                ],
                @options,
                );
-
+    if ($conf->{graph_font} && -f $conf->{graph_font}) {
+        $graph->set_title_font([$conf->{graph_font}], 12);
+        $graph->set_legend_font([$conf->{graph_font}], 11);
+    }
     return $graph;
 }
 
@@ -215,6 +246,10 @@ sub make_tab
     foreach my $row (@$all_row) {
        my $label = $row->[1] . "/" . $row->[2] ; # client/backup name
 
+       if ($arg->{level} && $arg->{level} eq 'All') {  # can separate level
+           $label = $row->[4] . ': ' . $label;   # if users ask for
+       }
+
        $ret->{date}->[$i]   = $row->[0];       
        $ret->{$label}->[$i] = $row->[3];
        $i++;
@@ -256,14 +291,15 @@ if ($graph eq 'job_size') {
 
     my $query = "
 SELECT 
-       UNIX_TIMESTAMP($jobt.StartTime)  AS starttime,
-       Client.Name                      AS clientname,
-       $jobt.Name                       AS jobname,
-       $jobt.JobBytes                   AS jobbytes
-FROM $jobt, FileSet, Client $filter $groupf
-WHERE $jobt.ClientId = Client.ClientId
-  AND $jobt.FileSetId = FileSet.FileSetId
-  AND $jobt.Type = 'B'
+       UNIX_TIMESTAMP(Job.StartTime)  AS starttime,
+       Client.Name                    AS clientname,
+       Job.Name                       AS jobname,
+       Job.JobBytes                   AS jobbytes,
+       Job.Level                      AS joblevel
+FROM $jobt AS Job, FileSet, Client $filter $groupf
+WHERE Job.ClientId = Client.ClientId
+  AND Job.FileSetId = FileSet.FileSetId
+  AND Job.Type = 'B'
   $clientq
   $statusq
   $filesetq
@@ -294,14 +330,15 @@ if ($graph eq 'job_file') {
 
     my $query = "
 SELECT 
-       UNIX_TIMESTAMP($jobt.StartTime)  AS starttime,
-       Client.Name                      AS clientname,
-       $jobt.Name                       AS jobname,
-       $jobt.JobFiles                   AS jobfiles
-FROM $jobt, FileSet, Client $filter $groupf
-WHERE $jobt.ClientId = Client.ClientId
-  AND $jobt.FileSetId = FileSet.FileSetId
-  AND $jobt.Type = 'B'
+       UNIX_TIMESTAMP(Job.StartTime)  AS starttime,
+       Client.Name                    AS clientname,
+       Job.Name                       AS jobname,
+       Job.JobFiles                   AS jobfiles,
+       Job.Level                      AS joblevel
+FROM $jobt AS Job, FileSet, Client $filter $groupf
+WHERE Job.ClientId = Client.ClientId
+  AND Job.FileSetId = FileSet.FileSetId
+  AND Job.Type = 'B'
   $clientq
   $statusq
   $filesetq
@@ -328,7 +365,7 @@ $limitq
 }
 
 # it works only with postgresql at this time
-# we dont use $jobt because we use File, so job is in Job table
+# we don't use $jobt because we use File, so job is in Job table
 elsif ($graph eq 'file_histo' and $arg->{where}) {
     
     my $dir  = $dbh->quote(dirname($arg->{where}) . '/');
@@ -338,7 +375,8 @@ elsif ($graph eq 'file_histo' and $arg->{where}) {
 SELECT UNIX_TIMESTAMP(Job.StartTime)    AS starttime,
        Client.Name                      AS client,
        Job.Name                         AS jobname,
-       base64_decode_lstat(8,LStat)     AS lstat
+       base64_decode_lstat(8,LStat)     AS lstat,
+       Job.Level                        AS joblevel
 
 FROM Job, FileSet, Filename, Path, File, Client $filter
 WHERE Job.ClientId = Client.ClientId
@@ -388,7 +426,8 @@ elsif ($graph eq 'rep_histo' and $arg->{where}) {
 SELECT UNIX_TIMESTAMP(Job.StartTime) AS starttime,
        Client.Name                   AS client,
        Job.Name                      AS jobname,
-       brestore_pathvisibility.size  AS size
+       brestore_pathvisibility.size  AS size,
+       Job.Level                     AS joblevel
 
 FROM Job, Client $filter, FileSet, Path, brestore_pathvisibility
 WHERE Job.ClientId = Client.ClientId
@@ -428,19 +467,20 @@ elsif ($graph eq 'job_rate') {
 
     my $query = "
 SELECT 
-       UNIX_TIMESTAMP($jobt.StartTime)  AS starttime,
-       Client.Name                      AS clientname,
-       $jobt.Name                       AS jobname,
-       $jobt.JobBytes /
+       UNIX_TIMESTAMP(Job.StartTime)  AS starttime,
+       Client.Name                    AS clientname,
+       Job.Name                       AS jobname,
+       Job.JobBytes /
        ($bweb->{sql}->{SEC_TO_INT}(
                           $bweb->{sql}->{UNIX_TIMESTAMP}(EndTime)  
                         - $bweb->{sql}->{UNIX_TIMESTAMP}(StartTime)) + 0.01) 
-         AS rate
+         AS rate,
+       Job.Level                      AS joblevel
 
-FROM $jobt, FileSet, Client $filter $groupf
-WHERE $jobt.ClientId = Client.ClientId
-  AND $jobt.FileSetId = FileSet.FileSetId
-  AND $jobt.Type = 'B'
+FROM $jobt AS Job, FileSet, Client $filter $groupf
+WHERE Job.ClientId = Client.ClientId
+  AND Job.FileSetId = FileSet.FileSetId
+  AND Job.Type = 'B'
   $clientq
   $statusq
   $filesetq
@@ -473,16 +513,18 @@ elsif ($graph eq 'job_duration') {
 
     my $query = "
 SELECT 
-       UNIX_TIMESTAMP($jobt.StartTime)                         AS starttime,
-       Client.Name                                             AS clientname,
-       $jobt.Name                                              AS jobname,
+       UNIX_TIMESTAMP(Job.StartTime)       AS starttime,
+       Client.Name                         AS clientname,
+       Job.Name                            AS jobname,
   $bweb->{sql}->{SEC_TO_INT}(  $bweb->{sql}->{UNIX_TIMESTAMP}(EndTime)  
                              - $bweb->{sql}->{UNIX_TIMESTAMP}(StartTime)) 
-         AS duration
-FROM $jobt, FileSet, Client $filter $groupf
-WHERE $jobt.ClientId = Client.ClientId
-  AND $jobt.FileSetId = FileSet.FileSetId
-  AND $jobt.Type = 'B'
+         AS duration,
+       Job.Level                      AS joblevel
+
+FROM $jobt AS Job, FileSet, Client $filter $groupf
+WHERE Job.ClientId = Client.ClientId
+  AND Job.FileSetId = FileSet.FileSetId
+  AND Job.Type = 'B'
   $clientq
   $statusq
   $filesetq
@@ -534,16 +576,15 @@ $limitq
     }
     
     my $stime = $bweb->{sql}->{"STARTTIME_$d"};
-    $stime =~ s/Job\./$jobt\./;
 
     my $query = "
 SELECT
      " . ($per_t?"":"UNIX_TIMESTAMP") . "($stime) AS A,
      $t(JobBytes)                  AS nb
-FROM $jobt, FileSet, Client $filter $groupf
-WHERE $jobt.ClientId = Client.ClientId
-  AND $jobt.FileSetId = FileSet.FileSetId
-  AND $jobt.Type = 'B'
+FROM $jobt AS Job, FileSet, Client $filter $groupf
+WHERE Job.ClientId = Client.ClientId
+  AND Job.FileSetId = FileSet.FileSetId
+  AND Job.Type = 'B'
   $clientq
   $statusq
   $filesetq