Class: NatsWork::StatsDCollector

Inherits:
MetricsCollector show all
Defined in:
lib/natswork/metrics.rb

Overview

StatsD metrics collector

Instance Method Summary collapse

Constructor Details

#initialize(client) ⇒ StatsDCollector

Returns a new instance of StatsDCollector.



220
221
222
# File 'lib/natswork/metrics.rb', line 220

def initialize(client)
  @client = client
end

Instance Method Details

#collect(type, metric, value, tags) ⇒ Object



224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
# File 'lib/natswork/metrics.rb', line 224

def collect(type, metric, value, tags)
  metric_name = tags.empty? ? metric : "#{metric}.#{tags.map { |k, v| "#{k}_#{v}" }.join('.')}"

  case type
  when :counter
    @client.increment(metric_name, value)
  when :gauge
    @client.gauge(metric_name, value)
  when :histogram
    @client.histogram(metric_name, value)
  when :timer
    @client.timing(metric_name, value)
  end
rescue StandardError
  # Log but don't raise
end