class StatsdTaggable::Client

Public Class Methods

new(config) click to toggle source
# File lib/statsd-opentsdb-client/statsd_taggable.rb, line 8
def initialize(config)
  @host = config[:host] || 'localhost'
  @port = (config[:port] || 8125).to_i
  @app_name = config[:app_name] || "my_app"
  @tag_prefix = config[:tag_prefix] || '_t_'
  @hostname = `hostname`.split(".").first
  @client = Statsd.new(@host, @port)
  if config.include? :logger
    Statsd.logger = config[:logger]
  end
  @default_tags = {
      'host' => @hostname,
      'app' => @app_name
  }
end

Public Instance Methods

count_with_tags(metric, count, tags, sample_rate = 1) click to toggle source
# File lib/statsd-opentsdb-client/statsd_taggable.rb, line 37
def count_with_tags (metric, count, tags, sample_rate = 1)
  with_tagged_name(metric, tags) { |new_metric_name| @client.count(new_metric_name, count, sample_rate) }
end
decrement_with_tags(metric, tags, sample_rate = 1) click to toggle source
# File lib/statsd-opentsdb-client/statsd_taggable.rb, line 33
def decrement_with_tags (metric, tags, sample_rate = 1)
  with_tagged_name(metric, tags) { |new_metric_name| @client.decrement(new_metric_name, sample_rate) }
end
gauge_with_tags(metric, value, tags, sample_rate = 1) click to toggle source
# File lib/statsd-opentsdb-client/statsd_taggable.rb, line 25
def gauge_with_tags (metric, value, tags, sample_rate = 1)
  with_tagged_name(metric, tags) { |new_metric_name| @client.gauge(new_metric_name, *[value, sample_rate]) }
end
increment_with_tags(metric, tags, sample_rate = 1) click to toggle source
# File lib/statsd-opentsdb-client/statsd_taggable.rb, line 29
def increment_with_tags (metric, tags, sample_rate = 1)
  with_tagged_name(metric, tags) { |new_metric_name| @client.increment(new_metric_name, sample_rate) }
end
set_with_tags(metric, value, tags, sample_rate = 1) click to toggle source
# File lib/statsd-opentsdb-client/statsd_taggable.rb, line 41
def set_with_tags (metric, value, tags, sample_rate = 1)
  with_tagged_name(metric, tags) { |new_metric_name| @client.set(new_metric_name, value, sample_rate) }
end
time_with_tags(metric, tags, sample_rate = 1, &block) click to toggle source
# File lib/statsd-opentsdb-client/statsd_taggable.rb, line 49
def time_with_tags (metric, tags, sample_rate = 1, &block)
  with_tagged_name(metric, tags) { |new_metric_name| @client.time(new_metric_name, sample_rate, &block) }
end
timing_with_tags(metric, tim, tags, sample_rate = 1) click to toggle source
# File lib/statsd-opentsdb-client/statsd_taggable.rb, line 45
def timing_with_tags (metric, tim, tags, sample_rate = 1)
  with_tagged_name(metric, tags) { |new_metric_name| @client.timing(new_metric_name, tim, sample_rate) }
end

Protected Instance Methods

encode_tags(metric, tags) click to toggle source
# File lib/statsd-opentsdb-client/statsd_taggable.rb, line 59
def encode_tags(metric, tags)
  tags.inject([metric]) do |memo, (k, v)|
    memo << "#{@tag_prefix}#{sanitize(k)}.#{sanitize(v)}"
  end.join(".")
end
sanitize(v) click to toggle source
# File lib/statsd-opentsdb-client/statsd_taggable.rb, line 65
def sanitize v
  v.to_s.gsub ".", "_"
end
with_tagged_name(metric, tags) { |encode_tags(metric, merge)| ... } click to toggle source
# File lib/statsd-opentsdb-client/statsd_taggable.rb, line 55
def with_tagged_name (metric, tags)
  yield encode_tags(metric, tags.merge(@default_tags))
end