Skip to content

Commit

Permalink
Merge pull request #4 from frhwang/hit-ratio
Browse files Browse the repository at this point in the history
added stats for keyspace hit ratio
  • Loading branch information
junegunn committed Dec 7, 2012
2 parents 16ca8c5 + 221b972 commit 080b96d
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 2 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ killall -9 redis-stat-daemon


## Contributors ## Contributors
- [Chris Meisl](https://github.com/cmeisl) - [Chris Meisl](https://github.com/cmeisl)
- [Hyunseok Hwang](https://github.com/frhwang)


## Contributing ## Contributing


Expand Down
18 changes: 18 additions & 0 deletions lib/redis-stat.rb
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -290,6 +290,14 @@ def process_how info, prev_info, key
end end
end end


get_ratio = lambda do |x, y|
if x > 0 && y > 0
x / (x + y) * 100
else
0
end
end

case key case key
when :at when :at
val = Time.now.strftime('%H:%M:%S') val = Time.now.strftime('%H:%M:%S')
Expand All @@ -310,6 +318,16 @@ def process_how info, prev_info, key
when :used_memory, :used_memory_rss, :aof_current_size, :aof_base_size when :used_memory, :used_memory_rss, :aof_current_size, :aof_base_size
val = info.sumf(key) val = info.sumf(key)
[humanize_number(val.to_i, true), val] [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 else
val = info.sumf(key) val = info.sumf(key)
[humanize_number(val), val] [humanize_number(val), val]
Expand Down
8 changes: 7 additions & 1 deletion lib/redis-stat/constants.rb
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ class RedisStat
:evicted_keys_per_second, :evicted_keys_per_second,
:keyspace_hits_per_second, :keyspace_hits_per_second,
:keyspace_misses_per_second, :keyspace_misses_per_second,
:keyspace_hits_ratio_per_second,
:aof_current_size, :aof_current_size,
:pubsub_channels,
], ],
:verbose => [ :verbose => [
:at, :at,
Expand All @@ -56,6 +56,8 @@ class RedisStat
:keyspace_hits, :keyspace_hits,
:keyspace_misses_per_second, :keyspace_misses_per_second,
:keyspace_misses, :keyspace_misses,
:keyspace_hits_ratio,
:keyspace_hits_ratio_per_second,
:aof_current_size, :aof_current_size,
:aof_base_size, :aof_base_size,
[:rdb_changes_since_last_save, :changes_since_last_save], [:rdb_changes_since_last_save, :changes_since_last_save],
Expand Down Expand Up @@ -84,6 +86,8 @@ class RedisStat
:keyspace_hits_per_second => [:magenta, :bold], :keyspace_hits_per_second => [:magenta, :bold],
:keyspace_misses => [:magenta], :keyspace_misses => [:magenta],
:keyspace_misses_per_second => [:magenta], :keyspace_misses_per_second => [:magenta],
:keyspace_hits_ratio => [:magenta],
:keyspace_hits_ratio_per_second => [:magenta],
:aof_current_size => [:cyan], :aof_current_size => [:cyan],
:aof_base_size => [:cyan], :aof_base_size => [:cyan],
:rdb_changes_since_last_save => [:green, :bold], :rdb_changes_since_last_save => [:green, :bold],
Expand Down Expand Up @@ -111,6 +115,8 @@ class RedisStat
:keyspace_hits_per_second => 'hit/s', :keyspace_hits_per_second => 'hit/s',
:keyspace_misses => 'mis', :keyspace_misses => 'mis',
:keyspace_misses_per_second => 'mis/s', :keyspace_misses_per_second => 'mis/s',
:keyspace_hits_ratio => 'hit%',
:keyspace_hits_ratio_per_second => 'hit%/s',
:aof_current_size => 'aofcs', :aof_current_size => 'aofcs',
:aof_base_size => 'aofbs', :aof_base_size => 'aofbs',
:rdb_changes_since_last_save => 'chsv', :rdb_changes_since_last_save => 'chsv',
Expand Down
2 changes: 1 addition & 1 deletion lib/redis-stat/version.rb
Original file line number Original file line Diff line number Diff line change
@@ -1,3 +1,3 @@
class RedisStat class RedisStat
VERSION = "0.3.2" VERSION = "0.3.3"
end end

0 comments on commit 080b96d

Please sign in to comment.