Solaris

 view release on metacpan or  search on metacpan

scripts/iost+  view on Meta::CPAN

#!/usr/local/bin/perl -w

use strict;
use Solaris::MapDev qw(inst_to_dev);
use Solaris::Kstat;
use POSIX qw(uname strftime);

################################################################################

sub ns($$)
{
my ($val, $width) = @_;
my $prec = $width - length(int($val)) - 1;
return(sprintf("%*.*f ", $width, $prec, $val));
}

################################################################################
# Main

my ($interval, $count) = @ARGV;
$interval = 5 if (! defined($interval) || $interval < 1);
$count = -1 if (! $count);

$SIG{INT} = $SIG{QUIT} = $SIG{HUP} = sub { $count = 0; };

my @modules = qw(sd ssd nfs dad atapicd st fd);
my ($mod, $inst, $kstats, $modinst, $dev, $then, $now, %stats, %totals, $io);
my $ks = Solaris::Kstat->new();

# Save initial stats values
print("iost+ started on ", strftime("%d/%m/%Y %T", localtime()),
      " on ", (uname())[1], ", sample interval $interval seconds\n\n");
foreach $mod (@modules)
   {
   $kstats = $ks->{$mod};
   foreach $inst (keys(%{$kstats}))
      {
      $modinst = "$mod$inst";
      next if (! exists($kstats->{$inst}{$modinst}));
      $dev = inst_to_dev($modinst) || $modinst;
      %{$then->{$dev}} = %{$kstats->{$inst}{$modinst}};
      }
   }

# Loop the required number of times
while ($count == -1 || $count-- > 0)
   {
   # Wait for a bit, then update the stats
   sleep($interval);
   $ks->update();
   my $ts = strftime("%T", localtime());

   # Copy the new stats values
   foreach $mod (@modules)
      {
      $kstats = $ks->{$mod};
      foreach $inst (keys(%{$kstats}))
         {
         $modinst = "$mod$inst";
         next if (! exists($kstats->{$inst}{$modinst}));
         $dev = inst_to_dev($modinst) || $modinst;
         %{$now->{$dev}} = %{$kstats->{$inst}{$modinst}};
         }
      }

   # Calculate the delta stats
   %stats = ();
   %totals = ();
   $io = 0;
   foreach $dev (keys(%{$then}))



( run in 2.094 seconds using v1.01-cache-2.11-cpan-524268b4103 )