From: Alan J. Pippin Date: Mon, 3 Mar 2008 15:02:25 +0000 (-0700) Subject: Added ability to parse snapshot total log files. X-Git-Url: http://git.pippins.net/embedvideo/.git/%27%20%20%20%20.%20%24GLOBALS%5B%27phpgw%27%5D-%3Elink%28%27inc/jquery/x.gif?a=commitdiff_plain;h=c86dd7de4b6627ff5bccb105bb4c06f6cd70d602;p=zfs-nexenta%2F.git Added ability to parse snapshot total log files. --- diff --git a/zfs-log-parser b/zfs-log-parser index 5657725..d43e650 100755 --- a/zfs-log-parser +++ b/zfs-log-parser @@ -6,6 +6,7 @@ $logfile=shift(@ARGV); $startdate=shift(@ARGV); +$backup_pool="backups"; sub usage { print "Usage: $0 \n"; @@ -17,6 +18,9 @@ $kilo = 1024; $mega = 1024 * 1024; $giga = 1024 * 1024 * 1024; +%month2num = ( "Jan" => "01", "Feb" => "02", "Mar" => "03", "Apr" => "04", "May" => "05", "Jun" => "06", + "Jul" => "07", "Aug" => "08", "Sep" => "09", "Oct" => "10", "Nov" => "11", "Dec" => "12"); + sub time_to_seconds { my ($hour,$minute,$sec) = @_; $seconds = ($hour * 60 * 60) + ($minute * 60) + ($sec); @@ -83,6 +87,59 @@ sub parse_replicate_logfile { } } +sub parse_snapshot_totals_logfile { + %totals=(); + $in_totals=0; + $maxlen=0; + $header=""; + while() { + $line = $_; + 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; + $month = $month2num{$month}; + if($daynum < 10) { $daynum = "0".$daynum; } + $date="$month-$daynum-$year"; + if(!defined $dates{$date}) { $header .= $date . " "; } + $dates{$date} = 1; + } + if(($in_totals == 1) && ($line =~ /^\s+$/)) { + $in_totals = 0; + } + if(($in_totals == 1) && ($line =~ /(\S+)\s+([\d\.]+)(\w+)\s+(\d+)/)) { + $filesystem = $1; $data = $2; $size = $3; $num_snaps = $4; + if($filesystem =~ /Snapshots/) { next; } + if($filesystem =~ /$backup_pool/) { next; } + if(length($filesystem) > $maxlen) { $maxlen = length($filesystem); } + if($size =~ /K/i) { $data = $data * $kilo; } + if($size =~ /M/i) { $data = $data * $mega; } + if($size =~ /G/i) { $data = $data * $giga; } + chomp($line); + $totals{$filesystem}{$date}{data} = $data; + if($totals{$filesystem}{start_data} == 0) { $totals{$filesystem}{start_data} = $data; } + $totals{$filesystem}{delta} = $data - $totals{$filesystem}{start_data}; + } + } + $total_delta=0; + printf("%-${maxlen}s %s %s\n","ZFS Filesystem","$header","Net Change"); + foreach $filesystem (sort keys %totals) { + $hashref = $totals{$filesystem}; + $data=""; + foreach $date (sort keys %$hashref) { + if($date !~ /(\d+)-(\d+)-(\d+)/) { next; } + $date_data=adjust_data($totals{$filesystem}{$date}{data}); + $data .= sprintf("%10s",$date_data). " "; + } + $data_total=adjust_data($data_total); + $total_delta+=$totals{$filesystem}{delta}; + $delta=adjust_data($totals{$filesystem}{delta}); + printf("%-${maxlen}s %s %10s\n",$filesystem,$data,$delta); + } + $data_len=length($data); + $total_delta=adjust_data($total_delta); + printf("%-${maxlen}s %-${data_len}s %10s\n","Totals:","",$total_delta); +} + ######### # MAIN ######### @@ -90,5 +147,6 @@ sub parse_replicate_logfile { open(FILE,"$logfile") || die "-E- Unable to open $logfile\n"; if($logfile =~ /replicate/) { parse_replicate_logfile(); } +if($logfile =~ /snapshot-totals/) { parse_snapshot_totals_logfile(); } close(FILE);