Module: Rstatsd::Helpers

Included in:
Chart, Collector, Server
Defined in:
lib/rstatsd/helpers.rb

Instance Method Summary collapse

Instance Method Details

#counter_key_name(key) ⇒ Object



13
14
15
# File 'lib/rstatsd/helpers.rb', line 13

def counter_key_name(key)
  "counter:#{key}"
end

#fetch_counters(counters) ⇒ Object



25
26
27
28
29
30
31
32
33
34
35
# File 'lib/rstatsd/helpers.rb', line 25

def fetch_counters(counters)
  finished_data = {}
  counters.each_with_index do |counter, index|
    data = redis_data_for(counter)
    data.keys.each do |key|
      finished_data[key] ||= Array.new(counters.length, 0)
      finished_data[key][index] = data[key]
    end
  end
  finished_data
end

#format_key(key) ⇒ Object



6
7
8
9
10
11
# File 'lib/rstatsd/helpers.rb', line 6

def format_key(key)
  key.strip
    .gsub(/\s+/, '_')
    .gsub(/\//, '-')
    .gsub(/[^a-zA-Z_\-0-9\.]/, '')
end

#redisObject



21
22
23
# File 'lib/rstatsd/helpers.rb', line 21

def redis
  @redis ||= Redis.new
end

#redis_data_for(key) ⇒ Object



37
38
39
40
41
42
43
# File 'lib/rstatsd/helpers.rb', line 37

def redis_data_for(key)
  redis.lrange(counter_key_name(key), 0, -1).inject({}) do |memo, point|
    val, time = point.split(":")
    memo[time] = val.to_i
    memo
  end
end

#timer_key_name(key) ⇒ Object



17
18
19
# File 'lib/rstatsd/helpers.rb', line 17

def timer_key_name(key)
  "timer:#{key}"
end