From db4c6e12a56ac713275a561207ce8f6818489bd0 Mon Sep 17 00:00:00 2001 From: Mika Eloranta Date: Wed, 24 Jul 2019 11:58:31 +0300 Subject: [PATCH] redis input: fix percentage value parsing Percentage values would get interpreted incorrectly as tags because they did not pass the int/float conversion. --- plugins/inputs/redis/redis.go | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/plugins/inputs/redis/redis.go b/plugins/inputs/redis/redis.go index cd438397c2318..31ebc7bbc87c5 100644 --- a/plugins/inputs/redis/redis.go +++ b/plugins/inputs/redis/redis.go @@ -253,8 +253,14 @@ func gatherInfoOutput( val := strings.TrimSpace(parts[1]) + // Some percentage values have a "%" suffix that we need to get rid of before int/float conversion + num_val := val; + if strings.HasSuffix(num_val, "%") { + num_val = num_val[:len(num_val) - 1] + } + // Try parsing as int - if ival, err := strconv.ParseInt(val, 10, 64); err == nil { + if ival, err := strconv.ParseInt(num_val, 10, 64); err == nil { switch name { case "keyspace_hits": keyspace_hits = ival @@ -269,7 +275,7 @@ func gatherInfoOutput( } // Try parsing as a float - if fval, err := strconv.ParseFloat(val, 64); err == nil { + if fval, err := strconv.ParseFloat(num_val, 64); err == nil { fields[metric] = fval continue }