[Nagiosplug-devel] check_swap divide by 0 error

Andreas Ericsson ae at op5.se
Tue Jun 28 12:29:05 CEST 2005


Nik Sands wrote:
> The "check_swap" nagios plugin has a minor flaw, in that the output  is 
> incorrect for machines with no swap configured (at least on  Solaris).  
> Some people may say, "well, you should have swap  configured!",

I'd rather say "If you don't have swap configured, why on earth are you 
running the check_swap plugin?", but perhaps that's just me.

> but when 
> the machine has 16 GB of RAM, it really isn't  necessary.

Not really true actually. Maintaining a small swap lets the kernel avoid 
quite a bit of exception handling and makes branch prediction much more 
efficient. At least this holds true on Linux, although I can imagine the 
design is similar on Solaris.

>  In any case, 
> it should at least show the correct  percentage used, which would be 
> either 100% (and warning or critical)  or 0%.  As it is it get's the 
> result of a divide by zero, which is  rather ugly.
> 
> The line of code is question is:
> 
>         percent_used = 100 * ((double) used_swap) / ((double)  total_swap);
> 
> When there's no swap, this amounts to:
> 
>         percent_used = 100 * 0 / 0;
> 
> If would be good to have a block before this, something like:
> 
>         if ( total_swap == 0 )
>         {
>             /* percent_used = either 0 or 100, depending on your  point 
> of view */
>         }
>         else
> 
> Thanks for your consideration of this imporovement.
> 
> Please note that I'm not a member of this list so won't see any  
> responses posted to the list.  If I need to see any responses (which  I 
> doubt), please CC them to me.
> 
> Cheers,
> Nik.
> 
> 
> ========================================================
> NIK SANDS - Systems Administrator, IT Services, University of  Tasmania, 
> Australia
>     Phone:  +61-3-63243732 (BH)
>     VoIP (Free Call):  (1800 262 218) 393 658821
>     AIM / iChat:  brassnix
> 
> 
> 
> -------------------------------------------------------
> SF.Net email is sponsored by: Discover Easy Linux Migration Strategies
> from IBM. Find simple to follow Roadmaps, straightforward articles,
> informative Webcasts and more! Get everything you need to get up to
> speed, fast. http://ads.osdn.com/?ad_id=7477&alloc_id=16492&op=click
> _______________________________________________________
> Nagios Plugin Development Mailing List 
> Nagiosplug-devel at lists.sourceforge.net
> Unsubscribe at 
> https://lists.sourceforge.net/lists/listinfo/nagiosplug-devel
> ::: Please include plugins version (-v) and OS when reporting any issue. 
> ::: Messages without supporting info will risk being sent to /dev/null
> 

-- 
Andreas Ericsson                   andreas.ericsson at op5.se
OP5 AB                             www.op5.se
Lead Developer




More information about the Devel mailing list