Skip to content

Commit

Permalink
added keyspace hitrate measurement
Browse files Browse the repository at this point in the history
Closes #283
  • Loading branch information
Tyler Nisonoff authored and sparrc committed Oct 19, 2015
1 parent 7600cc8 commit 6869362
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 4 deletions.
16 changes: 16 additions & 0 deletions plugins/redis/redis.go
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,8 @@ func gatherInfoOutput(
acc plugins.Accumulator,
tags map[string]string,
) error {
var keyspace_hits, keyspace_misses uint64 = 0, 0

scanner := bufio.NewScanner(rdr)
for scanner.Scan() {
line := scanner.Text()
Expand All @@ -185,6 +187,15 @@ func gatherInfoOutput(

val := strings.TrimSpace(parts[1])
ival, err := strconv.ParseUint(val, 10, 64)

if name == "keyspace_hits" {
keyspace_hits = ival
}

if name == "keyspace_misses" {
keyspace_misses = ival
}

if err == nil {
acc.Add(metric, ival, tags)
continue
Expand All @@ -197,6 +208,11 @@ func gatherInfoOutput(

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)
}
acc.Add("keyspace_hitrate", keyspace_hitrate, tags)
return nil
}

Expand Down
9 changes: 5 additions & 4 deletions plugins/redis/redis_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,8 @@ func TestRedis_ParseMetrics(t *testing.T) {
{"sync_partial_err", 0},
{"expired_keys", 0},
{"evicted_keys", 0},
{"keyspace_hits", 0},
{"keyspace_misses", 0},
{"keyspace_hits", 1},
{"keyspace_misses", 1},
{"pubsub_channels", 0},
{"pubsub_patterns", 0},
{"latest_fork_usec", 0},
Expand All @@ -83,6 +83,7 @@ func TestRedis_ParseMetrics(t *testing.T) {
{"used_cpu_user", 0.05},
{"used_cpu_sys_children", 0.00},
{"used_cpu_user_children", 0.00},
{"keyspace_hitrate", 0.50},
}

for _, c := range checkFloat {
Expand Down Expand Up @@ -151,8 +152,8 @@ sync_partial_ok:0
sync_partial_err:0
expired_keys:0
evicted_keys:0
keyspace_hits:0
keyspace_misses:0
keyspace_hits:1
keyspace_misses:1
pubsub_channels:0
pubsub_patterns:0
latest_fork_usec:0
Expand Down

0 comments on commit 6869362

Please sign in to comment.