Class: Tremolo::Tracker

Inherits:
Object
  • Object
show all
Includes:
Celluloid
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.



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

def initialize(host, port, options={})
  @host, @port = host, port

  @namespace = options[:namespace]
end

Instance Attribute Details

#namespaceObject (readonly)

Returns the value of attribute namespace.



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

def namespace
  @namespace
end

Instance Method Details

#decrement(series_name, tags = {}) ⇒ Object



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

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

#increment(series_name, tags = {}) ⇒ Object



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

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

#series(series_name) ⇒ Object



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

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

#time(series_name, tags = {}, &block) ⇒ Object



31
32
33
34
35
36
37
# File 'lib/tremolo/tracker.rb', line 31

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

#timing(series_name, value, tags = {}) ⇒ Object



27
28
29
# File 'lib/tremolo/tracker.rb', line 27

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

#write_point(series_name, data, tags = {}) ⇒ Object



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

def write_point(series_name, data, tags = {})
  write_points(series_name, [data], tags)
end

#write_points(series_name, data, tags = {}) ⇒ Object



43
44
45
# File 'lib/tremolo/tracker.rb', line 43

def write_points(series_name, data, tags = {})
  sender.async.write_points([namespace, series_name].compact.join('.'), data, tags)
end