-
Notifications
You must be signed in to change notification settings - Fork 495
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Re-adding these files, since Matt has found a solution to the hanging…
… problem. git-svn-id: http://reductivelabs.com/svn/facter/trunk@146 1f5c1d6a-bddf-0310-8f58-fc49e503516a
- Loading branch information
luke
committed
Jun 27, 2006
1 parent
ba2e189
commit ace180f
Showing
2 changed files
with
106 additions
and
0 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
# | ||
# memory.rb | ||
# Additional Facts for memory/swap usage | ||
# | ||
# Copyright (C) 2006 Mooter Media Ltd | ||
# Author: Matthew Palmer <matt@solutionsfirst.com.au> | ||
# | ||
# This program is free software; you can redistribute it and/or | ||
# modify it under the terms of the GNU General Public License | ||
# as published by the Free Software Foundation (version 2 of the License) | ||
# This program is distributed in the hope that it will be useful, | ||
# but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
# GNU General Public License for more details. | ||
# You should have received a copy of the GNU General Public License | ||
# along with this program; if not, write to the Free Software | ||
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston MA 02110-1301 USA | ||
|
||
module Facter::Memory | ||
def self.meminfo_number(tag) | ||
memsize = "" | ||
File.readlines("/proc/meminfo").each do |l| | ||
if l =~ /^#{tag}:\s+(\d+)\s+(\S+)/ | ||
memsize = scale_number($1.to_f, $2) | ||
end | ||
end | ||
|
||
memsize | ||
end | ||
|
||
def self.scale_number(size, multiplier) | ||
suffixes = ['', 'kB', 'MB', 'GB', 'TB'] | ||
|
||
s = suffixes.shift | ||
while s != multiplier | ||
s = suffixes.shift | ||
end | ||
|
||
while size > 1024.0 | ||
size /= 1024.0 | ||
s = suffixes.shift | ||
end | ||
|
||
return "%.2f %s" % [size, s] | ||
end | ||
end | ||
|
||
{:MemorySize => "MemTotal", | ||
:MemoryFree => "MemFree", | ||
:SwapSize => "SwapTotal", | ||
:SwapFree => "SwapFree"}.each do |fact, name| | ||
Facter.add(fact) do | ||
confine :kernel => :linux | ||
setcode do | ||
Facter::Memory.meminfo_number(name) | ||
end | ||
end | ||
end |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
# | ||
# processor.rb | ||
# Additional Facts about the machine's CPUs | ||
# | ||
# Copyright (C) 2006 Mooter Media Ltd | ||
# Author: Matthew Palmer <matt@solutionsfirst.com.au> | ||
# | ||
# | ||
# This program is free software; you can redistribute it and/or | ||
# modify it under the terms of the GNU General Public License | ||
# as published by the Free Software Foundation (version 2 of the License) | ||
# This program is distributed in the hope that it will be useful, | ||
# but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
# GNU General Public License for more details. | ||
# You should have received a copy of the GNU General Public License | ||
# along with this program; if not, write to the Free Software | ||
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston MA 02110-1301 USA | ||
# | ||
|
||
if Facter.kernel == "Linux" | ||
processor_num = -1 | ||
processor_list = [] | ||
File.readlines("/proc/cpuinfo").each do |l| | ||
if l =~ /processor\s+:\s+(\d+)/ | ||
processor_num = $1.to_i | ||
elsif l =~ /model name\s+:\s+(.*)\s*$/ | ||
processor_list[processor_num] = $1 unless processor_num == -1 | ||
processor_num = -1 | ||
end | ||
end | ||
|
||
Facter.add("ProcessorCount") do | ||
confine :kernel => :linux | ||
setcode do | ||
processor_list.length.to_s | ||
end | ||
end | ||
|
||
processor_list.each_with_index do |desc, i| | ||
Facter.add("Processor#{i}") do | ||
confine :kernel => :linux | ||
setcode do | ||
desc | ||
end | ||
end | ||
end | ||
end |