Created
September 8, 2011 00:28
-
-
Save ahpook/1202271 to your computer and use it in GitHub Desktop.
Custom facter fact for raw memorysize.
This file contains 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
# 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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.