Class: CacheStache::StatsQuery

Inherits:
Object
  • Object
show all
Defined in:
lib/cache_stache/stats_query.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#resolutionObject (readonly)

Returns the value of attribute resolution.



7
8
9
# File 'lib/cache_stache/stats_query.rb', line 7

def resolution
  @resolution
end

#windowObject (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

#executeObject



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