Class: ScoutApm::Instruments::Process::ProcessMemory

Inherits:
Object
  • Object
show all
Defined in:
lib/scout_apm/instruments/process/process_memory.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(logger) ⇒ ProcessMemory

Returns a new instance of ProcessMemory.



7
8
9
# File 'lib/scout_apm/instruments/process/process_memory.rb', line 7

def initialize(logger)
  @logger = logger
end

Instance Attribute Details

#loggerObject (readonly)

Returns the value of attribute logger.



5
6
7
# File 'lib/scout_apm/instruments/process/process_memory.rb', line 5

def logger
  @logger
end

Instance Method Details

#human_nameObject



19
20
21
# File 'lib/scout_apm/instruments/process/process_memory.rb', line 19

def human_name
  "Process Memory"
end

#metric_nameObject



15
16
17
# File 'lib/scout_apm/instruments/process/process_memory.rb', line 15

def metric_name
  "Physical"
end

#metric_typeObject



11
12
13
# File 'lib/scout_apm/instruments/process/process_memory.rb', line 11

def metric_type
  "Memory"
end

#metrics(_time) ⇒ Object



23
24
25
26
27
28
29
30
31
32
33
# File 'lib/scout_apm/instruments/process/process_memory.rb', line 23

def metrics(_time)
  result = run
  if result
    meta = MetricMeta.new("#{metric_type}/#{metric_name}")
    stat = MetricStats.new(false)
    stat.update!(result)
    { meta => stat }
  else
    {}
  end
end

#runObject



35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/scout_apm/instruments/process/process_memory.rb', line 35

def run
  case RUBY_PLATFORM.downcase
  when /linux/
    get_mem_from_procfile
  when /darwin9/ # 10.5
    get_mem_from_shell("ps -o rsz")
  when /darwin1[01234]/ # 10.6 - 10.11
    get_mem_from_shell("ps -o rss")
  else
    0 # What default? was nil.
  end.tap { |res| logger.debug "#{human_name}: #{res.inspect}" }
end