Module: SimpleMetrics::Graph

Extended by:
Graph
Included in:
Graph
Defined in:
lib/simple_metrics/graph.rb

Instance Method Summary collapse

Instance Method Details

#dayObject



8
# File 'lib/simple_metrics/graph.rb', line 8

def day;     Bucket[2]; end

#hoursObject



7
# File 'lib/simple_metrics/graph.rb', line 7

def hours;   Bucket[1]; end

#minutesObject



6
# File 'lib/simple_metrics/graph.rb', line 6

def minutes; Bucket[0]; end

#query(bucket, from, to, target) ⇒ Object



34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/simple_metrics/graph.rb', line 34

def query(bucket, from, to, target)
  if wild_card_query?(target)
    result = bucket.find_all_in_ts_range_by_wildcard(from, to, target)
    result = aggregate(result, target)
    bucket.fill_gaps(from, to, result)
  elsif target.is_a?(String)
    result = bucket.find_all_in_ts_range_by_name(from, to, target)
    bucket.fill_gaps(from, to, result) 
  else
    raise ArgumentError, "Unknown target format: #{target.inspect}"
  end
end

#query_all(bucket, from, to, *targets) ⇒ Object



26
27
28
29
30
31
32
# File 'lib/simple_metrics/graph.rb', line 26

def query_all(bucket, from, to, *targets)
  results = []
  Array(targets).each do |target|
    results << { :name => target, :data => query(bucket, from, to, target).map { |data| { :x => data.ts, :y => data.value || 0 } } }
  end
  results
end

#time_range(time) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/simple_metrics/graph.rb', line 11

def time_range(time)
  case time
  when 'minute'
    5 * one_minute
  when 'hour'
    one_hour
  when 'day'
    one_day
  when 'week'
    one_week
  else 
    raise "Unknown time param: #{time}"
  end
end

#weekObject



9
# File 'lib/simple_metrics/graph.rb', line 9

def week;    Bucket[3]; end