Class: Ventable::Statsd::Tracker

Inherits:
Object
  • Object
show all
Includes:
Singleton
Defined in:
lib/ventable/statsd/tracker.rb

Overview

Main interface class which delegates some methods to the instance of statsd in order to increment, or gauge/set various metrics.

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#enabledBool

set to false to bypass delegation

Returns:

  • (Bool)

    the current value of enabled



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

def enabled
  @enabled
end

#event_to_metric_proc=(value) ⇒ Proc (writeonly)

optional proc returning event configuration hash

Parameters:

  • value (Proc)

    the value to set the attribute event_to_metric_proc to.

Returns:

  • (Proc)

    the newly set value



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

def event_to_metric_proc=(value)
  @event_to_metric_proc = value
end

#statsd(operation, *args, **opts, &block) ⇒ Object

A wrapper around the actual Statsd, which checks whether the gem is enabled or disabled before calling Statsd.

Examples:

Increment a counter

enable!
statsd(:increment, 'my_event_count', 1)

Parameters:

  • operation (Symbol)

    method name to send to the actual Statsd

Returns:

  • nil if disabled, or whatever Statsd returns otherwise.



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

def statsd
  @statsd
end

Instance Method Details

#disable!Object



45
46
47
# File 'lib/ventable/statsd/tracker.rb', line 45

def disable!
  self.enabled = false
end

#enable!Object



41
42
43
# File 'lib/ventable/statsd/tracker.rb', line 41

def enable!
  self.enabled = true
end

#handle_event(event) ⇒ Object



66
67
68
69
70
# File 'lib/ventable/statsd/tracker.rb', line 66

def handle_event(event)
  ec      = event_config(event)
  options = ec[:options] || {}
  statsd(ec[:method], *[ec[:name], ec[:value]], **options)
end