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

Constructor Details

#initializeBase

Returns a new instance of Base.



72
73
74
# File 'lib/new_relic/agent/samplers/memory_sampler.rb', line 72

def initialize
  @broken = false
end

Instance Method Details

#can_run?Boolean

Returns:

  • (Boolean)


76
77
78
79
80
81
# File 'lib/new_relic/agent/samplers/memory_sampler.rb', line 76

def can_run?
  return false if @broken

  m = get_memory rescue nil
  m && m > 0
end

#get_sampleObject



83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
# File 'lib/new_relic/agent/samplers/memory_sampler.rb', line 83

def get_sample
  return nil if @broken

  begin
    m = get_memory
    if m.nil?
      ::NewRelic::Agent.logger.warn("Unable to get the resident memory for process #{$$}.  Disabling memory sampler.")
      @broken = true
    end
    return m
  rescue => e
    ::NewRelic::Agent.logger.warn("Unable to get the resident memory for process #{$$}. Disabling memory sampler.", e)
    @broken = true
    return nil
  end
end