Class: NewRelic::Agent::Samplers::MemorySampler::Base

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

Direct Known Subclasses

JavaHeapSampler, ProcStatus, ShellPS

Instance Method Summary collapse

Instance Method Details

#can_run?Boolean

Returns:

  • (Boolean)


61
62
63
64
65
# File 'lib/new_relic/agent/samplers/memory_sampler.rb', line 61

def can_run?
  return false if @broken
  m = get_memory rescue nil
  m && m > 0
end

#get_sampleObject



66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
# File 'lib/new_relic/agent/samplers/memory_sampler.rb', line 66

def get_sample
  return nil if @broken
  begin
    m = get_memory
    if m.nil?
      NewRelic::Agent.instance.log.error "Unable to get the resident memory for process #{$$}.  Disabling memory sampler."
      @broken = true
    end
    return m
  rescue => e
    NewRelic::Agent.instance.log.error "Unable to get the resident memory for process #{$$}. (#{e})"
    NewRelic::Agent.instance.log.debug e.backtrace.join("\n  ")
    NewRelic::Agent.instance.log.error "Disabling memory sampler."
    @broken = true
    return nil
  end
end