lib/facter/resolvers/memory_resolver.rb in facter-4.0.41 vs lib/facter/resolvers/memory_resolver.rb in facter-4.0.42

- old
+ new

@@ -23,15 +23,25 @@ @fact_list[fact_name] end def read_system(output) @fact_list[:total] = kilobytes_to_bytes(output.match(/MemTotal:\s+(\d+)\s/)[1]) - @fact_list[:memfree] = kilobytes_to_bytes(output.match(/MemFree:\s+(\d+)\s/)[1]) - @fact_list[:used_bytes] = compute_used(@fact_list[:total], reclaimable_memory(output)) + @fact_list[:memfree] = memfree(output) + @fact_list[:used_bytes] = compute_used(@fact_list[:total], @fact_list[:memfree]) @fact_list[:capacity] = compute_capacity(@fact_list[:used_bytes], @fact_list[:total]) end + def memfree(output) + available = output.match(/MemAvailable:\s+(\d+)\s/) + return kilobytes_to_bytes(available[1]) if available + + buffers = kilobytes_to_bytes(output.match(/Buffers:\s+(\d+)\s/)[1]) + cached = kilobytes_to_bytes(output.match(/Cached:\s+(\d+)\s/)[1]) + memfree = kilobytes_to_bytes(output.match(/MemFree:\s+(\d+)\s/)[1]) + memfree + buffers + cached + end + def read_swap(output) total = output.match(/SwapTotal:\s+(\d+)\s/)[1] return if total.to_i.zero? @fact_list[:swap_total] = kilobytes_to_bytes(total) @@ -40,21 +50,9 @@ @fact_list[:swap_capacity] = compute_capacity(@fact_list[:swap_used_bytes], @fact_list[:swap_total]) end def kilobytes_to_bytes(quantity) quantity.to_i * 1024 - end - - def reclaimable_memory(output) - buffers = kilobytes_to_bytes(output.match(/Buffers:\s+(\d+)\s/)[1]) - cached = kilobytes_to_bytes(output.match(/Cached:\s+(\d+)\s/)[1]) - s_reclaimable = output.match(/SReclaimable:\s+(\d+)\s/) - s_reclaimable = if s_reclaimable - kilobytes_to_bytes(s_reclaimable[1]) - else - 0 - end - @fact_list[:memfree] + buffers + cached + s_reclaimable end def compute_capacity(used, total) format('%<computed_capacity>.2f', computed_capacity: (used / total.to_f * 100)) + '%' end