monitoring for IO in Nagios
Alexander Harvey
alexh19740110 at gmail.com
Thu Oct 19 05:09:13 CEST 2006
Ok well in case anyone else is wondering, here's the solution I came up
with:
# cat /usr/local/nagios/libexec/check_io.pl
#!/usr/bin/perl
# author: alex harvey
# email: alexh19740110 at gmail.com
# definitions
use constant OK => 0;
use constant WARNING => 1;
use constant CRITICAL => 2;
# read in config file
require "/usr/local/nagios/etc/check_io.cfg";
# main
open IOSTAT, "$IOSTAT $INTERVAL 3 | $TAIL -${LINES} |";
while ( <IOSTAT> ) {
@col = split ' ';
foreach $disk (keys %DISKS) {
if ( $disk eq $col[0] ) {
if ( $col[0] eq $disk ) {
$DISKS{$disk}[0] = $col[1];
$DISKS{$disk}[1] = $col[2];
$DISKS{$disk}[2] = $col[7];
$DISKS{$disk}[3] = $col[9];
}
}
}
}
close IOSTAT;
$exit_state = OK;
foreach $disk (sort (keys %DISKS)) {
if ( $DISKS{$disk}[2] >= $SVC_T_WTHRESHOLD && $DISKS{$disk}[3] >=
$PC_B_WTHRESHOLD )
{
if ( $DISKS{$disk}[2] < $SVC_T_CTHRESHOLD && $DISKS{$disk}[3] <
$PC_B_WTHRESHOLD )
{
$exit_state = ($exit_state < CRITICAL) ? WARNING : $exit_state;
} else {
$exit_state = CRITICAL;
}
}
$exit_message = $exit_message.
" ".$disk.
":: [ r/s: ".$DISKS{$disk}[0].
", w/s: ".$DISKS{$disk}[1].
", svc_t: ".$DISKS{$disk}[2].
", and %b: ".$DISKS{$disk}[3].
" ],";
}
if ( $exit_state == OK ) {
$exit_message = "OK -$exit_message";
} elsif ( $exit_state == WARNING ) {
$exit_message = "WARNING -$exit_message";
} else {
$exit_message = "CRITICAL -$exit_message";
}
$exit_message =~ s/,$/\n/;
print $exit_message;
exit $exit_state
And the configuration file:
# cat /usr/local/nagios/etc/check_io.cfg
# check_io.cfg
# constants
$DISKS = 3; # number of physical disk partitions
# diskid => [ r/s, w/s, service_time, %busy ]
%DISKS = (
sd0 => [ 0, 0, 0, 0 ],
sd1 => [ 0, 0, 0, 0 ],
sd6 => [ 0, 0, 0, 0 ]
);
$IOSTAT = '/usr/bin/iostat -x';
$TAIL = '/usr/bin/tail';
$LINES = 7; # number of lines in iostat -x
$INTERVAL = 5; # second interval for iostat
$SVC_T_WTHRESHOLD = 30;
$PC_B_WTHRESHOLD = 5;
$SVC_T_CTHRESHOLD = 40;
$PC_B_CTHRESHOLD = 10;
This is for a Solaris box whose iostat output looks like this:
# iostat -x
extended device statistics
device r/s w/s kr/s kw/s wait actv svc_t %w %b
sd0 0.0 1.4 0.3 9.4 0.0 0.0 31.6 0 1
sd1 0.0 0.0 0.0 0.0 0.0 0.0 3.4 0 0
sd6 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0 0
st12 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0 0
nfs1 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0 0
Regards,
Alex
On 10/17/06, Andreas Ericsson <ae at op5.se> wrote:
>
> Alexander Harvey wrote:
> > That doesn't look like a Solaris script to me but as far as your coding
> is
> > concerned, my thoughts are
> >
>
> [ excellent and non-disputed points removed ]
>
> > (iv) for security you ought to use full paths to all of your binaries:
> > i.e.
> > /usr/bin/echo
> > instead of
> > echo
> >
>
> "echo" is a built-in feature of pretty much all shells, so just using
> plain 'echo' is a perfectly viable and more performance friendly option.
>
> A better solution, for security's sake, is to force the $PATH to a safe
> value at the beginning of the script and not bother with full paths.
>
> As a last note, "echo" is required to exist on the root partition, which
> places it in /bin on all systems I've ever come across.
>
> --
> Andreas Ericsson andreas.ericsson at op5.se
> OP5 AB www.op5.se
> Tel: +46 8-230225 Fax: +46 8-230231
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://www.monitoring-lists.org/archive/users/attachments/20061019/f9d1d9ab/attachment.html>
-------------- next part --------------
-------------------------------------------------------------------------
Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job easier
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
-------------- next part --------------
_______________________________________________
Nagios-users mailing list
Nagios-users at lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/nagios-users
::: Please include Nagios version, plugin version (-v) and OS when reporting any issue.
::: Messages without supporting info will risk being sent to /dev/null
More information about the Users
mailing list