class RorVsWild::Metrics::Memory
Constants
- BUFFERS
- CACHED
- MEM_AVAILABLE
- MEM_FREE
- MEM_TOTAL
- PROC_MEMINFO
- SWAP_FREE
- SWAP_TOTAL
Attributes
Public Instance Methods
Source
# File lib/rorvswild/metrics/memory.rb, line 8 def ram_used ram_total - ram_available end
Source
# File lib/rorvswild/metrics/memory.rb, line 12 def swap_used swap_total - swap_free end
Source
# File lib/rorvswild/metrics/memory.rb, line 25 def update return unless info = read_meminfo @ram_total = convert_to_bytes(info[MEM_TOTAL]) @ram_free = convert_to_bytes(info[MEM_FREE]) @ram_available = convert_to_bytes(info[MEM_AVAILABLE]) @ram_buffers = convert_to_bytes(info[BUFFERS]) @ram_cached = convert_to_bytes(info[CACHED]) @swap_total = convert_to_bytes(info[SWAP_TOTAL]) @swap_free = convert_to_bytes(info[SWAP_FREE]) end
Private Instance Methods
Source
# File lib/rorvswild/metrics/memory.rb, line 51 def convert_to_bytes(string) value, unit = string.split value.to_i * units[unit.downcase] end
Source
# File lib/rorvswild/metrics/memory.rb, line 42 def read_meminfo return unless File.readable?(PROC_MEMINFO) File.read(PROC_MEMINFO).split("\n").reduce({}) do |hash, line| name, value = line.split(":") hash[name] = value.strip hash end end
Source
# File lib/rorvswild/metrics/memory.rb, line 38 def units @units ||= {"kb" => 1000, "mb" => 1000 * 1000, "gb" => 1000 * 1000 * 1000}.freeze end