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') || 'job_size';
45 my $legend = CGI::param('legend') || 'on' ;
46 $legend = ($legend eq 'on')?1:0;
48 my $arg = $bweb->get_form(qw/width height limit offset age
49 jfilesets level status jjobnames jclients/);
51 my ($limitq, $label) = $bweb->get_limit(age => $arg->{age},
52 limit => $arg->{limit},
53 offset=> $arg->{offset},
54 order => 'Job.StartTime ASC',
58 if ($arg->{status} and $arg->{status} ne 'Any') {
59 $statusq = " AND Job.JobStatus = '$arg->{status}' ";
63 if ($arg->{level} and $arg->{level} ne 'Any') {
64 $levelq = " AND Job.Level = '$arg->{level}' ";
68 if ($arg->{jfilesets}) {
69 $filesetq = " AND FileSet.FileSet IN ($arg->{qfilesets}) ";
73 if ($arg->{jjobnames}) {
74 $jobnameq = " AND Job.Name IN ($arg->{jjobnames}) ";
76 $arg->{jjobnames} = 'all'; # skip warning
80 if ($arg->{jclients}) {
81 $clientq = " AND Client.Name IN ($arg->{jclients}) ";
83 $arg->{jclients} = 'all'; # skip warning
86 my $gtype = CGI::param('gtype') || 'bars';
88 print CGI::header('image/png');
94 if ($gtype eq 'lines') {
96 $graph = GD::Graph::lines->new ( $arg->{width}, $arg->{height} );
98 } elsif ($gtype eq 'bars') {
100 $graph = GD::Graph::bars->new ( $arg->{width}, $arg->{height} );
102 } elsif ($gtype eq 'linespoints') {
103 use GD::Graph::linespoints;
104 $graph = GD::Graph::linespoints->new ( $arg->{width}, $arg->{height} );
106 } elsif ($gtype eq 'bars3d') {
107 use GD::Graph::bars3d;
108 $graph = GD::Graph::bars3d->new ( $arg->{width}, $arg->{height} );
114 $graph->set('x_label' => 'Time',
115 'x_number_format' => sub { strftime('%D', localtime($_[0])) },
116 'x_tick_number' => 1,
132 foreach my $row (@$all_row) {
133 my $label = $row->[1] . "/" . $row->[2] ; # client/backup name
135 $ret->{date}->[$i] = $row->[0];
136 $ret->{$label}->[$i] = $row->[3];
138 $last_date = $row->[0];
141 # insert a fake element
142 foreach my $elt ( keys %{$ret}) {
143 $ret->{$elt}->[$i] = undef;
146 $ret->{date}->[$i] = $last_date + 1;
148 my $date = $ret->{date} ;
151 return ($date, $ret);
154 if ($graph eq 'job_size') {
158 UNIX_TIMESTAMP(Job.StartTime) AS starttime,
159 Client.Name AS clientname,
161 Job.JobBytes AS jobbytes
162 FROM Job, Client, FileSet
163 WHERE Job.ClientId = Client.ClientId
164 AND Job.FileSetId = FileSet.FileSetId
174 print STDERR $query if ($debug);
176 my $obj = get_graph('title' => "Job Size : $arg->{jclients}/$arg->{jjobnames}",
179 'y_number_format' => \&Bweb::human_size,
182 my $all = $dbh->selectall_arrayref($query) ;
184 my ($d, $ret) = make_tab($all);
186 $obj->set_legend(keys %$ret);
188 print $obj->plot([$d, values %$ret])->png;
191 if ($graph eq 'job_file') {
195 UNIX_TIMESTAMP(Job.StartTime) AS starttime,
196 Client.Name AS clientname,
198 Job.JobFiles AS jobfiles
199 FROM Job, Client, FileSet
200 WHERE Job.ClientId = Client.ClientId
201 AND Job.FileSetId = FileSet.FileSetId
211 print STDERR $query if ($debug);
213 my $obj = get_graph('title' => "Job Files : $arg->{jclients}/$arg->{jjobnames}",
214 'y_label' => 'Number Files',
218 my $all = $dbh->selectall_arrayref($query) ;
220 my ($d, $ret) = make_tab($all);
222 $obj->set_legend(keys %$ret);
224 print $obj->plot([$d, values %$ret])->png;
227 elsif ($graph eq 'job_rate') {
231 UNIX_TIMESTAMP(Job.StartTime) AS starttime,
232 Client.Name AS clientname,
235 ($bweb->{sql}->{SEC_TO_INT}(
236 $bweb->{sql}->{UNIX_TIMESTAMP}(EndTime)
237 - $bweb->{sql}->{UNIX_TIMESTAMP}(StartTime)) + 0.01)
240 FROM Job, Client, FileSet
241 WHERE Job.ClientId = Client.ClientId
242 AND Job.FileSetId = FileSet.FileSetId
252 print STDERR $query if ($debug);
254 my $obj = get_graph('title' => "Job Rate : $arg->{jclients}/$arg->{jjobnames}",
255 'y_label' => 'Rate b/s',
257 'y_number_format' => \&Bweb::human_size,
260 my $all = $dbh->selectall_arrayref($query) ;
262 my ($d, $ret) = make_tab($all);
264 $obj->set_legend(keys %$ret);
266 print $obj->plot([$d, values %$ret])->png;
271 elsif ($graph eq 'job_duration') {
275 UNIX_TIMESTAMP(Job.StartTime) AS starttime,
276 Client.Name AS clientname,
278 $bweb->{sql}->{SEC_TO_INT}( $bweb->{sql}->{UNIX_TIMESTAMP}(EndTime)
279 - $bweb->{sql}->{UNIX_TIMESTAMP}(StartTime))
281 FROM Job, Client, FileSet
282 WHERE Job.ClientId = Client.ClientId
283 AND Job.FileSetId = FileSet.FileSetId
293 print STDERR $query if ($debug);
295 my $obj = get_graph('title' => "Job Duration : $arg->{jclients}/$arg->{jjobnames}",
296 'y_label' => 'Duration',
298 'y_number_format' => \&Bweb::human_sec,
300 my $all = $dbh->selectall_arrayref($query) ;
302 my ($d, $ret) = make_tab($all);
304 $obj->set_legend(keys %$ret);
306 print $obj->plot([$d, values %$ret])->png;