Support percentage value parsing in redis input (#6163)

This commit is contained in:
Mika Eloranta 2019-07-24 23:52:44 +03:00 committed by Daniel Nelson
parent 9fc8976c66
commit 417740738d
2 changed files with 9 additions and 2 deletions

View File

@ -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
@ -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
}

View File

@ -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),
@ -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