6 Copyright (C) 2006 Eric Bollengier
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 2 of the License, or
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
19 You should have received a copy of the GNU General Public License
20 along with this program; if not, write to the Free Software
21 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
34 use POSIX qw/strftime/;
36 my $conf = new Bweb::Config(config_file => '/etc/bweb/config');
39 my $bweb = new Bweb(info => $conf);
41 my $dbh = $bweb->{dbh};
42 my $debug = $bweb->{debug};
44 my $graph = CGI::param('graph') || 'begin';
46 my $arg = $bweb->get_form(qw/width height limit offset age
47 jfilesets level status jjobnames jclients/);
49 my ($limitq, $label) = $bweb->get_limit(age => $arg->{age},
50 limit => $arg->{limit},
51 offset=> $arg->{offset},
52 order => 'Job.StartTime ASC',
56 if ($arg->{status} and $arg->{status} ne 'Any') {
57 $statusq = " AND Job.JobStatus = '$arg->{status}' ";
61 if ($arg->{level} and $arg->{level} ne 'Any') {
62 $levelq = " AND Job.Level = '$arg->{level}' ";
66 if ($arg->{jfilesets}) {
67 $filesetq = " AND FileSet.FileSet IN ($arg->{qfilesets}) ";
71 if ($arg->{jjobnames}) {
72 $jobnameq = " AND Job.Name IN ($arg->{jjobnames}) ";
74 $arg->{jjobnames} = 'all'; # skip warning
78 if ($arg->{jclients}) {
79 $clientq = " AND Client.Name IN ($arg->{jclients}) ";
81 $arg->{jclients} = 'all'; # skip warning
84 my $gtype = CGI::param('gtype') || 'bars';
86 print CGI::header('image/png');
92 if ($gtype eq 'lines') {
94 $graph = GD::Graph::lines->new ( $arg->{width}, $arg->{height} );
96 } elsif ($gtype eq 'bars') {
98 $graph = GD::Graph::bars->new ( $arg->{width}, $arg->{height} );
100 } elsif ($gtype eq 'linespoints') {
101 use GD::Graph::linespoints;
102 $graph = GD::Graph::linespoints->new ( $arg->{width}, $arg->{height} );
104 } elsif ($gtype eq 'bars3d') {
105 use GD::Graph::bars3d;
106 $graph = GD::Graph::bars3d->new ( $arg->{width}, $arg->{height} );
112 $graph->set('x_label' => 'Time',
113 'x_number_format' => sub { strftime('%D', localtime($_[0])) },
114 'x_tick_number' => 1,
130 foreach my $row (@$all_row) {
131 my $label = $row->[1] . "/" . $row->[2] ; # client/backup name
133 $ret->{date}->[$i] = $row->[0];
134 $ret->{$label}->[$i] = $row->[3];
136 $last_date = $row->[0];
139 # insert a fake element
140 foreach my $elt ( keys %{$ret}) {
141 $ret->{$elt}->[$i] = undef;
144 $ret->{date}->[$i] = $last_date + 1;
146 my $date = $ret->{date} ;
149 return ($date, $ret);
152 if ($graph eq 'job_size') {
156 UNIX_TIMESTAMP(Job.StartTime) AS starttime,
157 Client.Name AS clientname,
159 Job.JobBytes AS jobbytes
160 FROM Job, Client, FileSet
161 WHERE Job.ClientId = Client.ClientId
162 AND Job.FileSetId = FileSet.FileSetId
172 print STDERR $query if ($debug);
174 my $obj = get_graph('title' => "Job Size : $arg->{jclients}/$arg->{jjobnames}",
177 'y_number_format' => \&Bweb::human_size,
180 my $all = $dbh->selectall_arrayref($query) ;
182 my ($d, $ret) = make_tab($all);
183 $obj->set_legend(keys %$ret);
184 print $obj->plot([$d, values %$ret])->png;
187 if ($graph eq 'job_file') {
191 UNIX_TIMESTAMP(Job.StartTime) AS starttime,
192 Client.Name AS clientname,
194 Job.JobFiles AS jobfiles
195 FROM Job, Client, FileSet
196 WHERE Job.ClientId = Client.ClientId
197 AND Job.FileSetId = FileSet.FileSetId
207 print STDERR $query if ($debug);
209 my $obj = get_graph('title' => "Job Files : $arg->{jclients}/$arg->{jjobnames}",
210 'y_label' => 'Number Files',
214 my $all = $dbh->selectall_arrayref($query) ;
216 my ($d, $ret) = make_tab($all);
217 $obj->set_legend(keys %$ret);
218 print $obj->plot([$d, values %$ret])->png;
221 elsif ($graph eq 'job_rate') {
225 UNIX_TIMESTAMP(Job.StartTime) AS starttime,
226 Client.Name AS clientname,
229 ($bweb->{sql}->{SEC_TO_INT}(
230 $bweb->{sql}->{UNIX_TIMESTAMP}(EndTime)
231 - $bweb->{sql}->{UNIX_TIMESTAMP}(StartTime)) + 0.01)
234 FROM Job, Client, FileSet
235 WHERE Job.ClientId = Client.ClientId
236 AND Job.FileSetId = FileSet.FileSetId
246 print STDERR $query if ($debug);
248 my $obj = get_graph('title' => "Job Rate : $arg->{jclients}/$arg->{jjobnames}",
249 'y_label' => 'Rate b/s',
251 'y_number_format' => \&Bweb::human_size,
254 my $all = $dbh->selectall_arrayref($query) ;
256 my ($d, $ret) = make_tab($all);
257 $obj->set_legend(keys %$ret);
258 print $obj->plot([$d, values %$ret])->png;
263 elsif ($graph eq 'job_duration') {
267 UNIX_TIMESTAMP(Job.StartTime) AS starttime,
268 Client.Name AS clientname,
270 $bweb->{sql}->{SEC_TO_INT}( $bweb->{sql}->{UNIX_TIMESTAMP}(EndTime)
271 - $bweb->{sql}->{UNIX_TIMESTAMP}(StartTime))
273 FROM Job, Client, FileSet
274 WHERE Job.ClientId = Client.ClientId
275 AND Job.FileSetId = FileSet.FileSetId
285 print STDERR $query if ($debug);
287 my $obj = get_graph('title' => "Job Duration : $arg->{jclients}/$arg->{jjobnames}",
288 'y_label' => 'Duration',
290 'y_number_format' => \&Bweb::human_sec,
292 my $all = $dbh->selectall_arrayref($query) ;
294 my ($d, $ret) = make_tab($all);
295 $obj->set_legend(keys %$ret);
296 print $obj->plot([$d, values %$ret])->png;