AFS-Monitor

 view release on metacpan or  search on metacpan

examples/xstat_cm_test  view on Meta::CPAN

#!/usr/bin/perl -w
#
# Copyright © 2004 Alf Wachsmann <alfw@slac.stanford.edu> and
#                  Elizabeth Cassell <e_a_c@mailsnare.net>
#
# $Revision: 1.8 $ $Date: 2006/05/31 16:22:51 $ $Author: alfw $
#

use blib;
use strict;
use AFS::Monitor qw(xstat_cm_test constant);
use Data::Dumper;

my @cmname = ("virtue.openafs.org", "andrew.e.kth.se");
my @collID = (0, 1, 2);

my @tests;      # choose which tests to run
$tests[1] = 1;  # test of cmname @cmname and collIDs @collID
$tests[2] = 0;  # test of cmname but no collID
$tests[3] = 0;  # test of single cmname with collID
$tests[4] = 0;  # test of single cmname but no single collID

my $all = 1;

my $showdump = 0;   # print entire contents of hash for each test
my $formatted = 1;  # print formatted like original xstat_cm_test program

print "# Starting now... #\n";
my $result;


if ($all || $tests[1]) {
  print "\n******** TEST 1: ********\n";

  print "\nxstat_cm_test -cmname ", join(" ", @cmname),
        " -collID ", join(" ", @collID), "\n\n";

  $result = xstat_cm_test(cmname => \@cmname,
                          collID => \@collID);
  parse_result($result);
}

if ($all || $tests[2]) {
  print "\n******** TEST 2: ********\n";

  print "\nxstat_cm_test -cmname ", join(" ", @cmname), "\n\n";

  $result = xstat_cm_test(cmname => \@cmname);
  parse_result($result);
}


if ($all || $tests[3]) {
  print "\n******** TEST 3: ********\n";

  print "\nxstat_cm_test -cmname ", $cmname[0],
                       " -collID 2\n\n";

  $result = xstat_cm_test(cmname => $cmname[0],
                          collID => 2);
  parse_result($result);
}


if ($all || $tests[4]) {
  print "\n******** TEST 4: ********\n";

  print "\nxstat_cm_test -cmname ", $cmname[0], "\n\n";

  $result = xstat_cm_test(cmname => $cmname[0]);
  parse_result($result);
}



sub parse_result {
  my $info = shift;

  if ($AFS::CODE) {
    print "Error case: ", ref($info), "\n" if (defined($info));
    # die("Error: AFS::CODE = $AFS::CODE (", ($AFS::CODE+0), ")\n");
    print "Error: AFS::CODE = $AFS::CODE (", ($AFS::CODE+0), ")\n";
    return;
  }

  if ($showdump) {
    local $Data::Dumper::Quotekeys = 0;
    local $Data::Dumper::Sortkeys = 1;
    local $Data::Dumper::Indent = 1;
    local $Data::Dumper::Maxdepth = 2;
    local $Data::Dumper::Varname = "xstat_cm_test";
    print Dumper($info);
  }

  if ($formatted) {
    foreach my $host (@$info) {
      if ($host->{probeOK} == 0) {
        printf("CM_Handler: Probe 1, collection %d to CM on '%s' failed\n",
                $host->{collectionNumber},
                $host->{hostName});
        return;
      }
      if ($host->{collectionNumber} == constant("AFSCB_XSTATSCOLL_CALL_INFO")) {
        PrintCallInfo($host);
      } elsif ($host->{collectionNumber} == constant("AFSCB_XSTATSCOLL_PERF_INFO")) {
        PrintPerfInfo($host);
      } elsif ($host->{collectionNumber} == constant("AFSCB_XSTATSCOLL_FULL_PERF_INFO")) {
        PrintFullPerfInfo($host);
      } else {
        printf "** Unknown collection: %d\n", $host->{collectionNumber};
      }
    }
  }
}


sub PrintPerfInfo {
  my $host = shift;

  printf("AFSCB_XSTATSCOLL_PERF_INFO (coll %d) for CM %s\n[Probe 1, %s]\n\n",
          $host->{collectionNumber},
          $host->{hostName},
          scalar localtime $host->{probeTime});

  PrintOverallPerfInfo($host->{data});
}


sub PrintFullPerfInfo {
  my $host = shift;

  printf("AFSCB_XSTATSCOLL_FULL_PERF_INFO (coll %d) for CM %s\n[Probe 1, %s]\n\n",
          $host->{collectionNumber},
          $host->{hostName},
          scalar localtime $host->{probeTime});

  print "Overall Performance Info:\n-------------------------\n";

  PrintOverallPerfInfo($host->{data}->{perf});

  print "\n";

  PrintRPCPerfInfo($host->{data}->{rpc});

  my $authentP = $host->{data}->{authent};
  print "\nAuthentication info:\n--------------------\n";

  printf("\t%d PAGS, %d records (%d auth, %d unauth), %d max in PAG, chain max: %d\n",
          $authentP->{curr_PAGs},
          $authentP->{curr_Records},
          $authentP->{curr_AuthRecords},

examples/xstat_cm_test  view on Meta::CPAN

  printf "\t%10d cacheMaxDirtyChunks\n", $perf->{cacheMaxDirtyChunks};
  printf "\t%10d cacheCurrDirtyChunks\n", $perf->{cacheCurrDirtyChunks};
  printf "\t%10d dcacheHits\n", $perf->{dcacheHits};
  printf "\t%10d vcacheHits\n", $perf->{vcacheHits};
  printf "\t%10d dcacheMisses\n", $perf->{dcacheMisses};
  printf "\t%10d vcacheMisses\n", $perf->{vcacheMisses};
  printf "\t%10d cacheFilesReused\n", $perf->{cacheFilesReused};
  printf "\t%10d vcacheXAllocs\n", $perf->{vcacheXAllocs};
  printf "\t%10d dcacheXAllocs\n", $perf->{dcacheXAllocs};

  printf "\t%10d bufAlloced\n", $perf->{bufAlloced};
  printf "\t%10d bufHits\n",	 $perf->{bufHits};
  printf "\t%10d bufMisses\n", $perf->{bufMisses};
  printf "\t%10d bufFlushDirty\n", $perf->{bufFlushDirty};

  printf "\t%10d LargeBlocksActive\n", $perf->{LargeBlocksActive};
  printf "\t%10d LargeBlocksAlloced\n", $perf->{LargeBlocksAlloced};
  printf "\t%10d SmallBlocksActive\n", $perf->{SmallBlocksActive};
  printf "\t%10d SmallBlocksAlloced\n", $perf->{SmallBlocksAlloced};
  printf "\t%10d OutStandingMemUsage\n", $perf->{OutStandingMemUsage};
  printf "\t%10d OutStandingAllocs\n", $perf->{OutStandingAllocs};
  printf "\t%10d CallBackAlloced\n", $perf->{CallBackAlloced};
  printf "\t%10d CallBackFlushes\n", $perf->{CallBackFlushes};
  printf "\t%10d CallBackLoops\n", $perf->{cbloops};

  printf "\t%10d srvRecords\n", $perf->{srvRecords};
  printf "\t%10d srvNumBuckets\n", $perf->{srvNumBuckets};
  printf "\t%10d srvMaxChainLength\n", $perf->{srvMaxChainLength};
  printf "\t%10d srvMaxChainLengthHWM\n", $perf->{srvMaxChainLengthHWM};
  printf "\t%10d srvRecordsHWM\n", $perf->{srvRecordsHWM};

  printf "\t%10d sysName_ID\n", $perf->{sysName_ID};

  print "\tFile Server up/downtimes, same cell:\n";
  PrintUpDownStats($perf->{fs_UpDown}->[0]);

  print "\tFile Server up/downtimes, diff cell:\n";
  PrintUpDownStats($perf->{fs_UpDown}->[1]);

  print "\tVL Server up/downtimes, same cell:\n";
  PrintUpDownStats($perf->{vl_UpDown}->[0]);

  print "\tVL Server up/downtimes, diff cell:\n";
  PrintUpDownStats($perf->{vl_UpDown}->[1]);
}


sub PrintUpDownStats {
  my $updown = shift;

  printf "\t\t%10d numTtlRecords\n",	$updown->{numTtlRecords};
  printf "\t\t%10d numUpRecords\n",	$updown->{numUpRecords};
  printf "\t\t%10d numDownRecords\n",	$updown->{numDownRecords};
  printf "\t\t%10d sumOfRecordAges\n",$updown->{sumOfRecordAges};
  printf "\t\t%10d ageOfYoungestRecord\n",$updown->{ageOfYoungestRecord};
  printf "\t\t%10d ageOfOldestRecord\n",$updown->{ageOfOldestRecord};
  printf "\t\t%10d numDowntimeIncidents\n",$updown->{numDowntimeIncidents};
  printf "\t\t%10d numRecordsNeverDown\n",$updown->{numRecordsNeverDown};
  printf "\t\t%10d maxDowntimesInARecord\n",$updown->{maxDowntimesInARecord};
  printf "\t\t%10d sumOfDowntimes\n",	$updown->{sumOfDowntimes};
  printf "\t\t%10d shortestDowntime\n",$updown->{shortestDowntime};
  printf "\t\t%10d longestDowntime\n",$updown->{longestDowntime};

  printf "\t\tDowntime duration distribution:\n";
  printf "\t\t\t%8d: 0 min .. 10 min\n",  $updown->{downDurations}->[0];
  printf "\t\t\t%8d: 10 min .. 30 min\n", $updown->{downDurations}->[1];
  printf "\t\t\t%8d: 30 min .. 1 hr\n",   $updown->{downDurations}->[2];
  printf "\t\t\t%8d: 1 hr .. 2 hr\n",     $updown->{downDurations}->[3];
  printf "\t\t\t%8d: 2 hr .. 4 hr\n",     $updown->{downDurations}->[4];
  printf "\t\t\t%8d: 4 hr .. 8 hr\n",     $updown->{downDurations}->[5];
  printf "\t\t\t%8d: > 8 hr\n",           $updown->{downDurations}->[6];

  printf "\t\tDowntime incident distribution:\n";
  printf "\t\t\t%8d: 0 times\n",        $updown->{downIncidents}->[0];
  printf "\t\t\t%8d: 1 time\n",         $updown->{downIncidents}->[1];
  printf "\t\t\t%8d: 2 .. 5 times\n",   $updown->{downIncidents}->[2];
  printf "\t\t\t%8d: 6 .. 10 times\n",  $updown->{downIncidents}->[3];
  printf "\t\t\t%8d: 10 .. 50 times\n", $updown->{downIncidents}->[4];
  printf "\t\t\t%8d: > 50 times\n",     $updown->{downIncidents}->[5];
}


sub PrintRPCPerfInfo {
  my $rpc = shift;

  print "FS Operation Timings:\n---------------------\n";
  foreach (sort keys %{$rpc->{fsRPCTimes}}) {
    printf "%15s: %d ops (%d OK); sum=%f, sqr=%f, min=%f, max=%f\n",
           $_,
           $rpc->{fsRPCTimes}->{$_}->{numOps}, $rpc->{fsRPCTimes}->{$_}->{numSuccesses},
           $rpc->{fsRPCTimes}->{$_}->{sumTime}, $rpc->{fsRPCTimes}->{$_}->{sqrTime},
           $rpc->{fsRPCTimes}->{$_}->{minTime}, $rpc->{fsRPCTimes}->{$_}->{maxTime};
  }

  print "\nError Info:\n-----------\n";
  foreach (sort keys %{$rpc->{fsRPCErrors}}) {
    printf "%15s: %d server, %d network, %d prot, %d vol, %d busies, %d other\n",
           $_,
           $rpc->{fsRPCErrors}->{$_}->{err_Server},
           $rpc->{fsRPCErrors}->{$_}->{err_Network},
           $rpc->{fsRPCErrors}->{$_}->{err_Protection},
           $rpc->{fsRPCErrors}->{$_}->{err_Volume},
           $rpc->{fsRPCErrors}->{$_}->{err_VolumeBusies},
           $rpc->{fsRPCErrors}->{$_}->{err_Other};
  }

  print "\nTransfer timings:\n-----------------\n";
  foreach (sort keys %{$rpc->{fsXferTimes}}) {
    printf "%s: %d xfers (%d OK), time sum=%f, sqr=%f, min=%f, max=%f\n",
           $_,
           $rpc->{fsXferTimes}->{$_}->{numXfers}, $rpc->{fsXferTimes}->{$_}->{numSuccesses},
           $rpc->{fsXferTimes}->{$_}->{sumTime},
           $rpc->{fsXferTimes}->{$_}->{sqrTime},
           $rpc->{fsXferTimes}->{$_}->{minTime},
           $rpc->{fsXferTimes}->{$_}->{maxTime};

    printf "\t[bytes: sum=%d, min=%d, max=%d]\n",
           $rpc->{fsXferTimes}->{$_}->{sumBytes},
           $rpc->{fsXferTimes}->{$_}->{minBytes},
           $rpc->{fsXferTimes}->{$_}->{maxBytes};



( run in 1.304 second using v1.01-cache-2.11-cpan-39bf76dae61 )