Class: TingYun::Agent::Collector::MemorySampler::ShellPS
- Defined in:
- lib/ting_yun/agent/collector/middle_ware_collector/memory_sampler.rb
Instance Method Summary collapse
-
#get_memory ⇒ Object
Returns the amount of resident memory this process is using in MB.
-
#initialize(command) ⇒ ShellPS
constructor
A new instance of ShellPS.
- #to_s ⇒ Object
Methods inherited from Base
Constructor Details
#initialize(command) ⇒ ShellPS
Returns a new instance of ShellPS.
91 92 93 94 |
# File 'lib/ting_yun/agent/collector/middle_ware_collector/memory_sampler.rb', line 91 def initialize(command) super() @command = command end |
Instance Method Details
#get_memory ⇒ Object
Returns the amount of resident memory this process is using in MB
98 99 100 101 102 103 104 105 |
# File 'lib/ting_yun/agent/collector/middle_ware_collector/memory_sampler.rb', line 98 def get_memory process = $$ memory = `#{@command} #{process}`.split("\n")[1].to_f / 1024.0 rescue nil # if for some reason the ps command doesn't work on the resident os, # then don't execute it any more. raise "Faulty command: `#{@command} #{process}`" if memory.nil? || memory <= 0 memory end |
#to_s ⇒ Object
107 108 109 |
# File 'lib/ting_yun/agent/collector/middle_ware_collector/memory_sampler.rb', line 107 def to_s "shell command sampler: #{@command}" end |