Skip to content

Commit

Permalink
Support percentage value parsing in redis input (influxdata#6163)
Browse files Browse the repository at this point in the history
  • Loading branch information
Mika Eloranta authored and idohalevi committed Sep 23, 2020
1 parent 980f4ec commit 1d5af51
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
7 changes: 5 additions & 2 deletions plugins/inputs/redis/redis.go
Original file line number Diff line number Diff line change
Expand Up @@ -253,8 +253,11 @@ 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 := strings.TrimSuffix(val, "%")

// 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 +272,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
4 changes: 4 additions & 0 deletions plugins/inputs/redis/redis_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ func TestRedis_ParseMetrics(t *testing.T) {
"used_memory_rss": int64(811008),
"used_memory_peak": int64(1003936),
"used_memory_lua": int64(33792),
"used_memory_peak_perc": float64(93.58),
"used_memory_dataset_perc": float64(20.27),
"mem_fragmentation_ratio": float64(0.81),
"loading": int64(0),
"rdb_changes_since_last_save": int64(0),
Expand Down Expand Up @@ -152,6 +154,8 @@ used_memory_peak_human:980.41K
used_memory_lua:33792
mem_fragmentation_ratio:0.81
mem_allocator:libc
used_memory_peak_perc:93.58%
used_memory_dataset_perc:20.27%
# Persistence
loading:0
Expand Down

0 comments on commit 1d5af51

Please sign in to comment.