10 |
|
|
11 |
my $debug = 0; |
my $debug = 0; |
12 |
|
|
13 |
|
# comment out following field if you don't want links to omni reports |
14 |
|
# or haven't installed repgen.pl |
15 |
|
my $repgen_url="/omni/"; # URL to pages with rptgen.pl |
16 |
|
|
17 |
my $width = 600; # width of bar |
my $width = 600; # width of bar |
18 |
my $height = 15; # height of bar |
my $height = 15; # height of bar |
19 |
my $use_js = 1; # use JavaScript pop-up |
my $use_js = 1; # use JavaScript pop-up |
24 |
'In Progress/Failures' => '192,64,192', |
'In Progress/Failures' => '192,64,192', |
25 |
'In Progress/Errors' => '255,128,128', |
'In Progress/Errors' => '255,128,128', |
26 |
'Queuing' => '255,255,0', |
'Queuing' => '255,255,0', |
27 |
|
'Queuing/Errors' => '255,192,64', |
28 |
'Aborted' => '255,0,0', |
'Aborted' => '255,0,0', |
29 |
'Failed' => '255,0,0', |
'Failed' => '255,0,0', |
30 |
'Completed' => '64,255,64', |
'Completed' => '64,255,64', |
32 |
'Completed/Failure' => '128,0,128', |
'Completed/Failure' => '128,0,128', |
33 |
'Mount Request' => '128,128,255', |
'Mount Request' => '128,128,255', |
34 |
'Mount/Errors' => '255,64,128', |
'Mount/Errors' => '255,64,128', |
35 |
|
'Mount/Failures' => '255,128,192', |
36 |
); |
); |
37 |
|
|
38 |
my $int_t = (12 * 60 * 60); # interval to display on one screen |
my $int_t = (12 * 60 * 60); # interval to display on one screen |
40 |
|
|
41 |
#--- no user servicable parts below this line |
#--- no user servicable parts below this line |
42 |
|
|
43 |
# time range |
my $q=new CGI; |
|
|
|
|
$int_t = m_round($int_t); |
|
44 |
|
|
45 |
my ($from_t,$to_t) = (time()-$int_t,time()); |
my ($from_t,$to_t) = (time()-$int_t,time()); |
46 |
|
|
|
$to_t = param('to_t') if (param('to_t')); |
|
47 |
$from_t = param('from_t') if (param('from_t')); |
$from_t = param('from_t') if (param('from_t')); |
48 |
|
$to_t = param('to_t') if (param('to_t')); |
49 |
|
|
50 |
|
if (param('f-1')) { |
51 |
|
$from_t = $from_t - param('int_f-1') || $int_t; |
52 |
|
} elsif (param('f+1')) { |
53 |
|
$from_t = $from_t + param('int_f+1') || $int_t; |
54 |
|
} elsif (param('t-1')) { |
55 |
|
$to_t = $from_t - param('int_t-1') || $int_t; |
56 |
|
} elsif (param('t+1')) { |
57 |
|
$to_t = $from_t + $int_t; |
58 |
|
} |
59 |
|
|
60 |
|
# time range |
61 |
|
$int_t = m_round($int_t); |
62 |
|
|
63 |
# round to nearest minute |
# round to nearest minute |
64 |
sub m_round { |
sub m_round { |
76 |
# keep count of each status |
# keep count of each status |
77 |
my %count; |
my %count; |
78 |
|
|
79 |
if (param('pic')) { |
if (path_info()) { |
80 |
print "Content-type: image/png\nCache-Control: max-age=3600, must-revalidate\n\n"; |
print "Content-type: image/png\nCache-Control: max-age=86400, must-revalidate\nExpires: ",scalar localtime(time()+24*60*60),"\nLast-Modified: ",scalar localtime(0),"\n"; |
81 |
# create picture using GD |
# create picture using GD |
82 |
use GD; |
use GD; |
83 |
my $im = new GD::Image(1,$height); |
my $im = new GD::Image(1,$height); |
84 |
my $back = $im->colorAllocate(255,255,255); |
my $back = $im->colorAllocate(255,255,255); |
85 |
$im->transparent($back); |
$im->transparent($back); |
86 |
my ($r,$g,$b) = split(/,/,param('pic')); |
my $col = path_info(); $col =~ s,/,,g; |
87 |
my $col = $im->colorAllocate($r,$g,$b); |
my ($r,$g,$b) = split(/,/,$col); |
88 |
|
$col = $im->colorAllocate($r,$g,$b); |
89 |
$im->fill(0,0,$col); |
$im->fill(0,0,$col); |
90 |
|
print "Content-Length: ",length($im->png),"\n\n"; |
91 |
binmode STDOUT; |
binmode STDOUT; |
92 |
print $im->png; |
print $im->png; |
93 |
exit; |
exit; |
94 |
} |
} |
95 |
|
|
96 |
|
# open DBI connection |
97 |
|
my $dbh = DBI->connect("DBI:Pg:dbname=gantt","","") || die $DBI::errstr; |
98 |
|
|
99 |
print "Content-type: text/html |
print "Content-type: text/html |
100 |
Cache-Control: max-age=60, must-revalidate |
Cache-Control: max-age=60, must-revalidate |
101 |
|
|
102 |
<html> |
<html> |
103 |
<head> |
<head> |
104 |
<title>OmniBack Gantt: $from - $to</title> |
<title>OmniBack Gantt: $from - $to</title> |
105 |
<meta HTTP-EQUIV=\"Refresh\" CONTENT=60>"; |
<meta HTTP-EQUIV=\"Refresh\" CONTENT=600>"; |
106 |
if ($use_js) { |
if ($use_js) { |
107 |
print ' |
print ' |
108 |
<script type="text/javascript" language="javascript" src="1k.js"></script> |
<script type="text/javascript" language="javascript" src="1k.js"></script> |
116 |
</script> |
</script> |
117 |
'; |
'; |
118 |
} |
} |
119 |
print "</head><body>"; |
print "</head><body> |
120 |
|
<form action=".$q->url(-relative=>1)." method=get> |
121 |
|
<input type=hidden name=from_t value=$from_t> |
122 |
|
<input type=hidden name=to_t value=$to_t> |
123 |
|
"; |
124 |
|
|
125 |
# all vars ending in *_t have utime in them. |
# all vars ending in *_t have utime in them. |
126 |
# |
# |
127 |
my $len_t = $to_t - $from_t; |
my $len_t = $to_t - $from_t; |
128 |
|
|
129 |
die "interval must be positive and bigger than 1 sec !" if ($len_t < 1); |
die "interval must be positive and bigger than 1 sec !" if (abs($len_t) < 1); |
|
|
|
|
my $dbh = DBI->connect("DBI:Pg:dbname=gantt","","") || die $DBI::errstr; |
|
|
my $q=new CGI; |
|
130 |
|
|
131 |
|
|
132 |
sub mknav { |
sub mknav { |
133 |
my $f = shift @_; # from_t |
my $f = shift @_; # from_t |
134 |
my $t = shift @_; # to_t |
my $t = shift @_; # to_t |
135 |
|
my $d = shift @_; # delta |
136 |
my $ch = shift @_; # char |
my $ch = shift @_; # char |
137 |
|
|
138 |
return "<a href=\"".$q->url(-relative=>1)."?from_t=${f}&to_t=${t}\">$ch</a>"; |
return " |
139 |
|
<select name=int_${d}> |
140 |
|
<option value=".(12*60*60).">12h</option> |
141 |
|
<option value=".(24*60*60).">day</option> |
142 |
|
<option value=".(7*24*60*60).">week</option> |
143 |
|
</select> |
144 |
|
<input type=submit name=$d value=\"$ch\"> |
145 |
|
"; |
146 |
|
#return "<a href=\"".$q->url(-relative=>1)."?from_t=${f}&to_t=${t}\">$ch</a>"; |
147 |
} |
} |
148 |
|
|
149 |
print "<table cellspacing=0 cellpadding=0>"; |
print "<table cellspacing=0 cellpadding=0>"; |
150 |
print "<tr bgcolor=#e0e0e0><td>Specification</td><td align=left>"; |
print "<tr bgcolor=#e0e0e0><td>Specification</td><td align=left>"; |
151 |
print mknav(($from_t-$int_t),$to_t,'<small><<</small>'),$from; |
print mknav($from_t,$to_t,'f-1','<<'),$from; |
152 |
print mknav(($from_t+$int_t),$to_t,'<small>>></small>') if ($from_t+$int_t < $to_t); |
print mknav($from_t,$to_t,'f+1','>>') if ($from_t+$int_t < $to_t); |
153 |
print "</td><td align=right>"; |
print "</td><td align=right>"; |
154 |
print mknav($from_t,($to_t-$int_t),'<small><<</small>') if ($to_t-$int_t > $from_t); |
print mknav($from_t,$to_t,'t-1','<<') if ($to_t+$int_t > $from_t); |
155 |
print $to,mknav($from_t,($to_t+$int_t),'<small>>></small>'),"</td></tr>\n"; |
print $to,mknav($from_t,$to_t,'t+1','>>'),"</td></tr>\n"; |
156 |
|
|
157 |
# draw hour grid |
# draw hour grid |
158 |
sub hour_grid { |
sub hour_grid { |
236 |
|
|
237 |
print STDERR "bar[$col] len:$l s scale:",($len_t/$width)," size:$size px<br> alt:$alt\n" if ($debug); |
print STDERR "bar[$col] len:$l s scale:",($len_t/$width)," size:$size px<br> alt:$alt\n" if ($debug); |
238 |
|
|
239 |
my $html = "<img src=\"".$q->url(-relative=>1)."?pic=$col\" width=\"$size\" height=\"$h\""; |
my $html; |
240 |
|
|
241 |
|
my ($html_end, $img_end) = ("",""); |
242 |
|
if ($repgen_url && $alt =~ m#(\d\d\d\d)/(\d\d)/(\d\d)-(\d+)#) { |
243 |
|
$html .= "<a href=\"$repgen_url/$1-$2-$3-$4.html\">"; |
244 |
|
$html_end .= "</a>"; |
245 |
|
$img_end .= " border=0"; |
246 |
|
} |
247 |
|
|
248 |
|
$html .= "<img src=\"".$q->url(-relative=>1)."/$col\" width=\"$size\" height=\"$h\""; |
249 |
|
|
250 |
if ($use_js && $alt) { |
if ($use_js && $alt) { |
251 |
$html .= " onmouseover=\"T('$alt')\" onmouseout=\"T()\""; |
$html .= " onmouseover=\"T('$alt')\" onmouseout=\"T()\""; |
252 |
} elsif ($alt) { |
} elsif ($alt) { |
253 |
$html .= " alt=\"$alt\""; |
$html .= " alt=\"$alt\""; |
254 |
} |
} |
255 |
$html .= ">"; |
$html .= "$img_end>$html_end"; |
256 |
|
|
257 |
return($html); |
return($html); |
258 |
} |
} |
266 |
"; |
"; |
267 |
|
|
268 |
my $sth = $dbh->prepare($sql) || die "sql: $sql ".$dbh->errstr; |
my $sth = $dbh->prepare($sql) || die "sql: $sql ".$dbh->errstr; |
269 |
|
print STDERR "sql: $sql\n" if ($debug); |
270 |
|
|
271 |
my %spec; # specification hash |
my %spec; # specification hash |
272 |
|
|
273 |
my $curr_spec; |
my $curr_spec = ""; |
274 |
my $curr_t = $from_t; |
my $curr_t = $from_t; |
275 |
|
|
276 |
$sth->execute() || die "sql: $sql ".$dbh->errstr; |
$sth->execute() || die "sql: $sql ".$dbh->errstr; |
296 |
$len++; |
$len++; |
297 |
} else { |
} else { |
298 |
my $h = $last_var / $max_use * $height; |
my $h = $last_var / $max_use * $height; |
299 |
my $c = 255 - 255 * $last_var / $max_use; |
my $c = 255 - int (255 * $last_var / $max_use); |
300 |
print color_bar($len,"$c,$c,$c","$last_var concurrent jobs",1,$h+1); |
print color_bar($len,"$c,$c,$c","$last_var concurrent jobs",1,$h+1); |
301 |
$len = 0; |
$len = 0; |
302 |
$last_var = $v; |
$last_var = $v; |
303 |
} |
} |
304 |
} |
} |
305 |
|
# fix division by zero |
306 |
|
$max_use++ if ($max_use == 0); |
307 |
my $h = $last_var / $max_use * $height; |
my $h = $last_var / $max_use * $height; |
308 |
my $c = 255 - 255 * $last_var / $max_use; |
my $c = 255 - int (255 * $last_var / $max_use); |
309 |
print color_bar($len,"$c,$c,$c","$last_var concurrent jobs",1,$h+1) if ($len); |
print color_bar($len,"$c,$c,$c","$last_var concurrent jobs",1,$h+1) if ($len); |
310 |
print "</td></tr>"; |
print "</td></tr>"; |
311 |
} |
} |
312 |
|
|
313 |
|
my @line_t; # all seconds for this specification |
314 |
|
my @line_arr = (""); # all segments on line which are not fillers |
315 |
|
|
316 |
|
sub html_spec { |
317 |
|
print "<tr><td>$curr_spec</td><td colspan=2>"; |
318 |
|
|
319 |
|
my $last_var = 0; |
320 |
|
my $len = 0; |
321 |
|
my $i; |
322 |
|
for (my $t=0; $t<=$len_t; $t++) { |
323 |
|
$i = $line_t[$t] || 0; |
324 |
|
if ($i == $last_var) { |
325 |
|
$len++; |
326 |
|
} else { |
327 |
|
if ($last_var == 0) { |
328 |
|
print bar($len); |
329 |
|
} else { |
330 |
|
print bar($len,split(/\t/,$line_arr[$last_var],2)); |
331 |
|
} |
332 |
|
$len = 0; |
333 |
|
$last_var = $i; |
334 |
|
} |
335 |
|
} |
336 |
|
print bar($len,split(/\t/,$line_arr[$i],2)); |
337 |
|
|
338 |
|
print "</td></tr>\n"; |
339 |
|
} |
340 |
|
|
341 |
while(my $row = $sth->fetchrow_hashref) { |
while(my $row = $sth->fetchrow_hashref) { |
342 |
if (!defined $curr_spec || $row->{specification} ne $curr_spec) { |
if ($row->{specification} ne $curr_spec) { |
343 |
|
|
344 |
if ($curr_t < $to_t && $curr_spec) { |
if ($curr_t < $to_t && $curr_spec) { |
345 |
my $t = $to_t - $curr_t; |
my $t = $to_t - $curr_t; |
346 |
print STDERR "[end filler $curr_t:$t]" if ($debug); |
print STDERR "[end filler $curr_t:$t]" if ($debug); |
347 |
print bar($t); |
# print bar($t); |
348 |
} |
} |
349 |
|
|
350 |
print "</td></tr>\n" if ($curr_t != $from_t); |
# print "</td></tr>\n" if ($curr_t != $from_t); |
351 |
|
|
|
if ($dev && @dev_t && $dev ne $row->{device}) { |
|
|
sum_bar("summary for $dev",@dev_t); |
|
|
$dev = $row->{device}; |
|
|
@dev_t = (); |
|
|
} elsif (! $dev) { |
|
|
$dev = $row->{device}; |
|
|
} |
|
352 |
|
|
353 |
# init vars for next line |
# init vars for next line |
354 |
($fix_s,$fix_d) = (0,0); # init fix vars for bar |
($fix_s,$fix_d) = (0,0); # init fix vars for bar |
355 |
print "<tr><td>", $row->{specification},"</td><td colspan=2>"; |
|
356 |
|
if ($curr_spec ne "") { |
357 |
|
$curr_spec =~ s/ +/ /g; |
358 |
|
html_spec; |
359 |
|
} |
360 |
|
|
361 |
$curr_t = $from_t; # init timeline |
$curr_t = $from_t; # init timeline |
362 |
$curr_spec = $row->{specification}; |
$curr_spec = $row->{specification}; |
363 |
|
|
364 |
|
@line_t = (); |
365 |
|
@line_arr = ( "" ); |
366 |
|
|
367 |
|
if ($dev && @dev_t && $dev ne $row->{device}) { |
368 |
|
sum_bar("summary for $dev",@dev_t); |
369 |
|
$dev = $row->{device}; |
370 |
|
@dev_t = (); |
371 |
|
} elsif (! $dev) { |
372 |
|
$dev = $row->{device}; |
373 |
|
} |
374 |
} |
} |
375 |
|
|
376 |
my $start_t = str2time($row->{start}); |
my $start_t = str2time($row->{start}); |
380 |
if ($start_t > $curr_t + ($len_t / $width)) { |
if ($start_t > $curr_t + ($len_t / $width)) { |
381 |
my $t = $start_t - $curr_t; |
my $t = $start_t - $curr_t; |
382 |
print STDERR "[middle filler $curr_t:$t]" if ($debug); |
print STDERR "[middle filler $curr_t:$t]" if ($debug); |
383 |
print bar($t); |
# print bar($t); |
384 |
$curr_t = $start_t; |
$curr_t = $start_t; |
385 |
} else { |
} else { |
386 |
# prepend too few seconds to next event |
# prepend too few seconds to next event |
413 |
$row->{type}." <b>".$row->{status}."</b><br>". |
$row->{type}." <b>".$row->{status}."</b><br>". |
414 |
$row->{user_group_host}." <i>".$row->{sessionid}."</i><br>". |
$row->{user_group_host}." <i>".$row->{sessionid}."</i><br>". |
415 |
$row->{device}." on ".$row->{host}; |
$row->{device}." on ".$row->{host}; |
416 |
print bar($len,$row->{status},$alt); |
# print bar($len,$row->{status},$alt); |
417 |
|
|
418 |
|
push @line_arr,$row->{status}."\t".$alt; |
419 |
# store use of devices for each minute |
# store use of devices for each minute |
420 |
for (my $s=0; $s<$len; $s++) { |
for (my $s=0; $s<$len; $s++) { |
421 |
|
$line_t[$curr_t-$from_t+$s] = $#line_arr; |
422 |
$dev_t[$curr_t-$from_t+$s]++; |
$dev_t[$curr_t-$from_t+$s]++; |
423 |
$dev_sum_t[$curr_t-$from_t+$s]++; |
$dev_sum_t[$curr_t-$from_t+$s]++; |
424 |
} |
} |
430 |
} |
} |
431 |
|
|
432 |
if ($curr_t == $from_t) { # no entries in database! |
if ($curr_t == $from_t) { # no entries in database! |
433 |
print "<tr><td></td><td colspan=2>"; |
# print "<tr><td></td><td colspan=2>"; |
434 |
} |
} |
435 |
|
|
436 |
if ($curr_t < $to_t ) { |
if ($curr_t < $to_t ) { |
437 |
my $t = $to_t - $curr_t; |
my $t = $to_t - $curr_t; |
438 |
print STDERR "[last_line filler $curr_t:$t]" if ($debug); |
print STDERR "[last_line filler $curr_t:$t]" if ($debug); |
|
print bar($t); |
|
439 |
} |
} |
440 |
|
|
441 |
undef $sth; |
undef $sth; |
442 |
$dbh->disconnect; |
$dbh->disconnect; |
443 |
|
|
444 |
print "</td></tr>\n"; |
html_spec(); |
445 |
sum_bar("summary for $dev",@dev_t); |
sum_bar("summary for $dev",@dev_t); |
446 |
hour_grid(); |
hour_grid(); |
447 |
sum_bar("summary for all devices",@dev_sum_t); |
sum_bar("summary for all devices",@dev_sum_t); |
449 |
|
|
450 |
|
|
451 |
# label and usage |
# label and usage |
|
$len_t = 50; # disable bar scaling |
|
452 |
|
|
453 |
print "<hr>\nColors for statuses and usage (#):\n"; |
print "<hr>\nColors for statuses and usage (#):\n"; |
454 |
print "<table border=0><tr bgcolor=#e0e0e0><th>status</th><th>#</th><th>color</th></tr>\n"; |
print "<table border=0><tr bgcolor=#e0e0e0><th>status</th><th>#</th><th>color</th></tr>\n"; |
455 |
|
my $max = 0; |
456 |
|
foreach my $status (keys %count) { |
457 |
|
$max = $count{$status} if ($count{$status} > $max); |
458 |
|
} |
459 |
|
$len_t = $max ; # disable bar scaling |
460 |
|
|
461 |
foreach my $status (keys %count) { |
foreach my $status (keys %count) { |
462 |
#foreach my $status (keys %cols) { |
#foreach my $status (keys %cols) { |
463 |
print "<tr bgcolor=#e0e0e0><td><small>$status</small></td><td><small>",$count{$status}*1,"</small></td><td>",bar($count{$status},$status),"</td></tr>\n" if ($status ne ""); |
print "<tr bgcolor=#e0e0e0><td><small>$status</small></td><td><small>",$count{$status}*1,"</small></td><td>",bar($count{$status},$status),"</td></tr>\n" if ($status ne ""); |
466 |
# it will first evaluate bar sub (thus increasing number by one) and |
# it will first evaluate bar sub (thus increasing number by one) and |
467 |
# then display number (wrongly). |
# then display number (wrongly). |
468 |
} |
} |
469 |
print "</table>\n<p>Reload <a href=\"",$q->url(-relative=>1),"\">current</a> or see <a href=\"db2gantt_help.html\">help</a>.</p></body></html>"; |
print "</table></form>\n<p>Reload <a href=\"",$q->url(-relative=>1),"\">current</a> or see <a href=\"db2gantt_help.html\">help</a>.</p></body></html>"; |
|
|
|