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

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

Instance Method Summary collapse

Constructor Details

#initialize(context) ⇒ ProcessMemory

Returns a new instance of ProcessMemory.



21
22
23
# File 'lib/scout_apm/instruments/process/process_memory.rb', line 21

def initialize(context)
  @context = context
end

Instance Method Details

#human_nameObject



33
34
35
# File 'lib/scout_apm/instruments/process/process_memory.rb', line 33

def human_name
  "Process Memory"
end

#loggerObject



53
54
55
# File 'lib/scout_apm/instruments/process/process_memory.rb', line 53

def logger
  @context.logger
end

#metric_nameObject



29
30
31
# File 'lib/scout_apm/instruments/process/process_memory.rb', line 29

def metric_name
  "Physical"
end

#metric_typeObject



25
26
27
# File 'lib/scout_apm/instruments/process/process_memory.rb', line 25

def metric_type
  "Memory"
end

#metrics(timestamp, store) ⇒ Object



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

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

#rssObject



13
14
15
# File 'lib/scout_apm/instruments/process/process_memory.rb', line 13

def rss
  ::Process.rusage.maxrss
end

#rss_in_mbObject



17
18
19
# File 'lib/scout_apm/instruments/process/process_memory.rb', line 17

def rss_in_mb
  rss_to_mb(rss)
end

#rss_to_mb(rss) ⇒ Object

Account for Darwin returning maxrss in bytes and Linux in KB. Used by the slow converters. Doesn’t feel like this should go here though…more of a utility.



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

def rss_to_mb(rss)
  kilobyte_adjust = @context.environment.os == 'darwin' ? 1024 : 1
  rss.to_f / 1024 / kilobyte_adjust
end

#runObject



49
50
51
# File 'lib/scout_apm/instruments/process/process_memory.rb', line 49

def run
  rss_in_mb.tap { |res| logger.debug "#{human_name}: #{res.inspect}" }
end