Class: StatsdTaggable::BasicMetrics

Inherits:
Object
  • Object
show all
Defined in:
lib/statsd-opentsdb-client/statsd_taggable.rb

Instance Method Summary collapse

Constructor Details

#initialize(c) ⇒ BasicMetrics

Returns a new instance of BasicMetrics.



71
72
73
# File 'lib/statsd-opentsdb-client/statsd_taggable.rb', line 71

def initialize(c)
  @client = c
end

Instance Method Details

#emit(tags = {}) ⇒ Object



75
76
77
78
79
80
81
82
83
84
85
86
87
# File 'lib/statsd-opentsdb-client/statsd_taggable.rb', line 75

def emit(tags = {})

  # TODO: ensure shelling out doesn't happen too often, e.g.,
  # preserve a timestamp of the last shell-out, and refuse to shell-out
  # again unless the timestamp is old enough (e.g. 10 seconds)

  rss, pcpu = `ps -o rss=,pcpu= -p #{Process.pid}`.split
  rss = rss.to_i
  pcpu = pcpu.to_f

  @client.gauge_with_tags "statsd.apps.rss", rss, tags
  @client.gauge_with_tags "statsd.apps.pcpu", pcpu, tags
end