in lib/elastic_apm/metrics/cpu_mem_set.rb [222:252]
def read!
@page_size = `getconf PAGESIZE`.chomp.to_i rescue 4096
info =
IO.readlines('/proc/meminfo')
.lazy
.each_with_object({}) do |line, hsh|
if line.start_with?('MemTotal:')
hsh[:total] = line.split[1].to_i * 1024
elsif line.start_with?('MemAvailable:')
hsh[:available] = line.split[1].to_i * 1024
elsif line.start_with?('MemFree:')
hsh[:free] = line.split[1].to_i * 1024
elsif line.start_with?('Buffers:')
hsh[:buffers] = line.split[1].to_i * 1024
elsif line.start_with?('Cached:')
hsh[:cached] = line.split[1].to_i * 1024
end
break hsh if hsh[:total] && hsh[:available]
end
@total = info[:total]
@available =
info[:available] || info[:free] + info[:buffers] + info[:cached]
self
end