Class: CacheStache::StatsQuery
- Inherits:
-
Object
- Object
- CacheStache::StatsQuery
- Defined in:
- lib/cache_stache/stats_query.rb
Instance Attribute Summary collapse
-
#resolution ⇒ Object
readonly
Returns the value of attribute resolution.
-
#window ⇒ Object
readonly
Returns the value of attribute window.
Instance Method Summary collapse
- #execute ⇒ Object
-
#initialize(window: 1.hour, resolution: nil) ⇒ StatsQuery
constructor
A new instance of StatsQuery.
Constructor Details
#initialize(window: 1.hour, resolution: nil) ⇒ StatsQuery
Returns a new instance of StatsQuery.
9 10 11 12 13 14 |
# File 'lib/cache_stache/stats_query.rb', line 9 def initialize(window: 1.hour, resolution: nil) @window = window.to_i @resolution = resolution @config = CacheStache.configuration @cache_client = CacheClient.new(@config) end |
Instance Attribute Details
#resolution ⇒ Object (readonly)
Returns the value of attribute resolution.
7 8 9 |
# File 'lib/cache_stache/stats_query.rb', line 7 def resolution @resolution end |
#window ⇒ Object (readonly)
Returns the value of attribute window.
7 8 9 |
# File 'lib/cache_stache/stats_query.rb', line 7 def window @window end |
Instance Method Details
#execute ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/cache_stache/stats_query.rb', line 16 def execute to_ts = Time.current.to_i from_ts = to_ts - window buckets = @cache_client.fetch_buckets(from_ts, to_ts) { overall: calculate_overall_stats(buckets), keyspaces: calculate_keyspace_stats(buckets), buckets: buckets.map { |b| format_bucket(b) }, window_seconds: window, bucket_count: buckets.size } end |