added keyspace hitrate measurement

This commit is contained in:
Tyler Nisonoff 2015-10-17 21:05:56 -07:00
parent 73f1ed4f25
commit 5957af19fc
2 changed files with 23 additions and 5 deletions

View File

@ -159,6 +159,8 @@ func gatherInfoOutput(
acc plugins.Accumulator, acc plugins.Accumulator,
tags map[string]string, tags map[string]string,
) error { ) error {
var keyspace_hits, keyspace_misses uint64 = 0,0
scanner := bufio.NewScanner(rdr) scanner := bufio.NewScanner(rdr)
for scanner.Scan() { for scanner.Scan() {
line := scanner.Text() line := scanner.Text()
@ -185,6 +187,15 @@ func gatherInfoOutput(
val := strings.TrimSpace(parts[1]) val := strings.TrimSpace(parts[1])
ival, err := strconv.ParseUint(val, 10, 64) ival, err := strconv.ParseUint(val, 10, 64)
if name == "keyspace_hits" {
keyspace_hits = ival
}
if name == "keyspace_misses" {
keyspace_misses = ival
}
if err == nil { if err == nil {
acc.Add(metric, ival, tags) acc.Add(metric, ival, tags)
continue continue
@ -197,6 +208,12 @@ func gatherInfoOutput(
acc.Add(metric, fval, tags) acc.Add(metric, fval, tags)
} }
var keyspace_hitrate float64 = 0.0
if keyspace_hits != 0 || keyspace_misses != 0 {
keyspace_hitrate = float64(keyspace_hits) / float64(keyspace_hits + keyspace_misses)
}
fmt.Println(keyspace_hitrate)
acc.Add("keyspace_hitrate", keyspace_hitrate, tags)
return nil return nil
} }

View File

@ -55,8 +55,8 @@ func TestRedis_ParseMetrics(t *testing.T) {
{"sync_partial_err", 0}, {"sync_partial_err", 0},
{"expired_keys", 0}, {"expired_keys", 0},
{"evicted_keys", 0}, {"evicted_keys", 0},
{"keyspace_hits", 0}, {"keyspace_hits", 1},
{"keyspace_misses", 0}, {"keyspace_misses", 1},
{"pubsub_channels", 0}, {"pubsub_channels", 0},
{"pubsub_patterns", 0}, {"pubsub_patterns", 0},
{"latest_fork_usec", 0}, {"latest_fork_usec", 0},
@ -83,6 +83,7 @@ func TestRedis_ParseMetrics(t *testing.T) {
{"used_cpu_user", 0.05}, {"used_cpu_user", 0.05},
{"used_cpu_sys_children", 0.00}, {"used_cpu_sys_children", 0.00},
{"used_cpu_user_children", 0.00}, {"used_cpu_user_children", 0.00},
{"keyspace_hitrate", 0.50},
} }
for _, c := range checkFloat { for _, c := range checkFloat {
@ -115,7 +116,7 @@ client_longest_output_list:0
client_biggest_input_buf:0 client_biggest_input_buf:0
blocked_clients:0 blocked_clients:0
# Memory # Memor2
used_memory:1003936 used_memory:1003936
used_memory_human:980.41K used_memory_human:980.41K
used_memory_rss:811008 used_memory_rss:811008
@ -151,8 +152,8 @@ sync_partial_ok:0
sync_partial_err:0 sync_partial_err:0
expired_keys:0 expired_keys:0
evicted_keys:0 evicted_keys:0
keyspace_hits:0 keyspace_hits:1
keyspace_misses:0 keyspace_misses:1
pubsub_channels:0 pubsub_channels:0
pubsub_patterns:0 pubsub_patterns:0
latest_fork_usec:0 latest_fork_usec:0