--- parse_log.cgi 2003/10/06 09:38:25 1.4
+++ parse_log.cgi 2003/10/06 22:32:06 1.5
@@ -18,7 +18,8 @@
use Data::Dumper;
my $date_fmt = "%Y-%m-%d";
-my $date_time_fmt = "%Y-%m-%d %H:%M:%S";
+#my $date_time_fmt = "%Y-%m-%d %H:%M:%S";
+my $date_time_fmt = "%a %Y-%m-%d %H:%M:%S";
my $from_date = "now - 6 months";
my $to_date = "now";
@@ -29,7 +30,7 @@
my $from_time_interval = "7:00";
my $to_time_interval = "17:00";
-my $debug=1;
+my $debug=0;
$debug++ if (grep(/-v/,@ARGV));
$debug++ if (grep(/-d/,@ARGV));
@@ -50,19 +51,19 @@
my @sg_selected = $q->param('sg_filter');
# init misc sort parametars
-my @sort;
+my @sort_rules;
my $order;
my %sort_param;
my ($usort,$dsort);
if ($q->param('usort')) {
$sort_param{'usort'} = $q->param('usort');
$q->delete('usort');
- @sort = ( -compare => 'numeric', $sort_param{'usort'} );
+ @sort_rules = ( -compare => 'numeric', scalar $sort_param{'usort'} );
}
if ($q->param('dsort')) {
$sort_param{'dsort'} = $q->param('dsort');
$q->delete('dsort');
- @sort = ( -compare => 'numeric', -order=>'reverse', $sort_param{'dsort'} );
+ @sort_rules = ( -compare => 'numeric', -order=>'reverse', scalar $sort_param{'dsort'} );
}
# make interval
@@ -122,25 +123,22 @@
#
my %fail;
-my $downtime; # total downtime
my $sg_filter; # filter for service/group
-my $sg_count; # count number of downtimes
my $log_file="/var/log/mon/sap.log";
my $data;
# generate unique key for this data and options
-my $cache_key="monlog".join("",@sg_selected).$print_orphans.$rep_reset;
+my $cache_key="monlog".join("|",@sg_selected)."|".$print_orphans."|".$rep_reset;
+# debug disables cache
if (! $debug) {
-$data = $cache->get( $cache_key );
-$downtime = $cache->get("downtime $cache_key");
-$sg_filter = $cache->get("sg_filter $cache_key");
-$sg_count = $cache->get("sg_count $cache_key");
+ $data = $cache->get( $cache_key );
+ $sg_filter = $cache->get("sg_filter $cache_key");
}
-if (!$data || !$downtime || !$sg_filter || !$sg_count) {
+if (!$data || !$sg_filter) {
open(LOG, $log_file) || die "$log_file: $!";
@@ -155,9 +153,8 @@
'sg'=>"$group/$service",
'from'=>$fail{$id},
'to'=>$utime,
+ 'dur'=>($utime-$fail{id}),
'desc'=>$desc };
- $downtime->{"$group/$service"} += ($utime - $fail{$id}),
- $sg_count->{"$group/$service"}++;
}
$sg_filter->{"$group/$service"}++;
delete $fail{$id};
@@ -167,8 +164,8 @@
'sg'=>"$group/$service",
'from'=>-1,
'to'=>$utime,
+ 'dur'=>0,
'desc'=>$desc };
- $sg_count->{"$group/$service"}++;
}
delete $fail{$id};
$sg_filter->{"$group/$service"}++;
@@ -178,10 +175,9 @@
'sg'=>"$group/$service",
'from'=>$fail{$id},
'to'=>$utime,
+ 'dur'=>($utime-$fail{id}),
'desc'=>'[failure again]'};
- $downtime->{"$group/$service"} += ($utime - $fail{$id}),
$fail{$id} = $utime;
- $sg_count->{"$group/$service"}++;
}
$sg_filter->{"$group/$service"}++;
} else {
@@ -192,9 +188,7 @@
close(LOG);
$cache->set($cache_key, $data);
- $cache->set("downtime $cache_key", $downtime);
$cache->set("sg_filter $cache_key", $sg_filter);
- $cache->set("sg_count $cache_key", $sg_count);
}
@@ -216,20 +210,20 @@
),
),td(
em("Other options:"),br,
- $q->checkbox(-name=>'rep_reset',-checked=>0,
+ $q->checkbox(-name=>'rep_reset',-default=>0,
-label=>"show repeated failures on same service as individual failures"),
br,
- $q->checkbox(-name=>'print_orphans',-checked=>0,
+ $q->checkbox(-name=>'print_orphans',-default=>0,
-label=>"show records which are not complete in this interval"),
br,
- $q->checkbox(-name=>'use_date_limit',-checked=>1,
+ $q->checkbox(-name=>'use_date_limit',-default=>1,
-label=>"use date limit from:"),
$q->textfield(-name=>'from_date',-size=>20,-default=>$from_date),
" to: ",
$q->textfield(-name=>'to_date',-size=>20,-default=>$to_date),
small('Using Time::ParseDate'),
br,
- $q->checkbox(-name=>'use_time_limit',-checked=>1,
+ $q->checkbox(-name=>'use_time_limit',-default=>1,
-label=>"use time limit for each day:"),
$q->textfield(-name=>'from_time_interval',-size=>8,-default=>$from_time_interval),
" to: ",
@@ -252,14 +246,21 @@
# dump report
#
+my %dir_html_entity = (
+# 'u' => '⇑',
+# 'd' => '⇓'
+ 'u' => '▲',
+ 'd' => '▼',
+);
+
sub sort_link {
my $q = shift || return;
my $col = shift || return;
my $dir = lc(shift) || return;
if ($sort_param{$dir.'sort'} && $sort_param{$dir.'sort'} eq $col) {
- return '&'.$dir.'Arr;';
+ return $dir_html_entity{$dir};
} else {
- return '&'.$dir.'Arr;';
+ return ''.$dir_html_entity{$dir}.'';
}
}
@@ -276,9 +277,9 @@
# sort data
#
-my @sorted = sorted_array(@$data, @sort);
+my @sorted = sorted_array( @$data, @sort_rules );
-print "-- sort: ",Dumper(@sort)," (data: ".@$data." sorted: ".@sorted.") --\n",br,"-- dayMask: $dayMask --\n",br,"-- cache_key: $cache_key --\n",br if ($debug);
+print "-- sort: ",Dumper(@sort_rules)," (data: ".@$data." sorted: ".@sorted.") --\n",br,"-- dayMask: $dayMask --\n",br,"-- cache_key: $cache_key --\n",br if ($debug);
print start_table({-border=>1,-cellspacing=>0,-cellpadding=>2,-width=>'100%'});
@@ -301,20 +302,33 @@
th("description")
) if (scalar @sorted > 0);
+my $downtime; # total downtime
+my $downinterval; # total downtime in time interval
+my $sg_count; # count number of downtimes
+
foreach my $row (@sorted) {
next if ($q->param('use_date_limit') && ($row->{from} < $from_time || $row->{to} > $to_time));
my ($from,$dur,$int) = ('unknown','unknown','unknown');
+
if ($row->{from} != -1 ) {
$from = d($row->{from});
- $dur = dur($row->{to} - $row->{from});
- $int = dur($working_days->interval($row->{to},$row->{from}));
+ $dur = $row->{to} - $row->{from};
+ $downtime->{$row->{sg}} += $dur;
+ if ($q->param('use_time_limit')) {
+ $int = $working_days->interval($row->{from},$row->{to});
+ $dur = dur($int)."
∑ ".dur($dur)."";
+ $downinterval->{$row->{sg}} += $int;
+ } else {
+ $dur = dur($dur);
+ }
}
+ $sg_count->{$row->{sg}}++;
+
print Tr(
td({-align=>'left',-valign=>'center'},$row->{sg}),
td({-align=>'right',-bgcolor=>'#f0f0f0'},$from),
td({-align=>'right'},d($row->{to})),
td({-align=>'center',-bgcolor=>'#e0e0e0'},$dur),
- td({-align=>'center',-bgcolor=>'#e0e0e0'},$int),
td({-align=>'left'},$row->{desc}),
),"\n";
}
@@ -323,9 +337,15 @@
#
foreach my $sg (keys %$downtime) {
-print Tr(td({-colspan=>3,-align=>'right'},"total for $sg:"),
- td({-bgcolor=>'#e0e0e0',-align=>'right'},dur($downtime->{$sg})),
- td(small("in ".$sg_count->{$sg}." failures"))),"\n";
+ my $dur;
+ if ($downinterval->{$sg}) {
+ $dur=dur($downinterval->{$sg})."
∑ ".dur($downtime->{$sg})."";
+ } else {
+ $dur=dur($downtime->{sg});
+ }
+ print Tr(td({-colspan=>3,-align=>'right'},"total for $sg:"),
+ td({-bgcolor=>'#e0e0e0',-align=>'right'},$dur),
+ td(small("in ".$sg_count->{$sg}." failures"))),"\n";
}
print end_table,