class ElasticAPM::Metrics::CpuMem::Linux::Meminfo

@api private

def read!

rubocop:disable Metrics/MethodLength, Metrics/AbcSize
def read!
  # rubocop:disable Style/RescueModifier
  @page_size = `getconf PAGESIZE`.chomp.to_i rescue 4096
  # rubocop:enable Style/RescueModifier
  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
        end
        break hsh if hsh.length == 2
      end
  @total = info[:total]
  @available = info[:available]
  self
end