Class: Metrics::Drivers::Statsd
- Inherits:
-
Object
- Object
- Metrics::Drivers::Statsd
- Defined in:
- lib/metrics/drivers/statsd.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#client ⇒ Object
readonly
Returns the value of attribute client.
-
#source_prefix ⇒ Object
readonly
Returns the value of attribute source_prefix.
-
#template ⇒ Object
readonly
Returns the value of attribute template.
Instance Method Summary collapse
- #emit(instrumenter) ⇒ Object
-
#initialize(client, template, source_prefix) ⇒ Statsd
constructor
A new instance of Statsd.
- #write(*instrumenters) ⇒ Object
Constructor Details
#initialize(client, template, source_prefix) ⇒ Statsd
Returns a new instance of Statsd.
5 6 7 8 9 |
# File 'lib/metrics/drivers/statsd.rb', line 5 def initialize(client, template, source_prefix) @client = client # The statsd client @template = template # The template for the metric name @source_prefix = source_prefix # Source prefix end |
Instance Attribute Details
#client ⇒ Object (readonly)
Returns the value of attribute client.
3 4 5 |
# File 'lib/metrics/drivers/statsd.rb', line 3 def client @client end |
#source_prefix ⇒ Object (readonly)
Returns the value of attribute source_prefix.
3 4 5 |
# File 'lib/metrics/drivers/statsd.rb', line 3 def source_prefix @source_prefix end |
#template ⇒ Object (readonly)
Returns the value of attribute template.
3 4 5 |
# File 'lib/metrics/drivers/statsd.rb', line 3 def template @template end |
Instance Method Details
#emit(instrumenter) ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/metrics/drivers/statsd.rb', line 18 def emit(instrumenter) name = name_for(instrumenter) value = instrumenter.value case instrumenter.type when 'histogram' client.histogram(name, value) when 'measure', 'sample' if instrumenter.units == 'ms' client.timing(name, value) else client.gauge(name, value) end when 'count' client.count(name, value) else raise ArgumentError.new("unsupported instrumenter type for statsd: '%s'" % instrumenter.type) end end |
#write(*instrumenters) ⇒ Object
11 12 13 14 15 16 |
# File 'lib/metrics/drivers/statsd.rb', line 11 def write(*instrumenters) instrumenters.each do |instrumenter| emit(instrumenter) end instrumenters end |