retire da-backup checks
[mirror/dsa-nagios.git] / dsa-nagios-checks / checks / dsa-check-afs-rxdebug
1 #!/usr/bin/perl -w
2 $ID = q$Id: check_rxdebug,v 1.11 2006/03/17 23:06:54 quanah Exp $;
3 #
4 # check_rxdebug -- Nagios AFS server check for waiting connections.
5 #
6 # Written by Quanah Gibson-Mount based on work by Neil Crellin
7 # Updated by Russ Allbery <rra@stanford.edu>
8 # Copyright 2003, 2004, 2005 Board of Trustees, Leland Stanford Jr. University
9 #
10 # This program is free software; you may redistribute it and/or modify it
11 # under the same terms as Perl itself.
12 #
13 # Expects a file server with the -H option and runs rxdebug against that file
14 # server, looking for any connections that are waiting for a thread.  Exits
15 # with status 1 if there are more than two connections in that state (a
16 # warning) and with status 2 if there are more than eight connections in that
17 # state.  The thresholds can be overridden from the command line.
18
19 ##############################################################################
20 # Site configuration
21 ##############################################################################
22
23 # The default count of blocked connections at which to warn or send a critical
24 # alert.  These can be overridden with the -w and -c command-line options.
25 $WARNINGS = 2;
26 $CRITICAL = 8;
27
28 # The default timeout in seconds (implemented by alarm) for rxdebug.
29 $TIMEOUT = 60;
30
31 # The full path to rxdebug.  Make sure that this is on local disk so that
32 # monitoring doesn't have an AFS dependency.
33 ($RXDEBUG) = grep { -x $_ } qw(/usr/bin/rxdebug /usr/local/bin/rxdebug);
34 $RXDEBUG ||= '/usr/bin/rxdebug';
35
36 ##############################################################################
37 # Modules and declarations
38 ##############################################################################
39
40 require 5.003;
41
42 use strict;
43 use vars qw($CRITICAL $ID $RXDEBUG $TIMEOUT $WARNINGS);
44
45 use Getopt::Long qw(GetOptions);
46
47 ##############################################################################
48 # Implementation
49 ##############################################################################
50
51 # Parse command line options.
52 my ($help, $host, $version);
53 Getopt::Long::config ('bundling', 'no_ignore_case');
54 GetOptions ('critical|c=i' => \$CRITICAL,
55             'hostname|H=s' => \$host,
56             'help|h'       => \$help,
57             'timeout|t=i'  => \$TIMEOUT,
58             'version|V'    => \$version,
59             'warning|w=i'  => \$WARNINGS) or exit 3;
60 if ($help) {
61     print "Feeding myself to perldoc, please wait....\n";
62     exec ('perldoc', '-t', $0) or die "Cannot fork: $!\n";
63 } elsif ($version) {
64     my $version = join (' ', (split (' ', $ID))[1..3]);
65     $version =~ s/,v\b//;
66     $version =~ s/(\S+)$/($1)/;
67     $version =~ tr%/%-%;
68     print $version, "\n";
69     exit 0;
70 }
71 if (@ARGV) {
72     warn "Usage: $0 [-hv] [-c <level>] [-w <level>] -H <host>\n";
73     exit 3;
74 }
75 if ($WARNINGS > $CRITICAL) {
76     warn "$0: warning level $WARNINGS greater than critical level $CRITICAL\n";
77     exit 3;
78 }
79
80 # Set up the alarm.
81 $SIG{ALRM} = sub {
82     print "AFS CRITICAL - network timeout after $TIMEOUT seconds\n";
83     exit 2;
84 };
85 alarm ($TIMEOUT);
86
87 # Run rxdebug and parse the output, counting the number of waiting for process
88 # connections that we have.
89 unless (open (RXDEBUG, "$RXDEBUG $host -noconn |")) {
90     warn "$0: cannot run rxdebug\n";
91     exit 3;
92 }
93 my $blocked;
94 while (<RXDEBUG>) {
95     if (/^(\d+) calls waiting for a thread/) {
96         $blocked = $1;
97         last;
98     }
99 }
100 close RXDEBUG;
101 if ($? != 0) {
102     print "AFS CRITICAL - cannot contact server\n";
103     exit 2;
104 }
105 unless (defined $blocked) {
106     print "AFS CRITICAL - cannot parse rxdebug output\n";
107     exit 2;
108 }
109
110 # Check the connection count against our limits and make sure that it's okay.
111 if ($blocked >= $CRITICAL) {
112     print "AFS CRITICAL - $blocked blocked connections\n";
113     exit 2;
114 } elsif ($blocked >= $WARNINGS) {
115     print "AFS WARNING - $blocked blocked connections\n";
116     exit 1;
117 } else {
118     print "AFS OK - $blocked blocked connections\n";
119     exit 0;
120 }
121
122 ##############################################################################
123 # Documentation
124 ##############################################################################
125
126 =head1 NAME
127
128 check_rxdebug - Check AFS servers for blocked connections in Nagios
129
130 =head1 SYNOPSIS
131
132 check_rxdebug [B<-hV>] [B<-c> I<threshold>] [B<-w> I<threshold>]
133 [B<-t> I<timeout>] B<-H> I<host>
134
135 =head1 DESCRIPTION
136
137 B<check_rxdebug> is a Nagios plugin for checking AFS file servers to see if
138 there are client connections waiting for a free thread.  If there are more
139 than a few of these, AFS performance tends to be very slow; this is a fairly
140 reliable way to catch overloaded file servers.  By default, B<check_rxdebug>
141 returns a critical error if there are more than eight connections waiting
142 for a free thread and a warning if there are more than two.  These
143 thresholds can be changed with the B<-c> and B<-w> options.
144
145 B<check_rxdebug> will always print out a single line of output including the
146 number of blocked connections, displaying whether this is critical, a
147 warning, or okay.
148
149 =head1 OPTIONS
150
151 =over 4
152
153 =item B<-c> I<threshold>, B<--critical>=I<threshold>
154
155 Change the critical blocked connection count threshold to I<threshold>,
156 which should be an integer.  The default is 8.
157
158 =item B<-H> I<host>, B<--hostname>=I<host>
159
160 The AFS file server whose connections B<check_rxdebug> should check.  This
161 option is required.
162
163 =item B<-h>, B<--help>
164
165 Print out this documentation (which is done simply by feeding the script
166 to C<perldoc -t>).
167
168 =item B<-t> I<timeout>, B<--timeout>=I<timeout>
169
170 Change the timeout for the B<rxdebug> command.  The default timeout is 60
171 seconds.
172
173 =item B<-V>, B<--version>
174
175 Print out the version of B<check_rxdebug> and quit.
176
177 =item B<-w> I<threshold>, B<--warning>=I<threshold>
178
179 Change the warning blocked connection threshold to I<threshold>, which
180 should be an integer.  The default is 2.
181
182 =back
183
184 =head1 EXIT STATUS
185
186 B<check_rxdebug> follows the standard Nagios exit status requirements.  This
187 means that it will exit with status 0 if there are no problems, with status
188 1 if there is a warning, and with status 2 if there is a critical problem.
189 For other errors, such as invalid syntax, B<check_rxdebug> will exit with
190 status 3.
191
192 =head1 BUGS
193
194 The standard B<-v> verbose Nagios plugin option is not supported, although
195 it's not entirely clear what it would add.
196
197 The usage message for invalid options and for the B<-h> option doesn't
198 conform to Nagios standards.
199
200 =head1 CAVEATS
201
202 This script does not use the Nagios util library or any of the defaults that
203 it provides, which makes it somewhat deficient as a Nagios plugin.  This is
204 intentional, though, since this script can be used with other monitoring
205 systems as well.  It's not clear what a good solution to this would be.
206
207 =head1 SEE ALSO
208
209 The current version of this and other AFS monitoring plugins for Nagios are
210 available from the AFS monitoring tools page at
211 L<http://www.eyrie.org/~eagle/software/afs-monitor/>.
212
213 =head1 AUTHORS
214
215 The original idea behind this script was from Neil Crellin.  It was updated
216 by Quanah Gibson-Mount to work with Nagios, and then further updated by Russ
217 Allbery <rra@stanford.edu> to support more standard options and to use a
218 more uniform coding style.
219
220 =head1 COPYRIGHT AND LICENSE
221
222 Copyright 2003, 2004, 2005 Board of Trustees, Leland Stanford Jr. University.
223
224 This program is free software; you may redistribute it and/or modify it
225 under the same terms as Perl itself.
226
227 =cut