[PATCH/facter 1/1] (#1423) Memory facts for Solaris

2 views
Skip to first unread message

Dominic Cleal

unread,
Nov 30, 2010, 7:27:24 AM11/30/10
to puppe...@googlegroups.com
Add total memory from prtconf output, free from vmstat plus swap free and
total from swap -l listing.

Signed-off-by: Dominic Cleal <dcl...@redhat.com>
---
Local-branch: tickets/master/1423
lib/facter/memory.rb | 51 ++++++++++++++++++++++++++++++++++++++------
lib/facter/util/memory.rb | 12 ++++++++++
2 files changed, 56 insertions(+), 7 deletions(-)

diff --git a/lib/facter/memory.rb b/lib/facter/memory.rb
index 06640e6..f744c3f 100644
--- a/lib/facter/memory.rb
+++ b/lib/facter/memory.rb
@@ -69,13 +69,7 @@ if Facter.value(:kernel) == "OpenBSD"
end
end

- Facter.add("MemoryFree") do
- confine :kernel => :openbsd
- memfree = Facter::Util::Resolution.exec("vmstat | tail -n 1 | awk '{ print $5 }'")
- setcode do
- Facter::Memory.scale_number(memfree.to_f,"kB")
- end
- end
+ Facter::Memory.vmstat_find_free_memory()

Facter.add("MemoryTotal") do
confine :kernel => :openbsd
@@ -85,3 +79,46 @@ if Facter.value(:kernel) == "OpenBSD"
end
end
end
+
+if Facter.value(:kernel) == "SunOS"
+ swap = Facter::Util::Resolution.exec('/usr/sbin/swap -l')
+ swapfree, swaptotal = 0, 0
+ swap.each do |dev|
+ if dev =~ /^\/\S+\s.*\s+(\d+)\s+(\d+)$/
+ swaptotal += $1.to_i / 2
+ swapfree += $2.to_i / 2
+ end
+ end
+
+ Facter.add("SwapSize") do
+ confine :kernel => :sunos
+ setcode do
+ Facter::Memory.scale_number(swaptotal.to_f,"kB")
+ end
+ end
+
+ Facter.add("SwapFree") do
+ confine :kernel => :sunos
+ setcode do
+ Facter::Memory.scale_number(swapfree.to_f,"kB")
+ end
+ end
+
+ # Total memory size available from prtconf
+ pconf = Facter::Util::Resolution.exec('/usr/sbin/prtconf')
+ phymem = ""
+ pconf.each do |line|
+ if line =~ /^Memory size:\s+(\d+) Megabytes/
+ phymem = $1
+ end
+ end
+
+ Facter.add("MemorySize") do
+ confine :kernel => :sunos
+ setcode do
+ Facter::Memory.scale_number(phymem.to_f,"MB")
+ end
+ end
+
+ Facter::Memory.vmstat_find_free_memory()
+end
diff --git a/lib/facter/util/memory.rb b/lib/facter/util/memory.rb
index 2004491..43abec6 100644
--- a/lib/facter/util/memory.rb
+++ b/lib/facter/util/memory.rb
@@ -50,5 +50,17 @@ module Facter::Memory

return "%.2f %s" % [size, s]
end
+
+ def self.vmstat_find_free_memory()
+ row = Facter::Util::Resolution.exec('vmstat').split("\n")[-1]
+ if row =~ /^\s*\d+\s*\d+\s*\d+\s*\d+\s*(\d+)/
+ Facter.add("MemoryFree") do
+ memfree = $1
+ setcode do
+ Facter::Memory.scale_number(memfree.to_f, "kB")
+ end
+ end
+ end
+ end
end

--
1.7.3.2

Paul Berry

unread,
Dec 2, 2010, 6:27:16 PM12/2/10
to puppe...@googlegroups.com
It looks like there are two independent changes here.  In addition to adding facts for SunOS, this change refactors the OpenBSD MemoryFree fact, moving it to util/memory.rb and rewriting it to use a regular expression.  Was the OpenBSD change intentional?  Because if so it should probably be in a separate commit, and also it probably could be better written using split() rather than a regular expression to pick out the fifth column.

Regarding the SunOS changes, we are in the process of moving offices so our solaris box is unavailable, but we should be able to test the Solaris-related facts in the next week.

Paul Nasrat

unread,
Dec 3, 2010, 4:33:44 AM12/3/10
to puppe...@googlegroups.com

Looks like it was basically extract method for common usage between
OpenBSD and SunOS

> Was the
> OpenBSD change intentional?  Because if so it should probably be in a
> separate commit, and also it probably could be better written using split()

Ideally yeah but tbh, I'd rather fix the platform support. Getting
community patches is valuable

> rather than a regular expression to pick out the fifth column.
> Regarding the SunOS changes, we are in the process of moving offices so our
> solaris box is unavailable, but we should be able to test the
> Solaris-related facts in the next week.

Umm EC2 OpenSolaris images? Obviously that doesn't help for sparc
specific things but you really should be able to test things whilst
your testlab is down.

Have you considered getting a cage in a DC for your test equipment as
that seems like it'd make sense.

Paul

Dominic Cleal

unread,
Dec 3, 2010, 5:41:22 AM12/3/10
to puppe...@googlegroups.com
On 02/12/10 23:27, Paul Berry wrote:
> On Tue, Nov 30, 2010 at 4:27 AM, Dominic Cleal <dcl...@redhat.com
> <mailto:dcl...@redhat.com>> wrote:
>
> Add total memory from prtconf output, free from vmstat plus swap
> free and
> total from swap -l listing.
>
> Signed-off-by: Dominic Cleal <dcl...@redhat.com
> <mailto:dcl...@redhat.com>>

>
> It looks like there are two independent changes here. In addition to
> adding facts for SunOS, this change refactors the OpenBSD MemoryFree
> fact, moving it to util/memory.rb and rewriting it to use a regular
> expression. Was the OpenBSD change intentional? Because if so it
> should probably be in a separate commit, and also it probably could be
> better written using split() rather than a regular expression to pick
> out the fifth column.

Thanks for the feedback Paul. The change was intentional as the Solaris
MemoryFree code would have been identical. I'll resubmit this as two
separate commits and use split().

Cheers,

--
Dominic Cleal
Red Hat Consulting
m: +44 (0)7818 512168

Paul Nasrat

unread,
Dec 3, 2010, 6:31:26 AM12/3/10
to puppe...@googlegroups.com

Cool - yeah use a single branch and two commits and mail_patches will
do the right thing in making it a patch series.

Paul

Dominic Cleal

unread,
Dec 3, 2010, 1:45:23 PM12/3/10
to puppe...@googlegroups.com
Add total memory from prtconf output, free from vmstat plus swap free and
total from swap -l listing.

Signed-off-by: Dominic Cleal <dcl...@redhat.com>
---
Local-branch: tickets/master/1423
lib/facter/memory.rb | 43 +++++++++++++++++++++++++++++++++++++++++++
1 files changed, 43 insertions(+), 0 deletions(-)

diff --git a/lib/facter/memory.rb b/lib/facter/memory.rb
index 8eab377..f744c3f 100644
--- a/lib/facter/memory.rb
+++ b/lib/facter/memory.rb
@@ -79,3 +79,46 @@ if Facter.value(:kernel) == "OpenBSD"

--
1.7.3.2

Dominic Cleal

unread,
Dec 3, 2010, 1:45:22 PM12/3/10
to puppe...@googlegroups.com
Moved vmstat exec to Facter::Memory::Util so it can used to retrieve free
memory in the same way on Solaris.

Signed-off-by: Dominic Cleal <dcl...@redhat.com>
---
Local-branch: tickets/master/1423

lib/facter/memory.rb | 8 +-------
lib/facter/util/memory.rb | 10 ++++++++++
2 files changed, 11 insertions(+), 7 deletions(-)

diff --git a/lib/facter/memory.rb b/lib/facter/memory.rb
index 06640e6..8eab377 100644
--- a/lib/facter/memory.rb
+++ b/lib/facter/memory.rb
@@ -69,13 +69,7 @@ if Facter.value(:kernel) == "OpenBSD"
end
end


- Facter.add("MemoryFree") do
- confine :kernel => :openbsd
- memfree = Facter::Util::Resolution.exec("vmstat | tail -n 1 | awk '{ print $5 }'")
- setcode do
- Facter::Memory.scale_number(memfree.to_f,"kB")
- end
- end
+ Facter::Memory.vmstat_find_free_memory()

Facter.add("MemoryTotal") do
confine :kernel => :openbsd

diff --git a/lib/facter/util/memory.rb b/lib/facter/util/memory.rb
index 2004491..5687ff2 100644
--- a/lib/facter/util/memory.rb
+++ b/lib/facter/util/memory.rb
@@ -50,5 +50,15 @@ module Facter::Memory



return "%.2f %s" % [size, s]
end
+
+ def self.vmstat_find_free_memory()
+ row = Facter::Util::Resolution.exec("vmstat").split("\n")[-1]

+ Facter.add("MemoryFree") do

+ memfree = row.split[4]
+ setcode do
+ Facter::Memory.scale_number(memfree.to_f, "kB")
+ end
+ end
+ end
end

--
1.7.3.2

Matt Robinson

unread,
Dec 6, 2010, 2:41:06 PM12/6/10
to puppe...@googlegroups.com
+1. Merged into facter's next.

> --
> You received this message because you are subscribed to the Google Groups "Puppet Developers" group.
> To post to this group, send email to puppe...@googlegroups.com.
> To unsubscribe from this group, send email to puppet-dev+...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/puppet-dev?hl=en.
>
>

Reply all
Reply to author
Forward
0 new messages