Support percentage value parsing in redis input (#6163)
This commit is contained in:
parent
9fc8976c66
commit
417740738d
|
@ -253,8 +253,11 @@ func gatherInfoOutput(
|
||||||
|
|
||||||
val := strings.TrimSpace(parts[1])
|
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
|
// 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 {
|
switch name {
|
||||||
case "keyspace_hits":
|
case "keyspace_hits":
|
||||||
keyspace_hits = ival
|
keyspace_hits = ival
|
||||||
|
@ -269,7 +272,7 @@ func gatherInfoOutput(
|
||||||
}
|
}
|
||||||
|
|
||||||
// Try parsing as a float
|
// 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
|
fields[metric] = fval
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
|
@ -49,6 +49,8 @@ func TestRedis_ParseMetrics(t *testing.T) {
|
||||||
"used_memory_rss": int64(811008),
|
"used_memory_rss": int64(811008),
|
||||||
"used_memory_peak": int64(1003936),
|
"used_memory_peak": int64(1003936),
|
||||||
"used_memory_lua": int64(33792),
|
"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),
|
"mem_fragmentation_ratio": float64(0.81),
|
||||||
"loading": int64(0),
|
"loading": int64(0),
|
||||||
"rdb_changes_since_last_save": int64(0),
|
"rdb_changes_since_last_save": int64(0),
|
||||||
|
@ -152,6 +154,8 @@ used_memory_peak_human:980.41K
|
||||||
used_memory_lua:33792
|
used_memory_lua:33792
|
||||||
mem_fragmentation_ratio:0.81
|
mem_fragmentation_ratio:0.81
|
||||||
mem_allocator:libc
|
mem_allocator:libc
|
||||||
|
used_memory_peak_perc:93.58%
|
||||||
|
used_memory_dataset_perc:20.27%
|
||||||
|
|
||||||
# Persistence
|
# Persistence
|
||||||
loading:0
|
loading:0
|
||||||
|
|
Loading…
Reference in New Issue