Class: Tremolo::Tracker

Inherits:
Object
  • Object
show all
Defined in:
lib/tremolo/tracker.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(host, port, options = {}) ⇒ Tracker

Returns a new instance of Tracker.



5
6
7
8
9
# File 'lib/tremolo/tracker.rb', line 5

def initialize(host, port, options={})
  @sender = Sender.new(host, port)

  @namespace = options[:namespace]
end

Instance Attribute Details

#namespaceObject (readonly)

Returns the value of attribute namespace.



3
4
5
# File 'lib/tremolo/tracker.rb', line 3

def namespace
  @namespace
end

Instance Method Details

#decrement(series_name) ⇒ Object



19
20
21
# File 'lib/tremolo/tracker.rb', line 19

def decrement(series_name)
  write_point(series_name, {value: -1})
end

#increment(series_name) ⇒ Object



15
16
17
# File 'lib/tremolo/tracker.rb', line 15

def increment(series_name)
  write_point(series_name, {value: 1})
end

#series(series_name) ⇒ Object



11
12
13
# File 'lib/tremolo/tracker.rb', line 11

def series(series_name)
  Series.new(self, series_name)
end

#time(series_name, &block) ⇒ Object



27
28
29
30
31
32
33
# File 'lib/tremolo/tracker.rb', line 27

def time(series_name, &block)
  start = Time.now
  block.call.tap do |_|
    value = ((Time.now-start)*1000).round
    timing(series_name, value)
  end
end

#timing(series_name, value) ⇒ Object



23
24
25
# File 'lib/tremolo/tracker.rb', line 23

def timing(series_name, value)
  write_point(series_name, {value: value})
end

#write_point(series_name, data) ⇒ Object



35
36
37
# File 'lib/tremolo/tracker.rb', line 35

def write_point(series_name, data)
  write_points(series_name, [data])
end

#write_points(series_name, data) ⇒ Object



39
40
41
# File 'lib/tremolo/tracker.rb', line 39

def write_points(series_name, data)
  @sender.write_points([namespace, series_name].compact.join('.'), data)
end