Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

redis input: fix percentage value parsing #6163

Merged
merged 1 commit into from
Jul 24, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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