From: Florian Forster Date: Tue, 20 Jan 2009 09:34:51 +0000 (+0100) Subject: memcached plugin: Make absolutely sure, we don't divide by zero. X-Git-Tag: collectd-4.6.0~99 X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=816d4c62bc2a54331b6c66c9d4fa3d846f3931a6;p=collectd.git memcached plugin: Make absolutely sure, we don't divide by zero. It's a well-known fact only Chuck Norris can do that! --- diff --git a/src/memcached.c b/src/memcached.c index fb33880f..f139b719 100644 --- a/src/memcached.c +++ b/src/memcached.c @@ -475,8 +475,16 @@ static int memcached_read (void) /* {{{ */ if ((octets_rx != 0) || (octets_tx != 0)) submit_counter2 ("memcached_octets", NULL, octets_rx, octets_tx); - if (! isnan (gets) && !isnan (hits)) - submit_gauge ("percent", "hitratio", (hits / gets) * 100.0); + if (!isnan (gets) && !isnan (hits)) + { + gauge_t rate = NAN; + + if (gets != 0.0) + rate = 100.0 * hits / gets; + + submit_gauge ("percent", "hitratio", rate); + } + return 0; } /* }}} */