Skip to content

Instantly share code, notes, and snippets.

@ahpook
Created September 8, 2011 00:28
Show Gist options
  • Save ahpook/1202271 to your computer and use it in GitHub Desktop.
Save ahpook/1202271 to your computer and use it in GitHub Desktop.
Custom facter fact for raw memorysize.
# for some reason facter takes the raw memorysize and reports it as
# a formatted string, which is useless for calculation
#
Facter.add("memorysize_raw") do
confine :kernel => :linux
setcode do
size = 0
File.readlines("/proc/meminfo").each do |l|
size = $1.to_f if l =~ /^MemTotal:\s+(\d+)/
end
size
end
end
@scurvy
Copy link

scurvy commented Mar 4, 2012

Found this through Google, but you shouldn't rely on MemTotal from meminfo. That value can actually change as kernel modules leak memory. It's not grabbed from anything physical, it's a sum of all the other memory columns. Just wanted to let you (and others) about this as we just got bit by it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment