Class: TabsTabs::Metrics::Value
- Inherits:
-
Object
- Object
- TabsTabs::Metrics::Value
- Defined in:
- lib/tabs_tabs/metrics/value.rb,
lib/tabs_tabs/metrics/value/stats.rb
Defined Under Namespace
Classes: Stats
Instance Attribute Summary collapse
-
#key ⇒ Object
readonly
Returns the value of attribute key.
Instance Method Summary collapse
- #drop! ⇒ Object
- #drop_by_resolution!(resolution) ⇒ Object
-
#initialize(key) ⇒ Value
constructor
A new instance of Value.
- #record(value, timestamp = Time.now) ⇒ Object
- #stats(period, resolution) ⇒ Object
- #storage_key(resolution, timestamp) ⇒ Object
Methods included from Helpers
#normalize_period, #timestamp_range, #to_numeric
Methods included from Storage
#del, #del_by_prefix, #exists, #expireat, #get, #hdel, #hget, #hgetall, #hincrby, #hkeys, #hset, #incr, #mget, #redis, #rpush, #sadd, #set, #sismember, #smembers, #smembers_all, #tabs_key, #ttl
Constructor Details
#initialize(key) ⇒ Value
Returns a new instance of Value.
9 10 11 |
# File 'lib/tabs_tabs/metrics/value.rb', line 9 def initialize(key) @key = key end |
Instance Attribute Details
#key ⇒ Object (readonly)
Returns the value of attribute key.
7 8 9 |
# File 'lib/tabs_tabs/metrics/value.rb', line 7 def key @key end |
Instance Method Details
#drop! ⇒ Object
38 39 40 |
# File 'lib/tabs_tabs/metrics/value.rb', line 38 def drop! del_by_prefix("stat:value:#{key}") end |
#drop_by_resolution!(resolution) ⇒ Object
42 43 44 |
# File 'lib/tabs_tabs/metrics/value.rb', line 42 def drop_by_resolution!(resolution) del_by_prefix("stat:value:#{key}:data:#{resolution}") end |
#record(value, timestamp = Time.now) ⇒ Object
13 14 15 16 17 18 19 20 21 |
# File 'lib/tabs_tabs/metrics/value.rb', line 13 def record(value, =Time.now) .utc TabsTabs::Resolution.all.each do |resolution| store_key = storage_key(resolution, ) update_values(store_key, value) TabsTabs::Resolution.expire(resolution, store_key, ) end true end |
#stats(period, resolution) ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/tabs_tabs/metrics/value.rb', line 23 def stats(period, resolution) = period, resolution keys = .map do || storage_key(resolution, ) end values = mget(*keys).map do |v| value = v.nil? ? default_value(0) : JSON.parse(v) value["timestamp"] = .shift value.with_indifferent_access end Stats.new(period, resolution, values) end |
#storage_key(resolution, timestamp) ⇒ Object
46 47 48 49 |
# File 'lib/tabs_tabs/metrics/value.rb', line 46 def storage_key(resolution, ) formatted_time = TabsTabs::Resolution.serialize(resolution, ) "stat:value:#{key}:data:#{resolution}:#{formatted_time}" end |