module TabsTabs
Constants
- METRIC_TYPES
- VERSION
Public Instance Methods
complete_task(key, token, timestamp=Time.now)
click to toggle source
# File lib/tabs_tabs/tabs_tabs.rb, line 43 def complete_task(key, token, timestamp=Time.now) raise MetricTypeMismatchError.new("Only task metrics can complete a task") unless metric_type(key) == "task" get_metric(key).complete(token, timestamp) end
config()
click to toggle source
# File lib/tabs_tabs/tabs_tabs.rb, line 21 def config Config end
configure() { |Config| ... }
click to toggle source
# File lib/tabs_tabs/tabs_tabs.rb, line 13 def configure yield(Config) end
counter_total(key) { || ... }
click to toggle source
# File lib/tabs_tabs/tabs_tabs.rb, line 61 def counter_total(key) unless metric_exists?(key) if block_given? return yield else raise UnknownMetricError.new("Unknown metric: #{key}") end end raise MetricTypeMismatchError.new("Only counter metrics can be incremented") unless metric_type(key) == "counter" get_metric(key).total end
create_metric(key, type)
click to toggle source
# File lib/tabs_tabs/tabs_tabs.rb, line 48 def create_metric(key, type) raise UnknownTypeError.new("Unknown metric type: #{type}") unless METRIC_TYPES.include?(type) raise DuplicateMetricError.new("Metric already exists: #{key}") if metric_exists?(key) hset "metrics", key, type metric_klass(type).new(key) end
drop_all_metrics!()
click to toggle source
# File lib/tabs_tabs/tabs_tabs.rb, line 99 def drop_all_metrics! metrics = self.list_metrics metrics.each { |key| self.drop_metric! key } end
drop_metric!(key)
click to toggle source
# File lib/tabs_tabs/tabs_tabs.rb, line 92 def drop_metric!(key) raise UnknownMetricError.new("Unknown metric: #{key}") unless metric_exists?(key) metric = get_metric(key) metric.drop! hdel "metrics", key end
drop_resolution_for_metric!(key, resolution)
click to toggle source
# File lib/tabs_tabs/tabs_tabs.rb, line 104 def drop_resolution_for_metric!(key, resolution) raise UnknownMetricError.new("Unknown metric: #{key}") unless metric_exists?(key) raise ResolutionMissingError.new(resolution) unless TabsTabs::Resolution.all.include? resolution metric = get_metric(key) metric.drop_by_resolution!(resolution) unless metric_type(key) == "task" end
get_metric(key)
click to toggle source
# File lib/tabs_tabs/tabs_tabs.rb, line 55 def get_metric(key) raise UnknownMetricError.new("Unknown metric: #{key}") unless metric_exists?(key) type = hget("metrics", key) metric_klass(type).new(key) end
get_stats(key, period, resolution)
click to toggle source
# File lib/tabs_tabs/tabs_tabs.rb, line 73 def get_stats(key, period, resolution) raise UnknownMetricError.new("Unknown metric: #{key}") unless metric_exists?(key) metric = get_metric(key) metric.stats(period, resolution) end
increment_counter(key, timestamp=Time.now)
click to toggle source
# File lib/tabs_tabs/tabs_tabs.rb, line 25 def increment_counter(key, timestamp=Time.now) create_metric(key, "counter") unless metric_exists?(key) raise MetricTypeMismatchError.new("Only counter metrics can be incremented") unless metric_type(key) == "counter" get_metric(key).increment(timestamp) end
list_metrics()
click to toggle source
# File lib/tabs_tabs/tabs_tabs.rb, line 84 def list_metrics hkeys "metrics" end
metric_exists?(key)
click to toggle source
# File lib/tabs_tabs/tabs_tabs.rb, line 88 def metric_exists?(key) list_metrics.include? key end
metric_type(key)
click to toggle source
# File lib/tabs_tabs/tabs_tabs.rb, line 79 def metric_type(key) raise UnknownMetricError.new("Unknown metric: #{key}") unless metric_exists?(key) hget "metrics", key end
record_value(key, value, timestamp=Time.now)
click to toggle source
# File lib/tabs_tabs/tabs_tabs.rb, line 31 def record_value(key, value, timestamp=Time.now) create_metric(key, "value") unless metric_exists?(key) raise MetricTypeMismatchError.new("Only value metrics can record a value") unless metric_type(key) == "value" get_metric(key).record(value, timestamp) end
redis()
click to toggle source
# File lib/tabs_tabs/tabs_tabs.rb, line 17 def redis Config.redis end
start_task(key, token, timestamp=Time.now)
click to toggle source
# File lib/tabs_tabs/tabs_tabs.rb, line 37 def start_task(key, token, timestamp=Time.now) create_metric(key, "task") raise MetricTypeMismatchError.new("Only task metrics can start a task") unless metric_type(key) == "task" get_metric(key).start(token, timestamp) end
Private Instance Methods
metric_klass(type)
click to toggle source
# File lib/tabs_tabs/tabs_tabs.rb, line 113 def metric_klass(type) "TabsTabs::Metrics::#{type.classify}".constantize end