require "newgetopt.pl";
use Time::Local;
+delete @ENV{'IFS', 'CDPATH', 'ENV', 'BASH_ENV', 'PATH'};
+$ENV{'PATH'} = "/usr/bin:/usr/sbin:/sbin:/bin";
+
$confdir="@CONFIG_DIR@";
$prefix='@prefix@';
$prefix=$prefix; # avoid warnings about possible typo
$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 ) {
}
+if ( ! -e "$confdir/$conf" ) {
+ print "Configuration directory '" . $confdir/$conf . "' doesn't exist\n";
+ exit 1;
+}
if ( ! -d "$confdir/$conf" ) {
- die "amstatus$suf: could not find directory $confdir/$conf";
+ print "Configuration directory '" . $confdir/$conf . "' is not a directory\n";
+ exit 1;
}
-$oldPATH = $ENV{'PATH'};
-$ENV{'PATH'} = "/bin:/usr/bin:/usr/sbin:/sbin"; # force known path
-
$pwd = `pwd`;
chomp $pwd;
chdir "$confdir/$conf";
}
$unit=`$sbindir/amgetconf$suf displayunit`;
-$ENV{'PATH'} = $oldPATH;
chomp($unit);
$unitdivisor=1;
if($unit eq 'K') {
$ntsize{$nb_tape} = 0;
$ntesize{$nb_tape} = 0;
$tape_size = 0;
+$driver_finished = 0;
while(<AMDUMP>) {
chomp;
if(/(amdump|amflush): start at (.*)/) {
print " from $2\n";
- $starttime=&unctime(split(/[ ]+/,$2));
}
- elsif(/amdump: datestamp (\S+)/) {
- $gdatestamp = $1;
+ elsif(/(amdump|amflush): datestamp (\S+)/) {
+ $gdatestamp = $2;
if(!defined $datestamp{$gdatestamp}) {
$datestamp{$gdatestamp} = 1;
push @datestamp, $gdatestamp;
}
+ $starttime=&set_starttime($2);
+ }
+ elsif(/(amdump|amflush): starttime (\S+)/) {
+ $starttime=&set_starttime($2);
}
elsif(/planner: timestamp (\S+)/) {
$gdatestamp = $1;
$taper_started{$hostpart}=1;
$taper_finished{$hostpart}=0;
$taper_time{$hostpart}=$1;
+ $ntchunk_size = 0;
}
#features (maybe missing features)
elsif(/driver: send-cmd time (\S+) to taper: FILE-WRITE (\d+-\d+) (\S+) (\S+) (\S*) (\S+) (\d*) (\S+)/){
$taper_started{$hostpart}=1;
$taper_finished{$hostpart}=0;
$taper_time{$hostpart}=$1;
+ $ntchunk_size = 0;
}
elsif(/driver: send-cmd time (\S+) to taper: PORT-WRITE (\d+-\d+) (\S+) (\S+) \d+( \d+|)/){
$current_time=$1;
$taper_started{$hostpart}=1;
$taper_finished{$hostpart}=0;
$taper_time{$hostpart}=$1;
+ $ntchunk_size = 0;
}
elsif(/driver: send-cmd time (\S+) to taper: PORT-WRITE (\d+-\d+) (\S+) (\S+) (\S+) \d+ \d+/){
$current_time=$1;
$taper_started{$hostpart}=1;
$taper_finished{$hostpart}=0;
$taper_time{$hostpart}=$1;
+ $ntchunk_size = 0;
}
elsif(/driver: result time (\S+) from taper: (DONE|PARTIAL) (\d+-\d+) (\S+) (\d+) "?\[sec (\S+) kb (\d+) kps/) {
$current_time=$1;
$size{$hostpart}=$size;
}
$ntpartition{$nb_tape}++;
- $ntsize{$nb_tape} += $size{$hostpart};
+ $ntsize{$nb_tape} += $size{$hostpart} - $ntchunk_size;
if(defined $esize{$hostpart} && $esize{$hostpart} > 1) {
- $ntesize{$nb_tape} += $esize{$hostpart};
+ $ntesize{$nb_tape} += $esize{$hostpart} - $ntchunk_size;
}
else {
- $ntesize{$nb_tape} += $size{$hostpart};
+ $ntesize{$nb_tape} += $size{$hostpart} - $ntchunk_size;
}
if ($3 eq "PARTIAL") {
$partial{$hostpart} = 1;
else {
$partial{$hostpart} = 0;
}
+ if($ntchunk_size > 0) {
+ $ntchunk{$nb_tape}++;
+ }
}
elsif(/driver: result time (\S+) from taper: (TRY-AGAIN|TAPE-ERROR) (\d+-\d+) (.+)/) {
$current_time=$1;
$ntpartition{$nb_tape} = 0;
$ntsize{$nb_tape} = 0;
$ntesize{$nb_tape} = 0;
+ $ntchunk{$nb_tape} = 0;
+ }
+ elsif(/splitting chunk that started at \d*kb after (\d*)kb/) {
+ $ntchunk{$nb_tape}++;
+ $ntsize{$nb_tape} += $1;
+ $ntesize{$nb_tape} += $1;
+ $ntchunk_size += $1;
+ }
+ elsif(/driver: FINISHED/) {
+ $driver_finished = 1;
}
else {
#print "Ignoring: $_\n";
printf "%-${maxnamelength}s%2d", "$host:$partition", $level{$hostpart};
printf " no estimate\n";
}
+ $exit_status |= $STATUS_FAILED;
$fpartition++;
+ $fsize+=$esize{$hostpart};
}
}
else {
$desize += $esize{$hostpart};
}
if(defined $dump_started{$hostpart} &&
- $dump_started{$hostpart} == 1 &&
+ $dump_started{$hostpart} == 1 &&
+ $dump_finished{$hostpart} == -1) {
+ if(defined $opt_failed) {
+ printf "%8s ", $datestamp if defined $opt_date;
+ printf "%-${maxnamelength}s%2d", "$host:$partition", $level{$hostpart};
+ printf "%9d$unit", $esize{$hostpart};
+ print " dump to tape failed: " . $error{$hostpart};
+ print "\n";
+ }
+ $exit_status |= $STATUS_FAILED;
+ $fpartition++;
+ $fsize+=$esize{$hostpart};
+ }
+ elsif(defined $dump_started{$hostpart} &&
+ $dump_started{$hostpart} == 1 &&
$dump_finished{$hostpart} == 0 &&
$taper_started{$hostpart} == 1) {
if( defined $opt_dumpingtape ) {
}
print "\n";
}
+ $exit_status |= $STATUS_TAPE;
$tfpartition++;
$tfsize += $xsize;
if( defined $starttime ) {
print " (", &showtime($taper_time{$hostpart}), ")";
}
- print ", PARTIAL" if defined $partial{$hostpart} &&
- $partial{$hostpart} == 1;
+ if(defined $partial{$hostpart} && $partial{$hostpart} == 1) {
+ print ", PARTIAL";
+ $exit_status |= $STATUS_FAILED;
+ }
print "\n";
}
$tpartition++;
printf "%-${maxnamelength}s%2d", "$host:$partition", $level{$hostpart};
printf " " . $error{$hostpart} . "\n";
}
+ $exit_status |= $STATUS_FAILED;
+
$fpartition++;
$fsize+=$esize{$hostpart};
}
printf "%9d$unit", $esize{$hostpart};
print " wait for dumping $error{$hostpart}\n";
}
+ if($driver_finished == 1) {
+ $exit_status |= $STATUS_MISSING;
+ }
$wpartition++;
$wsize += $esize{$hostpart};
}
}
print "\n";
}
+ $exit_status |= $STATUS_FAILED;
$fpartition++;
$fsize+=$esize{$hostpart};
}
print " (", &showtime($dump_time{$hostpart}), ")";
}
print ", wait for writing to tape";
- print ", PARTIAL" if defined $partial{$hostpart} &&
- $partial{$hostpart} == 1;;
+ if(defined $partial{$hostpart} && $partial{$hostpart} == 1) {
+ print ", PARTIAL";
+ $exit_status |= $STATUS_FAILED;
+ }
print "\n";
}
$dpartition++;
printf "%-${maxnamelength}s%2d", "$host:$partition", $level{$hostpart};
printf "%9d$unit", $size{$hostpart};
print " waiting to flush";
- print ", PARTIAL" if defined $partial{$hostpart} &&
- $partial{$hostpart} == 1;
+ if(defined $partial{$hostpart} && $partial{$hostpart} == 1) {
+ print ", PARTIAL";
+ $exit_status |= $STATUS_FAILED;
+ }
print "\n";
}
$wfpartition++;
if($nb_tape > 1 || $tape_size != 0) {
for($i=1; $i <= $nb_tape; $i++) {
if($tape_size != 0) {
- printf " tape %-3d : %3d %9d$unit %9d$unit (%6.2f%%) %s\n",
+ printf " tape %-3d : %3d %9d$unit %9d$unit (%6.2f%%) %s",
$i, $ntpartition{$i}, $ntsize{$i}, $ntesize{$i}, 100*$ntsize{$i}/$tape_size, $ntlabel{$i};
+ if($ntchunk{$i} > 0) {
+ printf " (%d chunks)", $ntchunk{$i};
+ }
+ print "\n";
}
else {
printf " tape %-3d : %3d %9d$unit %9d$unit %s\n",
}
}
+exit $exit_status;
+
sub make_hostpart() {
local($host,$partition,$datestamp) = @_;
return $time;
}
+sub set_starttime() {
+ my (@tl);
+ my ($time);
+ my ($date);
+
+ # Preset an array of values in case some parts are not passed as
+ # arguments. This lets the date, etc, be omitted and default to
+ # today.
+
+ ($date)=@_;
+ @tl = localtime;
+
+ $tl[5] = substr($date, 0, 4) if(length($date) >= 4);
+ $tl[4] = substr($date, 4, 2)-1 if(length($date) >= 6);
+ $tl[3] = substr($date, 6, 2) if(length($date) >= 8);
+ $tl[2] = substr($date, 8, 2) if(length($date) >= 10);
+ $tl[1] = substr($date, 10, 2) if(length($date) >= 12);
+ $tl[0] = substr($date, 12, 2) if(length($date) >= 14);
+
+ $time = &timelocal (@tl);
+
+ return $time;
+}
+
sub showtime() {
my($delta)=shift;
my($oneday)=24*60*60;