Code

memcached plugin: Make absolutely sure, we don't divide by zero.
authorFlorian Forster <octo@huhu.verplant.org>
Tue, 20 Jan 2009 09:34:51 +0000 (10:34 +0100)
committerFlorian Forster <octo@huhu.verplant.org>
Tue, 20 Jan 2009 09:34:51 +0000 (10:34 +0100)
It's a well-known fact only Chuck Norris can do that!

src/memcached.c

index fb33880ff5cc68aae4764723742e4cc3e0944f99..f139b7195591f637a51998b5fe132192414dabfa 100644 (file)
@@ -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;
 }
 /* }}} */