Permalink
Browse files

Merge pull request #4 from frhwang/hit-ratio

added stats for keyspace hit ratio
  • Loading branch information...
junegunn committed Dec 7, 2012
2 parents 16ca8c5 + 221b972 commit 080b96ddbe748bd44bed6eb4226c8b2fc7a7818c
Showing with 27 additions and 2 deletions.
  1. +1 −0 README.md
  2. +18 −0 lib/redis-stat.rb
  3. +7 −1 lib/redis-stat/constants.rb
  4. +1 −1 lib/redis-stat/version.rb
View
@@ -78,6 +78,7 @@ killall -9 redis-stat-daemon
## Contributors
- [Chris Meisl](https://github.com/cmeisl)
- [Hyunseok Hwang](https://github.com/frhwang)
## Contributing
View
@@ -290,6 +290,14 @@ def process_how info, prev_info, key
end
end
get_ratio = lambda do |x, y|
if x > 0 && y > 0
x / (x + y) * 100
else
0
end
end
case key
when :at
val = Time.now.strftime('%H:%M:%S')
@@ -310,6 +318,16 @@ def process_how info, prev_info, key
when :used_memory, :used_memory_rss, :aof_current_size, :aof_base_size
val = info.sumf(key)
[humanize_number(val.to_i, true), val]
when :keyspace_hits_ratio
hits = info.sumf(:keyspace_hits)
misses = info.sumf(:keyspace_misses)
val = get_ratio.call(hits, misses)
[humanize_number(val), val]
when :keyspace_hits_ratio_per_second
hits = get_diff.call(:keyspace_hits) || 0
misses = get_diff.call(:keyspace_misses) || 0
val = get_ratio.call(hits, misses)
[humanize_number(val), val]
else
val = info.sumf(key)
[humanize_number(val), val]
@@ -33,8 +33,8 @@ class RedisStat
:evicted_keys_per_second,
:keyspace_hits_per_second,
:keyspace_misses_per_second,
:keyspace_hits_ratio_per_second,
:aof_current_size,
:pubsub_channels,
],
:verbose => [
:at,
@@ -56,6 +56,8 @@ class RedisStat
:keyspace_hits,
:keyspace_misses_per_second,
:keyspace_misses,
:keyspace_hits_ratio,
:keyspace_hits_ratio_per_second,
:aof_current_size,
:aof_base_size,
[:rdb_changes_since_last_save, :changes_since_last_save],
@@ -84,6 +86,8 @@ class RedisStat
:keyspace_hits_per_second => [:magenta, :bold],
:keyspace_misses => [:magenta],
:keyspace_misses_per_second => [:magenta],
:keyspace_hits_ratio => [:magenta],
:keyspace_hits_ratio_per_second => [:magenta],
:aof_current_size => [:cyan],
:aof_base_size => [:cyan],
:rdb_changes_since_last_save => [:green, :bold],
@@ -111,6 +115,8 @@ class RedisStat
:keyspace_hits_per_second => 'hit/s',
:keyspace_misses => 'mis',
:keyspace_misses_per_second => 'mis/s',
:keyspace_hits_ratio => 'hit%',
:keyspace_hits_ratio_per_second => 'hit%/s',
:aof_current_size => 'aofcs',
:aof_base_size => 'aofbs',
:rdb_changes_since_last_save => 'chsv',
@@ -1,3 +1,3 @@
class RedisStat
VERSION = "0.3.2"
VERSION = "0.3.3"
end

0 comments on commit 080b96d

Please sign in to comment.