Class: TingYun::Agent::Collector::MemorySampler::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/ting_yun/agent/collector/middle_ware_collector/memory_sampler.rb

Direct Known Subclasses

ProcStatus, ShellPS

Instance Method Summary collapse

Constructor Details

#initializeBase

Returns a new instance of Base.



59
60
61
# File 'lib/ting_yun/agent/collector/middle_ware_collector/memory_sampler.rb', line 59

def initialize
  @broken = false
end

Instance Method Details

#can_run?Boolean

Returns:

  • (Boolean)


63
64
65
66
67
# File 'lib/ting_yun/agent/collector/middle_ware_collector/memory_sampler.rb', line 63

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

#get_memoryObject



69
70
71
# File 'lib/ting_yun/agent/collector/middle_ware_collector/memory_sampler.rb', line 69

def get_memory
  raise 'Implement in the subclass'
end

#get_sampleObject



73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
# File 'lib/ting_yun/agent/collector/middle_ware_collector/memory_sampler.rb', line 73

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