From: Pavel Rochnyack Date: Mon, 9 Oct 2017 20:08:38 +0000 (+0700) Subject: memcached: Fix hitratio calculation X-Git-Tag: collectd-5.8.0~45 X-Git-Url: https://git.verplant.org/?a=commitdiff_plain;h=60bc9b5c6ef49ec78291d64ebe4c58569b1f9a61;p=collectd.git memcached: Fix hitratio calculation If there is no requests, NAN is reported as hitratio. If there is no hits - zero is reported. --- diff --git a/src/memcached.c b/src/memcached.c index 5a9faf32..85794a5c 100644 --- a/src/memcached.c +++ b/src/memcached.c @@ -406,9 +406,12 @@ static gauge_t calculate_ratio_percent(derive_t part, derive_t total, *prev_part = part; *prev_total = total; - if (num == 0 || denom == 0) + if (denom == 0) return NAN; + if (num == 0) + return 0; + return 100.0 * (gauge_t)num / (gauge_t)denom; } @@ -426,9 +429,12 @@ static gauge_t calculate_ratio_percent2(derive_t part1, derive_t part2, *prev1 = part1; *prev2 = part2; - if (num == 0 || denom == 0) + if (denom == 0) return NAN; + if (num == 0) + return 0; + return 100.0 * (gauge_t)num / (gauge_t)denom; }