Since most of my Virtual Infrastructure runs on NFS datastores I like to keep a very close eye on what’s going on inside the NetApp. I generally use Cacti for long term monitoring of the status of the datastores and the NetApp as a whole.
However, when I want to see what’s going on in less than five minute increments, Cacti is pretty much useless. I wrote this script a while ago so that if I feel that latency is becoming a problem, I can check it right away and see it in frequent intervals.
Most often I use this script when Nagios starts to chirp at me. I use a slightly modified version of this script with Nagios and have it alert when latency gets out of hand. I then use this script to get a good look at what’s going on.
The OnTAP SDK is almost as entertaining to work with as VMware’s…
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 |
#!/usr/bin/perl -w # # na-realtime-nfs-latency.pl - written by Andrew Sullivan, 2009-06-23 # # Please report bugs and request improvements at http://practical-admin.com/blog/?p=758 # # I wanted a way to see the realtime nfs latency as reported by a NetApp # appliance. This perl script uses the OnTAP SDK to query the NetApp for # the performance stats and display back the latency and operations performed. # # The latency is found by measuring the total latency and total ops at two # intervals. The first set of values is subtracted from the second, and then # the ops are divided into the total latency giving us average latency. # # Examples: # This will query the appliance every 15 seconds to display the latency. I don't # provide a password because it will ask for one if it's not provided. # na-realtime-nfs-latency.pl --hostname toaster --username not_root --interval 10 # # Same as above, but with the abbreviated options # na-realtime-nfs-latency.pl -H toaster -u not_root -i 10 # # TODO: # Modify to work for all versions of NFS, not just 3 # # I placed the NetApp perl modules into my perl lib directory, however, # if you haven't done this, you will probably need to specify where they # are using a lib declaration #use lib "NetApp"; use NaServer; use NaElement; use Getopt::Long qw(:config no_ignore_case); main( ); sub main { my $opts = parse_options(); my $server = get_filer( $opts->{ 'hostname' }, $opts->{ 'username' }, $opts->{ 'password' } ); # print a nice header printf '%14s %10s %14s %10s', "Read Latency", "Read Ops", "Write Latency", "Write Ops"; print "n" . "-" x 14 . " " . "-" x 10 . " " . "-" x 14 . " " . "-" x 10 . "n"; # initialize the first data set my $first = get_latency( $server ); while (1) { # zeroize the counters my $nfs_read_latency = 0; my $nfs_write_latency = 0; my $nfs_read_ops = 0; my $nfs_write_ops = 0; # wait the specified amount sleep $opts->{ 'interval' }; # gather the second set of values my $second = get_latency( $server ); # check to make sure we don't divide by zero if ($second->{'avg_read_latency_base'} > $first->{'avg_read_latency_base'}) { $nfs_read_ops = $second->{'avg_read_latency_base'} - $first->{'avg_read_latency_base'}; $nfs_read_latency = ($second->{'read_latency'} - $first->{'read_latency'}) / $nfs_read_ops; } if ($second->{'avg_write_latency_base'} > $first->{'avg_write_latency_base'}) { $nfs_write_ops = $second->{'avg_write_latency_base'} - $first->{'avg_write_latency_base'}; $nfs_write_latency = ($second->{'write_latency'} - $first->{'write_latency'}) / $nfs_write_ops; } # print the data printf '%11.2f ms %10i %11.2f ms %10i', $nfs_read_latency / 1000, $nfs_read_ops, $nfs_write_latency / 1000, $nfs_write_ops; print "n"; # shift our values $first = $second; } } ### Supporting subroutines ### # # Prints the usage information # sub print_usage { print <<EOL Missing or incorrect arguments! na-realtime-nfs-latency.pl --hostname|-H --username|-u [ --password|-p ] [ --interval|-i ] na-realtime-nfs-latency.pl --help|-h It is not necessary to supply a password during the command line call. If it is not provided, it will be asked for. EOL } # # Defines and parses the options from the command line, also # checks to make sure that options are valid. Will prompt for # a password if one is not provided. # sub parse_options { my %options = ( 'hostname' => '', 'username' => '', 'password' => '', 'interval' => 30, 'help' => 0 ); GetOptions( %options, 'hostname|H=s', 'username|u=s', 'password|p:s', 'interval|i:i', 'help|h' ); if (! $options{ 'hostname' } || ! $options{ 'username' } || $options{ 'help' }) { print_usage(); exit(1); } if (! $options{ 'password' }) { print "Enter password: "; if ( $^O eq "MSWin32" ) { require Term::ReadKey; Term::ReadKey->import( qw(ReadMode) ); Term::ReadKey->import( qw(ReadLine) ); ReadMode('noecho'); chomp( $options{ 'password' } = ReadLine(0) ); ReadMode('normal'); } else { system("stty -echo") and die "ERROR: stty failedn"; chomp ( $options{ 'password' } = ); system("stty echo") and die "ERROR: stty failedn"; } print "n"; } return %options; } # # Creates the NaServer object # sub get_filer { my ($hostname, $username, $password) = @_; my $s = NaServer->new($hostname, 1, 7); $s->set_style(LOGIN_PASSWORD); $s->set_admin_user($username, $password); $s->set_transport_type(NA_SERVER_TRANSPORT_HTTP); return $s; } # # Queries the NetApp and returns a hash of responses # sub get_latency { my $server = shift; my $return = {}; my $request = build_request(); my $result = $server->invoke_elem( $request ); foreach ($result->child_get('instances')->child_get('instance-data')->child_get('counters')->children_get()) { my $name = $_->child_get_string('name'); $name =~ s/nfsv[2|3|4]_//; $return->{ $name } = $_->child_get_string('value'); } return $return; } # # creates the NaElement tree for querying latency # sub build_request { my $request = NaElement->new('perf-object-get-instances'); $request->child_add_string('objectname', 'nfsv3'); my $counters = NaElement->new('counters'); $counters->child_add_string('counter', 'nfsv3_read_latency'); $counters->child_add_string('counter', 'nfsv3_write_latency'); $counters->child_add_string('counter', 'nfsv3_avg_read_latency_base'); $counters->child_add_string('counter', 'nfsv3_avg_write_latency_base'); $request->child_add( $counters ); return $request; } |