Class: StatsdTaggable::Client
- Inherits:
-
Object
- Object
- StatsdTaggable::Client
- Defined in:
- lib/statsd-opentsdb-client/statsd_taggable.rb
Instance Method Summary collapse
- #encode_tags(metric, tags) ⇒ Object
- #gauge(metric, tags, value) ⇒ Object
-
#initialize(config) ⇒ Client
constructor
A new instance of Client.
- #sanitize(v) ⇒ Object
Constructor Details
#initialize(config) ⇒ Client
Returns a new instance of Client.
5 6 7 8 9 10 11 12 13 14 15 16 |
# File 'lib/statsd-opentsdb-client/statsd_taggable.rb', line 5 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`.to_s.strip.split(".").first @client = Statsd.new(@host,@port) @default_tags = { 'host' => @hostname, 'app' => @app_name } end |
Instance Method Details
#encode_tags(metric, tags) ⇒ Object
22 23 24 25 26 |
# File 'lib/statsd-opentsdb-client/statsd_taggable.rb', line 22 def (metric, ) .inject([metric]) do |memo, (k,v)| memo << "#{@tag_prefix}#{sanitize(k)}.#{sanitize(v)}" end.join(".") end |
#gauge(metric, tags, value) ⇒ Object
18 19 20 |
# File 'lib/statsd-opentsdb-client/statsd_taggable.rb', line 18 def gauge(metric, , value) @client.gauge((metric, .merge(@default_tags)), value) end |
#sanitize(v) ⇒ Object
28 29 30 |
# File 'lib/statsd-opentsdb-client/statsd_taggable.rb', line 28 def sanitize v v.to_s.gsub ".", "_" end |