forked from inuits/monitoring-plugins
-
Notifications
You must be signed in to change notification settings - Fork 0
/
check_drbd
executable file
·346 lines (248 loc) · 7.16 KB
/
check_drbd
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
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
#!/usr/bin/perl
=head1 NAME
check_drbd - Nagios plugin for DRBD
=head1 SYNOPSIS
B<check_drbd> [B<--verbose> | B<-v>]
=head1 DESCRIPTION
B<check_drbd> is a Nagios plugin for DRBD. It checks the connection state,
resource roles and disk states for every configured DRBD resource, and
produces a WARNING or CRITICAL alert if anything is amiss. The states
of both the local and remote sides of each connection are monitored.
=head2 Nagios status information
The status information emitted by this plugin is similar to the information
in F</proc/drbd>:
drbd0: Connected Primary/Secondary UpToDate/UpToDate
| | | | | |
| | | | | Remote disk state
| | | | Local disk state
| | | Remote resource role
| | Local resource role
| Connection state
DRBD device
If more than one device is present, and all devices are OK, the output is
summarised:
drbd0: PriConUpT, drbd1: SecConUpT
If any devices are not OK, the output contains their statuses in full.
=head2 Nagios performance data
Complete performance data is emitted for all configured DRBD resources:
=over
=item drbdI<*>_ns
=item drbdI<*>_nr
The volume of network data sent to and received from the peer, in kiB.
=item drbdI<*>_dw
=item drbdI<*>_dr
The volume of network data written to and read from the local disk, in kiB.
=item drbdI<*>_al
The number of updates of the activity log area of the metadata.
=item drbdI<*>_lo
The number of open requests to the local I/O subsystem issued by DRBD.
=item drbdI<*>_pe
The number of requests sent to the peer but not yet been answered by the latter.
=item drbdI<*>_ua
The number of requests received by the peer but not yet been answered by the latter.
=item drbdI<*>_ap
The number of block I/O requests forwarded by DRBD, but not yet answered by DRBD.
=item drbdI<*>_ep
The number of epoch objects.
=item drbdI<*>_oos
The amount of storage currently out-of-sync, in kiB.
=back
=head1 OPTIONS
=over
=item B<-v>, B<--verbose>
Increase the verbosity of the output messages. This disables the Nagios status
information summarisation described above: all resources' statuses are printed
in full.
=back
=head1 EXIT STATUS
=over
=item 0
All resources are OK.
=item 1
Some resources are not OK, but do not need immediate attention.
=item 2
Some resources are not OK and need immediate attention.
=item 3
An error occurred while collecting the resources' statuses.
=back
=head1 FILES
F</proc/drbd>
=head1 SEE ALSO
L<The DRBD Home Page|http://www.drbd.org/>
=cut
use strict;
use warnings;
use constant BASENAME => ($0 =~ m{.*/([^/]+)})[0] || 'check_drbd';
use constant STATE_FILE => '/proc/drbd';
use constant {
OK => 0,
WARNING => 1,
CRITICAL => 2,
UNKNOWN => 3,
};
use Getopt::Long;
use IO::File;
sub help;
sub usage;
sub perfdata;
sub ok;
sub warning;
sub critical;
sub unknown;
sub get_state;
$SIG{__DIE__} = sub {
die @_ if $^S;
print @_;
exit UNKNOWN;
};
my $verbose;
Getopt::Long::Configure('bundling', 'no_ignore_case');
GetOptions(
'verbose|v+' => \$verbose,
'help|?' => sub { help; exit 0 },
'usage' => sub { usage; exit 0 },
) and @ARGV == 0
or do { usage; exit UNKNOWN };
my @state = get_state;
my $status = OK;
foreach my $id (0 .. $#state) {
my $device = $state[$id]
or next;
# Assume CRITICAL by default
foreach (qw( cs )) {
$device->{"${_}_level"} = {
Connected => OK,
Unconfigured => OK,
StandAlone => WARNING,
SyncingAll => WARNING,
SyncingQuick => WARNING,
SyncSource => WARNING,
SyncTarget => WARNING,
VerifyS => WARNING,
VerifyT => WARNING,
Disconnecting => WARNING,
TearDown => WARNING,
StartingSyncS => WARNING,
StartingSyncT => WARNING,
WFSyncUUID => WARNING,
}->{$device->{$_}};
$device->{"${_}_level"} = CRITICAL unless defined $device->{"${_}_level"};
}
foreach (qw( ro pro )) {
$device->{"${_}_level"} = {
Primary => OK,
Secondary => OK,
}->{$device->{$_}};
$device->{"${_}_level"} = CRITICAL unless defined $device->{"${_}_level"};
}
foreach (qw( ds pds )) {
$device->{"${_}_level"} = {
UpToDate => OK,
Consistent => OK,
Negotiating => WARNING,
Attaching => WARNING,
}->{$device->{$_}};
$device->{"${_}_level"} = CRITICAL unless defined $device->{"${_}_level"};
}
my $level = OK;
foreach (grep /_level$/, keys %$device) {
$level = $device->{$_} if $level < $device->{$_};
}
$status = $level if $status < $level;
$device->{level} = $level;
$device->{info} = sprintf 'drbd%d: %s %s/%s %s/%s', $id, $device->{cs}, $device->{ro}, $device->{pro}, $device->{ds}, $device->{pds};
$device->{short} = sprintf 'drbd%d: %0.3s%0.3s%0.3s', $id, $device->{ro}, $device->{cs}, $device->{ds}; # Role and connstate reversed, like old check_drbd
foreach (qw( ns nr dw dr al bm )) {
my $value = $device->{$_};
defined $value
or next;
perfdata "drbd${id}_${_}=${value}c";
}
foreach (qw( lo pe ua ap oos )) {
my $value = $device->{$_};
defined $value
or next;
perfdata "drbd${id}_${_}=${value};;;0";
}
}
@state
or critical 'No DRBD volumes present';
if ($status) {
my $message = join ', ', map $_->{info}, grep { defined and $_->{level} } @state;
if ($status == WARNING) {
warning $message;
} else {
critical $message;
}
} else {
my $message = join ', ', map { ($verbose || @state == 1) ? $_->{info} : $_->{short} } grep defined, @state;
ok $message;
}
die;
###########################################################################
sub help {
print <<EOF;
Usage: @{[BASENAME]} [OPTION...]
Check DRBD resources.
Plugin options:
-v, --verbose Increase verbosity
Help options:
-?, --help Give this help list
--usage Give a short usage message
EOF
}
sub usage {
print <<EOF;
Usage: @{[BASENAME]} [-v?] [--verbose] [--help] [--usage]
EOF
}
###########################################################################
{
my @perfdata;
sub perfdata { push @perfdata, @_ }
sub _exit {
my ($status, $message) = @_;
if (defined $message) {
print $message;
} else {
print qw( OK WARNING CRITICAL )[$status] || 'UNKNOWN';
}
if (my $perfdata = shift @perfdata) {
print "|$perfdata ";
}
print "\n";
if (@perfdata) {
print '|';
print map "$_ \n", @perfdata;
}
exit $status;
}
}
sub ok { _exit OK, @_ }
sub warning { _exit WARNING, @_ }
sub critical { _exit CRITICAL, @_ }
sub unknown { _exit UNKNOWN, @_ }
###########################################################################
sub get_state {
my $io = new IO::File(STATE_FILE)
or critical "Could not open @{[STATE_FILE]} for reading: $!\n";
# 0: cs:Connected ro:Primary/Secondary ds:UpToDate/UpToDate C r----
# ns:0 nr:20492 dw:20480 dr:124 al:5 bm:1296 lo:0 pe:0 ua:0 ap:0 ep:1 wo:d oos:0
my @state;
my $device;
while (<$io>) {
if (m(^ \s* (\d+): \s* cs:(\w+) \s+ (?:ro|st):(\w+)/(\w+) \s+ ds:(\w+)/(\w+) )x) {
$device = $state[$1] = {
cs => $2,
ro => $3,
pro => $4,
ds => $5,
pds => $6,
};
next;
};
$device or next;
$device->{$1} = $2 while /(\w+):(\S+)/g;
}
@state;
}