📄 amstatus.pl
字号:
#!@PERL@ -Tw## Run perl.eval '(exit $?0)' && eval 'exec @PERL@ -S $0 ${1+"$@"}' & eval 'exec @PERL@ -S $0 $argv:q' if 0;require "newgetopt.pl";use Time::Local;use Text::ParseWords;delete @ENV{'IFS', 'CDPATH', 'ENV', 'BASH_ENV', 'PATH'};$ENV{'PATH'} = "/bin:/usr/bin:/usr/sbin:/sbin"; # force known path$confdir="@CONFIG_DIR@";$prefix='@prefix@';$prefix=$prefix; # avoid warnings about possible typo$exec_prefix="@exec_prefix@";$exec_prefix=$exec_prefix; # ditto$sbindir="@sbindir@";#$STATUS_STRANGE = 2;$STATUS_FAILED = 4;$STATUS_MISSING = 8;$STATUS_TAPE = 16;$exit_status = 0;$USE_VERSION_SUFFIXES='@USE_VERSION_SUFFIXES@';$suf = '';if ( $USE_VERSION_SUFFIXES =~ /^yes$/i ) { $suf='-@VERSION@';}$result = &NGetOpt ( "summary", "stats|statistics", "dumping|d", "waitdumping|wdumping", "waittaper|wtaper", "dumpingtape|dtape", "writingtape|wtape", "finished", "failed|error", "estimate", "gestimate|gettingestimate", "date", "config|c:s", "file:s", "locale-independent-date-format", );if($result !=1 ) { &usage();}if( defined $opt_config ) { $conf = $opt_config;}else { if($#ARGV == 0 ) { $conf=$ARGV[0]; } else { &usage(); }}#untaint user input $ARGV[0]if ($conf =~ /^([\w.-]+)$/) { # $1 is untainted $conf = $1;} else { die "filename '$conf' has invalid characters.\n";}if ( ! -e "$confdir/$conf" ) { print "Configuration directory '" . $confdir/$conf . "' doesn't exist\n"; exit 1;}if ( ! -d "$confdir/$conf" ) { print "Configuration directory '" . $confdir/$conf . "' is not a directory\n"; exit 1; }$pwd = `pwd`;chomp $pwd;chdir "$confdir/$conf";$logdir=`$sbindir/amgetconf$suf logdir`;exit 1 if $? != 0;chomp $logdir;$errfile="$logdir/amdump";$nb_options = defined( $opt_summary ) + defined( $opt_stats ) + defined( $opt_dumping ) + defined( $opt_waitdumping ) + defined( $opt_waittaper ) + defined( $opt_dumpingtape ) + defined( $opt_writingtape ) + defined( $opt_finished ) + defined( $opt_estimate ) + defined( $opt_gestimate ) + defined( $opt_failed );if($nb_options == 0 ) { $opt_summary = 1; $opt_stats = 1; $opt_dumping = 1; $opt_waitdumping = 1; $opt_waittaper = 1; $opt_dumpingtape = 1; $opt_writingtape = 1; $opt_finished = 1; $opt_failed = 1; $opt_gestimate = 1; $opt_estimate = 1;}$unit=`$sbindir/amgetconf$suf displayunit`;chomp($unit);$unit =~ tr/A-Z/a-z/;$unitdivisor=1;if($unit eq 'k') { $unitdivisor = 1;}elsif($unit eq 'm') { $unitdivisor = 1024;}elsif($unit eq 'g') { $unitdivisor = 1024*1024;}elsif($unit eq 't') { $unitdivisor = 1024*1024*1024;}else { $unit = 'k'; $unitdivisor = 1;}if( defined $opt_file) { if( $opt_file =~ m,^/, ) { $errfile = $opt_file; } else { $errfile = "$pwd/$opt_file"; $errfile = "$logdir/$opt_file" if ( ! (-f $errfile )); }}else { $errfile="$logdir/amflush" if(! (-f $errfile)); if (! -f $errfile) { if (-f "$logdir/amflush.1" && -f "$logdir/amdump.1" && -M "$logdir/amflush.1" < -M "$logdir/amdump.1") { $errfile="$logdir/amflush.1"; } else { $errfile="$logdir/amdump.1"; } }}open(AMDUMP,"<$errfile") || die("$errfile: $!");print "Using $errfile\n";$start_degraded_mode = 0;$label = ""; # -w fodder$origsize = 0; # -w fodder$idle_dumpers = 0;$status_driver = "";$status_taper = 0;$estimate_done = 0;$holding_space = 0;$start_time = 0;@dumpers_active = ();$nb_tape = 0;$ntpartition{$nb_tape} = 0;$ntsize{$nb_tape} = 0;$ntesize{$nb_tape} = 0;$tape_size = 0;$driver_finished = 0;$generating_schedule = 0;while($lineX = <AMDUMP>) { chomp $lineX; $lineX =~ s/[:\s]+$//g; #remove separator at end of line next if $lineX eq ""; @line = "ewords('[:\s]+', 0, $lineX); next if !defined $line[0]; if($line[0] eq "amdump" || $line[0] eq "amflush") { if ($line[1] eq "start" && $line[2] eq "at") { $datestr = $lineX; $datestr =~ s/.*start at //g; if (!defined $opt_locale_independent_date_format) { print "From " . $datestr . "\n"; } } elsif($line[1] eq "datestamp") { $gdatestamp = $line[2]; if(!defined $datestamp{$gdatestamp}) { $datestamp{$gdatestamp} = 1; push @datestamp, $gdatestamp; } } elsif($line[1] eq "starttime") { $starttime=&set_starttime($line[2]); } elsif($line[1] eq "starttime-locale-independent") { if (defined $opt_locale_independent_date_format) { printf "From " . $line[2] . " " . $line[3] . ":" . $line[4] . ":" . $line[5] . " " . $line[6] . "\n"; } } if($line[0] eq "amflush") { $estimate_done=1; } } elsif($line[0] eq "planner") { if($line[1] eq "timestamp") { $gdatestamp = $line[2]; if(!defined $datestamp{$gdatestamp}) { $datestamp{$gdatestamp} = 1; push @datestamp, $gdatestamp; } } elsif($line[1] eq "FAILED") { #2:host 3:disk 4:datestamp 5:level 6:errmsg $host=$line[2]; $partition=$line[3]; $datestamp=$line[4]; $hostpart=&make_hostpart($host,$partition,$datestamp); $dump_started{$hostpart}=-1; $level{$hostpart}=$line[5]; $error{$hostpart}="planner: " . $line[6]; } elsif($line[1] eq "time") { if($line[3] eq "got") { if($line[4] eq "result") { $host = $line[7]; $partition = $line[9]; $hostpart=&make_hostpart($host,$partition,$gdatestamp); $estimate{$hostpart}=1; $level{$hostpart}=$line[10]; $line[12] =~ /(\d+)K/; $esize{$hostpart}=$1 / $unitdivisor; $partialestimate{$hostpart}=0; $getest{$hostpart} = ""; } elsif($line[4] eq "partial") { $host = $line[8]; $partition = $line[10]; $hostpart=&make_hostpart($host,$partition,$gdatestamp); $level1 = $line[11]; $line[13] =~ /(-?\d+)K/; $size1 = $1; $level2 = $line[14]; $line[16] =~ /(-?\d+)K/; $size2 = $1; $level3 = $line[17]; $line[19] =~ /(-?\d+)K/; $size3 = $1; if($size1 > 0 || $size2 > 0 || $size3 > 0) { $estimate{$hostpart}=1; $level{$hostpart}=$line[11]; $esize{$hostpart}=$size1 / $unitdivisor; $partialestimate{$hostpart}=1; if($size1 > 0) { $getest{$hostpart} =~ s/:$level1://; } if($size2 > 0) { $getest{$hostpart} =~ s/:$level2://; } if($size3 > 0) { $getest{$hostpart} =~ s/:$level3://; } if($getest{$hostpart} eq "") {$partialestimate{$hostpart}=0;} } } } elsif($line[3] eq "getting" && $line[4] eq "estimates" && $line[5] eq "took") { $estimate_done=1; } } } elsif($line[0] eq "setup_estimate") { $host = $line[1]; $partition = $line[2]; $hostpart=&make_hostpart($host,$partition,$gdatestamp); $estimate{$hostpart}=0; $level{$hostpart}=0; $degr_level{$hostpart}=-1; $esize{$hostpart}=0; $dump_started{$hostpart}=0; $dump_finished{$hostpart}=0; $taper_started{$hostpart}=0; $taper_finished{$hostpart}=0; $partialestimate{$hostpart}=0; $error{$hostpart}=""; if($line[7] eq "last_level") { $getest{$hostpart}=""; $level1 = $line[15]; $level2 = $line[17]; $level3 = $line[19]; if($level1 != -1) { $getest{$hostpart} .= ":$level1:" }; if($level2 != -1) { $getest{$hostpart} .= ":$level2:" }; if($level3 != -1) { $getest{$hostpart} .= ":$level3:" }; } } elsif($line[0] eq "GENERATING" && $line[1] eq "SCHEDULE") { $generating_schedule=1; } elsif($line[0] eq "--------") { if ($generating_schedule == 1) { $generating_schedule = 2; } elsif ($generating_schedule == 2) { $generating_schedule = 3; } } elsif($line[0] eq "DUMP") { if($generating_schedule == 2 ) { $host = $line[1]; $partition = $line[3]; $datestamp = $line[4]; $hostpart=&make_hostpart($host,$partition,$datestamp); $level{$hostpart}=$line[6]; $esize=$line[14]; #compressed size $esize=32 if $esize<32; $esize{$hostpart}=$esize / $unitdivisor; if(!defined($line[22])) { $degr_level{$hostpart}=-1; } else { $degr_level{$hostpart}=$line[18]; $esize=$line[25]; #compressed size $esize=32 if $esize<32; $degr_size{$hostpart}=$esize / $unitdivisor; } } } elsif($line[0] eq "FLUSH") { $host = $line[1]; $partition = $line[2]; $datestamp = $line[3]; $level = $line[4]; $holding_file = $line[5]; $hostpart=&make_hostpart($host,$partition,$datestamp); $flush{$hostpart}=0; $holding_file{$hostpart}=$holding_file; $level{$hostpart}=$level; } elsif($line[0] eq "driver") { if($line[1] eq "start" && $line[2] eq "time") { $start_time=$line[3]; $current_time=$line[3]; $dumpers_active[0]=0; $dumpers_held[0]={}; $dumpers_active=0; } elsif($line[1] eq "tape" && $line[2] eq "size") { $lineX =~ /^driver: start time (\S+)/; $tape_size = $line[3] / $unitdivisor; } elsif($line[1] eq "adding" && $line[2] eq "holding" && $line[3] eq "disk") { $holding_space += $line[8]; } elsif($line[1] eq "send-cmd" && $line[2] eq "time") { #print "send-cmd: " , $line[5] . " " . $line[6] . " " . $line[7] . "\n" if defined $line[5] && defined $line[6] && defined $line[7]; $current_time = $line[3]; if($line[5] =~ /dumper\d*/) { $dumper = $line[5]; if($line[6] eq "PORT-DUMP") { #7:handle 8:port 9:host 10:amfeatures 11:disk 12:device 13:level ... $host = $line[9]; $partition = $line[11]; $hostpart=&make_hostpart($host,$partition,$gdatestamp); $serial=$line[7]; $dump_started{$hostpart}=1; $dump_time{$hostpart}=$current_time; $dump_finished{$hostpart}=0; if( $level{$hostpart} != $line[13] && $degr_level{$hostpart} == $line[13]) { $level{$hostpart}=$degr_level{$hostpart}; $esize{$hostpart}=$degr_size{$hostpart}; } if(! defined($busy_time{$dumper})) { $busy_time{$dumper}=0; } $running_dumper{$dumper} = $hostpart; $error{$hostpart}=""; $size{$hostpart} = 0; $dumpers_active++; if(! defined($dumpers_active[$dumpers_active])) { $dumpers_active[$dumpers_active]=0; } if(! defined($dumpers_held[$dumpers_active])) { $dumpers_held[$dumpers_active]={}; } } } elsif($line[5] =~ /chunker\d*/) { if($line[6] eq "PORT-WRITE") { $host=$line[9]; $partition=$line[11]; $hostpart=&make_hostpart($host,$partition,$gdatestamp); $serial=$line[7]; $serial{$serial}=$hostpart; $holding_file{$hostpart}=$line[8]; #$chunk_started{$hostpart}=1; $chunk_time{$hostpart}=$current_time; #$chunk_finished{$hostpart}=0; } elsif($line[6] eq "CONTINUE") { #7:handle 8:filename 9:chunksize 10:use $serial=$line[7]; $hostpart=$serial{$serial}; if($hostpart ne "") { $dump_roomq{$hostpart}=undef; $error{$hostpart}=""; } } } elsif($line[5] =~ /taper/) { if($line[6] eq "START-TAPER") { #7:timestamp $gdatestamp=$line[7]; if(!defined $datestamp{$gdatestamp}) { $datestamp{$gdatestamp} = 1; push @datestamp, $gdatestamp; } } elsif($line[6] eq "FILE-WRITE") { #7:handle 8:filename 9:host 10:disk 11:level 12:datestamp 13:splitsize $serial=$line[7]; $host=$line[9]; $partition=$line[10]; $level=$line[11]; $ldatestamp=$line[12]; if(!defined $datestamp{$ldatestamp}) { $datestamp{$ldatestamp} = 1; push @datestamp, $ldatestamp; } $hostpart=&make_hostpart($host,$partition,$ldatestamp); $serial{$serial}=$hostpart; if(!defined $level{$hostpart}) { $level{$hostpart} = $level; } $taper_started{$hostpart}=1; $taper_finished{$hostpart}=0; $taper_time{$hostpart}=$current_time; $ntchunk_size = 0; } elsif($line[6] eq "PORT-WRITE") { #7:handle 8:host 9:disk 10:level 11:datestamp 12:splitsize 13:diskbuffer 14:fallback_splitsize $serial=$line[7]; $host=$line[8]; $partition=$line[9]; $level=$line[10]; $ldatestamp=$line[11]; $hostpart=&make_hostpart($host,$partition,$ldatestamp); $serial{$serial}=$hostpart; $taper_started{$hostpart}=1; $taper_finished{$hostpart}=0; $taper_time{$hostpart}=$current_time; $ntchunk_size = 0; } } } elsif($line[1] eq "result" && $line[2] eq "time") { #print "result: " , $line[5] . " " . $line[6] . " " . $line[7] . "\n" if defined $line[5] && defined $line[6] && defined $line[7]; $current_time = $line[3]; if($line[5] =~ /dumper\d+/) { if($line[6] eq "FAILED" || $line[6] eq "TRY-AGAIN") { #7:handle 8:message $serial = $line[7]; $error = $line[8]; $hostpart=$serial{$serial}; $dump_finished{$hostpart}=-1; $busy_time{$line[5]}+=($current_time-$dump_time{$hostpart}); $running_dumper{$line[5]} = "0"; $dump_time{$hostpart}=$current_time; $error{$hostpart}="dumper: $error"; $dumpers_active--; } elsif($line[6] eq "DONE") { #7:handle 8:origsize 9:size ... $serial=$line[7]; $origsize=$line[8] / $unitdivisor; $outputsize=$line[9] / $unitdivisor; $hostpart=$serial{$serial}; $size{$hostpart}=$outputsize; $dump_finished{$hostpart}=1; $busy_time{$line[5]}+=($current_time-$dump_time{$hostpart}); $running_dumper{$line[5]} = "0"; $dump_time{$hostpart}=$current_time;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -