Class: Tnw::Metrics::Parsers::ProcMeminfo

Inherits:
Object
  • Object
show all
Defined in:
lib/tnw/metrics/parsers/proc_meminfo.rb

Constant Summary collapse

KIBIBYTE =
1024

Class Method Summary collapse

Class Method Details

.parse(output) ⇒ Object

Raises:



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/tnw/metrics/parsers/proc_meminfo.rb', line 7

def self.parse(output)
  values = output.each_line.to_h do |line|
    key, value = line.split(":", 2)
    [ key, value.to_s.split.first ]
  end

  total = kibibytes(values, "MemTotal")
  available = kibibytes(values, "MemAvailable")
  raise ParseError, "/proc/meminfo reports available memory above total memory" if available > total

  {
    total_bytes: total,
    used_bytes: total - available,
    available_bytes: available
  }
end