Created
July 9, 2014 10:37
-
-
Save johnyzed/8bed34f99667ace51016 to your computer and use it in GitHub Desktop.
facter script that create custom facts on the memory of the node
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'facter' | |
{ :MemorySizeRaw => "MemTotal", | |
:MemoryFreeRaw => "MemFree", | |
:SwapSizeRaw => "SwapTotal", | |
:SwapFreeRaw => "SwapFree" | |
}.each do |fact, name| | |
Facter.add(fact) do | |
confine :kernel => :linux | |
setcode do | |
memsize_raw = "" | |
Thread::exclusive do | |
File.readlines("/proc/meminfo").each do |l| | |
memsize_raw = $1.to_i if l =~ /^#{name}:\s+(\d+)\s+\S+/ | |
# MemoryFree == memfree + cached + buffers | |
# (assume scales are all the same as memfree) | |
if name == "MemFree" && | |
l =~ /^(?:Buffers|Cached):\s+(\d+)\s+\S+/ | |
memsize_raw += $1.to_i | |
end | |
end | |
end | |
memsize_raw | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment