Class: NewRelic::Agent::Samplers::MemorySampler::ShellPS

Inherits:
Base
  • Object
show all
Defined in:
lib/new_relic/agent/samplers/memory_sampler.rb

Instance Method Summary collapse

Methods inherited from Base

#can_run?, #get_sample

Constructor Details

#initialize(command) ⇒ ShellPS

Returns a new instance of ShellPS.



95
96
97
98
# File 'lib/new_relic/agent/samplers/memory_sampler.rb', line 95

def initialize(command)
  super()
  @command = command
end

Instance Method Details

#get_memoryObject

Returns the amount of resident memory this process is using in MB



101
102
103
104
105
106
107
108
# File 'lib/new_relic/agent/samplers/memory_sampler.rb', line 101

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_sObject



109
110
111
# File 'lib/new_relic/agent/samplers/memory_sampler.rb', line 109

def to_s
  "shell command sampler: #{@command}"
end