#!/usr/bin/perl # # filerops: Gather statistics on NetApp filers use strict; use warnings; use File::Basename; use Getopt::Long; sub usage { my $script = basename($0); print <<USAGE $script -f <filer> -i <minutes> <-n|-s> [-o] -f <filer> filer to gather stats from -h this elite help menu, hack the planet -i <min> interval in minutes before gathering data -n gather nfsops statistics netapp: nfsstat -o show highest nfsops offender -s gather filer statistics netapp: stats examples: $script -f <filer> -i 10 -n $script -f <filer> -i 1 -n -s $script -f <filer> -i 5 -n -o -s NOTE: This script assumes ssh agent forwarding is enabled. USAGE ; exit 0; } my $opts = {}; GetOptions($opts, 'filer|f=s', 'help|h', 'interval|i=i', 'offender|o', 'nfsops|n', 'stats|s', ) or usage; usage if (exists($opts->{'help'})); usage if (not exists($opts->{'filer'})); usage if (not exists($opts->{'interval'})); usage if ((not exists($opts->{'nfsops'})) && (not exists($opts->{'stats'}))); my $keys = `/usr/bin/ssh-add -l 2>&1`; if ($? != 0) { print STDERR "ERROR: No ssh keys loaded.\n\n"; usage; } my $interval = $opts->{'interval'}; my $filer = $opts->{'filer'}; if ((exists($opts->{'nfsops'})) || (exists($opts->{'stats'}))) { print "\n"; if (exists($opts->{'nfsops'})) { my $nfsops = `/usr/bin/ssh -a root\@$filer 'nfsstat -z'`; if ( $nfsops ne '' ) { print STDERR "ERROR: Unable to clear nfsops table, exiting.\n"; exit 1; } print "Filer nfsops cleared.\n"; } if (exists($opts->{'stats'})) { my $stats = ''; my $x = 0; while (defined($stats)) { $stats = `/usr/bin/ssh -a root\@$filer 'stats stop' 2>&1`; print "Statistics currently gathering ($1), attempting another stop.\n" if ( $stats =~ m/StatisticsID:\ (.*)/ ); last if ( $stats =~ m/No background stats are currently running/ ); if ($x == 5) { print STDERR "ERROR: Unable to clear stats table, exiting.\n"; exit 1; } $x++; } print "Filer statistics cleared.\n"; $stats = `/usr/bin/ssh -a root\@$filer 'stats start' 2>&1`; my $id = $1 if ( $stats =~ m/Stats identifier name is '(.*)'/ ); if (not defined($id)) { print STDERR "ERROR: Unable to start statistic gathering, exiting\n"; exit 1; } print "Filer statistic gathering has initiated (id: $id).\n"; } sleep ($interval * 60); if (exists($opts->{'nfsops'})) { my $offender = $opts->{'offender'}; my @lines = `/usr/bin/ssh -a root\@$filer 'nfsstat -l'`; if ( scalar(@lines) < 1 ) { print STDERR "ERROR: Unable to gather nfsops, exiting.\n"; exit 1; } my $nfshost; my $nfsho = 0; my @nfsops = (); print "\n"; foreach my $line (@lines) { print $line; my @values = split(' ', $line); if ( $line !~ m/<hostname unknown>/ ) { push(@nfsops, $values[4]); if ($values[4] > $nfsho) { $nfsho = $values[4]; $nfshost = $values[1]; } } else { push(@nfsops, $values[5]); if ($values[5] > $nfsho) { $nfsho = $values[5]; $nfshost = "<hostname unknown>"; } } } print "\n"; my $total = 0; foreach my $nfsop (@nfsops) { $total += $nfsop; } print "Highest nfsop offender: $nfshost\n" if (defined($offender)); print "Total nfsops: $total\n"; } if (exists($opts->{'stats'})) { my %shash; my @lines = `/usr/bin/ssh -a root\@$filer 'stats stop'`; if ( scalar(@lines) < 1 || $lines[0] !~ m/StatisticsID:/ ) { print STDERR "ERROR: Unable to gather statistics, exiting.\n"; exit 1; } print "\nFiler statistics cleared (id: $1).\n" if ( $lines[0] =~ m/StatisticsID:\ (.*)/ ); foreach my $line (@lines) { next if ( $line !~ m/^(volume|nfsv3|ifnet)/ ); my @data = split(':', $line); my $key = join(':', $data[0], $data[1]); my $ops = join(':', $data[2], $data[3]); push(@{$shash{$key}}, $ops); } print "\n"; foreach my $key (sort keys %shash) { my ($major, $minor) = split(':', $key); print uc($major) . ": $minor (average)\n\n"; foreach my $op (@{$shash{$key}}) { my ($desc, $value) = split(':', $op); $desc =~ s/_/\ /g; chomp $value; print "\t$desc: $value\n"; my ($num, $rate) = split('/', $value) if ($value =~ m/\//); if (defined($rate)) { my $b = undef; if ($num =~ m/b$/) { $num =~ s/b$//g; $b = 'b'; } my $total = ($num * ($interval * 60)); print "\t$desc: $total"; print $b if (defined($b)); print " in $interval minutes\n"; } } print "\n"; } } } exit 0;
Today is: 8 January, 2012
Check todays hot topics