Skip to content

Commit

Permalink
redis input: fix percentage value parsing
Browse files Browse the repository at this point in the history
Percentage values would get interpreted incorrectly as tags because they
did not pass the int/float conversion.
  • Loading branch information
Mika Eloranta committed Jul 24, 2019
1 parent 9fc8976 commit db4c6e1
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions plugins/inputs/redis/redis.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
}
Expand Down

0 comments on commit db4c6e1

Please sign in to comment.