Class: Statsd_Taggable::Client
- Inherits:
-
Object
- Object
- Statsd_Taggable::Client
- Defined in:
- lib/statsd_taggable.rb
Instance Method Summary collapse
-
#basic_metrics ⇒ Object
TODO: consider extracting.
- #encode_tags(metric, tags) ⇒ Object
- #expand_tags(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 |
# File 'lib/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_' @client = Statsd.new(@host,@port) end |
Instance Method Details
#basic_metrics ⇒ Object
TODO: consider extracting
36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/statsd_taggable.rb', line 36 def basic_metrics rss, pcpu = `ps -o rss=,pcpu= -p #{Process.pid}`.split rss = rss.to_i pcpu = pcpu.to_f = ({}) puts "Basic rss,pcpu: #{rss} #{pcpu}" gauge "statsd.apps.rss", , rss gauge "statsd.apps.pcpu", , pcpu end |
#encode_tags(metric, tags) ⇒ Object
17 18 19 20 21 22 23 |
# File 'lib/statsd_taggable.rb', line 17 def (metric, ) terms = [metric] .each do |k,v| terms << "#{@tag_prefix}#{sanitize(k)}.#{sanitize(v)}" end terms.join(".") end |
#expand_tags(tags) ⇒ Object
25 26 27 28 29 |
# File 'lib/statsd_taggable.rb', line 25 def ['host'] = `hostname`.strip ['app'] = @app_name end |
#gauge(metric, tags, value) ⇒ Object
13 14 15 |
# File 'lib/statsd_taggable.rb', line 13 def gauge(metric, , value) @client.gauge((metric, ), value) end |
#sanitize(v) ⇒ Object
31 32 33 |
# File 'lib/statsd_taggable.rb', line 31 def sanitize v v.to_s.gsub ".", "_" end |