lib/facter/resolvers/memory_resolver.rb in facter-4.0.35 vs lib/facter/resolvers/memory_resolver.rb in facter-4.0.36
- old
+ new
@@ -25,11 +25,11 @@
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], @fact_list[:memfree])
+ @fact_list[:used_bytes] = compute_used(@fact_list[:total], reclaimable_memory(output))
@fact_list[:capacity] = compute_capacity(@fact_list[:used_bytes], @fact_list[:total])
end
def read_swap(output)
total = output.match(/SwapTotal:\s+(\d+)\s/)[1]
@@ -41,9 +41,16 @@
@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 = kilobytes_to_bytes(output.match(/SReclaimable:\s+(\d+)\s/)[1])
+ @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