Created the zfs-replicate-wrapper script that factors in duration to
[zfs-nexenta/.git] / zfs-log-parser
index f3619dbe912fc5caf4e13184119905a8304a37c8..94e4490b500a581b623dc6daa681eabb4e1735ff 100755 (executable)
@@ -52,14 +52,14 @@ sub parse_replicate_logfile {
        if(($in_replicate == 0) && ("$startdate" ne "") && ($line !~ /$startdate/)) { next; }
        if($line =~ /(\S+)\s+(\S+)\s+(\d+)\s+(\d+):(\d+):(\d+)\s+(\S+)\s+(\S+)/) {
            $dayname=$1; $month=$2; $daynum=$3; $hour=$4; $minute=$5; $sec=$6; $year=$8;
-           if(($in_replicate == 0) && ($line =~ /lock obtained/)) {
+           if(($in_replicate == 0) && ($line =~ /replicate started/)) {
                $in_replicate = 1;
                $date="$dayname $month $daynum $hour:$minute:$sec $year";
                $totals{$date}{data} = 0;
                $totals{$date}{transfertime} = 0;
                $totals{$date}{duration} = time_to_seconds($hour,$minute,$sec);
            }
-           elsif(($in_replicate == 1) && ($line=~ /lock released/)) {
+           elsif(($in_replicate == 1) && ($line=~ /replicate complete/)) {
                $in_replicate = 0;
                $totals{$date}{duration} = time_to_seconds($hour,$minute,$sec) - $totals{$date}{duration};
            }
@@ -82,7 +82,11 @@ sub parse_replicate_logfile {
        $duration=adjust_duration($totals{$date}{duration});
        $data=adjust_data($totals{$date}{data});
        $transfertime=adjust_duration($totals{$date}{transfertime});
-       $rate = adjust_data(int($totals{$date}{data}/$totals{$date}{transfertime}));
+        if($totals{$date}{transfertime} > 0) { 
+         $rate = adjust_data(int($totals{$date}{data}/$totals{$date}{transfertime}));
+        } else { 
+          $rate = 0;
+        }
        print "$date: data=${data} transfertime=$transfertime rate=${rate}/sec duration=$duration\n";
     }
 }
@@ -91,10 +95,13 @@ sub parse_snapshot_totals_logfile {
     %totals=();
     $in_totals=0;
     $maxlen=0;
+    $found_startdate=0;
     $header="";
     while(<FILE>) {
        $line = $_;
         if($line =~ /logfile turned over/) { next; }
+        if(($in_totals == 0) && ("$startdate" ne "") && ($line !~ /$startdate/) && ($found_startdate==0)) { next; }
+        if(($in_totals == 0) && ("$startdate" ne "") && ($line =~ /$startdate/) && ($found_startdate==0)) { $found_startdate=1; }
        if(($in_totals == 0) && ($line =~ /(\S+)\s+(\S+)\s+(\d+)\s+(\d+):(\d+):(\d+)\s+(\S+)\s+(\S+)/)) {
            $dayname=$1; $month=$2; $daynum=$3; $hour=$4; $minute=$5; $sec=$6; $year=$8;
            $in_totals = 1;
@@ -152,7 +159,11 @@ sub parse_snapshot_totals_logfile {
 # MAIN
 #########
 #print "-> Parsing $logfile\n";
-open(FILE,"$logfile") || die "-E- Unable to open $logfile\n";
+if("$logfile" =~ /\.[bz2|gz]/) { 
+  open(FILE,"zcat $logfile|") || die "-E- Unable to open $logfile\n";
+} else {
+  open(FILE,"$logfile") || die "-E- Unable to open $logfile\n";
+}
 
 if($logfile =~ /replicate/) { parse_replicate_logfile(); }
 if($logfile =~ /snapshot-totals/) { parse_snapshot_totals_logfile(); }