On version 0.25.4 for both server and client. Trying to do some logic around the $memorysize fact. if ($memorysize > 15360) and ($memorysize < 112640) { $tmpfs_size = "6G" } else { $tmpfs_size = "8G" } Returns err: Could not retrieve catalog from remote server: Error 400 on SERVER: comparison of String with 15360 failed at /etc/puppet/modules/mysql/manifests/virtual_tmpdir.pp:13 on node foo.bar -- You received this message because you are subscribed to the Google Groups "Puppet Users" group. To post to this group, send email to puppet-users@googlegroups.com. To unsubscribe from this group, send email to puppet-users+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/puppet-users?hl=en.
Ok some more investigation turned up some more questions. So it seems memorysize is returned with a unit of measurement suffix added to it.... My question to the puppet mailing list would be. How would you use memory size fact in puppet while keeping in mind that we could be talking MB or GB? I need to make decisions based on the amount of memory available. The whole scaling unit of measurement is kind of annoying though. / proc/meminfo normally reports as kb doesnt it? On Mar 8, 11:06 am, John Cesario <john.cesa...@gmail.com> wrote:> On version 0.25.4 for both server and client. > > Trying to do some logic around the $memorysize fact. > > if ($memorysize > 15360) and ($memorysize < 112640) { > $tmpfs_size = "6G" > } else { > $tmpfs_size = "8G" > } > > Returns > > err: Could not retrieve catalog from remote server: Error 400 on SERVER: > comparison of String with 15360 failed at > /etc/puppet/modules/mysql/manifests/virtual_tmpdir.pp:13 on node foo.bar-- You received this message because you are subscribed to the Google Groups "Puppet Users" group. To post to this group, send email to puppet-users@googlegroups.com. To unsubscribe from this group, send email to puppet-users+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/puppet-users?hl=en.
Doug Warner
2010-Mar-08 20:26 UTC
Re: [Puppet Users] Re: memorysize returned as string - maybe
I wrote a "memorysize_mb" fact to solve this problem; this ensures the number returned is only an integer value. $ cat memorysize_mb.rb require ''facter'' Facter.add("memorysize_mb") do confine :kernel => :Linux ram = 0 # Steal linux''s meminfo File.open( "/proc/meminfo" , ''r'' ) do |f| f.grep( /^MemTotal:/ ) { |mem| ram = mem.split( / +/ )[1].to_i / 1024 } end setcode do ram end end On 03/08/2010 03:12 PM, John wrote:> Ok some more investigation turned up some more questions. > So it seems memorysize is returned with a unit of measurement suffix > added to it.... > > My question to the puppet mailing list would be. > > How would you use memory size fact in puppet while keeping in mind > that we could be talking MB or GB? > > I need to make decisions based on the amount of memory available. > The whole scaling unit of measurement is kind of annoying though. / > proc/meminfo normally reports as kb doesnt it? > > On Mar 8, 11:06 am, John Cesario <john.cesa...@gmail.com> wrote: >> On version 0.25.4 for both server and client. >> >> Trying to do some logic around the $memorysize fact. >> >> if ($memorysize > 15360) and ($memorysize < 112640) { >> $tmpfs_size = "6G" >> } else { >> $tmpfs_size = "8G" >> } >> >> Returns >> >> err: Could not retrieve catalog from remote server: Error 400 on SERVER: >> comparison of String with 15360 failed at >> /etc/puppet/modules/mysql/manifests/virtual_tmpdir.pp:13 on node foo.bar >
Ohad Levy
2010-Mar-10 06:24 UTC
Re: [Puppet Users] Re: memorysize returned as string - maybe
another option that I use is to extend the string class in ruby, that would allow you to do something like: Facter.memorysize.to_gb in order to do that add somewhere (e.g. before your custom fact) class String def to_gb begin value,unit=self.match(/(\d+|.+) ([KMG]B)$/i)[1..2] case unit.to_sym when nil, :B, :byte then (value.to_f / 1000_000_000) when :GB, :G, :gigabyte then value.to_f when :MB, :M, :megabyte then (value.to_f / 1000) when :KB, :K, :kilobyte, :kB then (value.to_f / 1000_000) else raise "Unknown unit: #{unit.inspect}!" end rescue raise "Unknown string" end end end Ohad On Tue, Mar 9, 2010 at 4:26 AM, Doug Warner <doug@warner.fm> wrote:> I wrote a "memorysize_mb" fact to solve this problem; this ensures the > number > returned is only an integer value. > > $ cat memorysize_mb.rb > require ''facter'' > > Facter.add("memorysize_mb") do > confine :kernel => :Linux > > ram = 0 > > # Steal linux''s meminfo > File.open( "/proc/meminfo" , ''r'' ) do |f| > f.grep( /^MemTotal:/ ) { |mem| > ram = mem.split( / +/ )[1].to_i / 1024 > } > end > > setcode do > ram > end > end > > > On 03/08/2010 03:12 PM, John wrote: > > Ok some more investigation turned up some more questions. > > So it seems memorysize is returned with a unit of measurement suffix > > added to it.... > > > > My question to the puppet mailing list would be. > > > > How would you use memory size fact in puppet while keeping in mind > > that we could be talking MB or GB? > > > > I need to make decisions based on the amount of memory available. > > The whole scaling unit of measurement is kind of annoying though. / > > proc/meminfo normally reports as kb doesnt it? > > > > On Mar 8, 11:06 am, John Cesario <john.cesa...@gmail.com> wrote: > >> On version 0.25.4 for both server and client. > >> > >> Trying to do some logic around the $memorysize fact. > >> > >> if ($memorysize > 15360) and ($memorysize < 112640) { > >> $tmpfs_size = "6G" > >> } else { > >> $tmpfs_size = "8G" > >> } > >> > >> Returns > >> > >> err: Could not retrieve catalog from remote server: Error 400 on SERVER: > >> comparison of String with 15360 failed at > >> /etc/puppet/modules/mysql/manifests/virtual_tmpdir.pp:13 on node foo.bar > > > > >-- You received this message because you are subscribed to the Google Groups "Puppet Users" group. To post to this group, send email to puppet-users@googlegroups.com. To unsubscribe from this group, send email to puppet-users+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/puppet-users?hl=en.
Michael DeHaan
2010-Mar-10 15:41 UTC
Re: [Puppet Users] Re: memorysize returned as string - maybe
On Wed, Mar 10, 2010 at 1:24 AM, Ohad Levy <ohadlevy@gmail.com> wrote:> another option that I use is to extend the string class in ruby, that would > allow you to do something like: > Facter.memorysize.to_gb > in order to do that add somewhere (e.g. before your custom fact) > class String > def to_gb > begin > value,unit=self.match(/(\d+|.+) ([KMG]B)$/i)[1..2] > case unit.to_sym > when nil, :B, :byte then (value.to_f / 1000_000_000) > when :GB, :G, :gigabyte then value.to_f > when :MB, :M, :megabyte then (value.to_f / 1000) > when :KB, :K, :kilobyte, :kB then (value.to_f / 1000_000) > else raise "Unknown unit: #{unit.inspect}!" > end > rescue > raise "Unknown string" > end > end > end > OhadI''d rather look into fixing the problem than doing code monkeypatching in everyday environments and require folks to write facts to get this data. Let''s look at making things like this available today in facter. Patch material? I generally think facts shouldn''t include units anyway, yet we don''t want to break existing things that depend on them. --Michael -- You received this message because you are subscribed to the Google Groups "Puppet Users" group. To post to this group, send email to puppet-users@googlegroups.com. To unsubscribe from this group, send email to puppet-users+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/puppet-users?hl=en.
Ohad Levy
2010-Mar-10 15:51 UTC
Re: [Puppet Users] Re: memorysize returned as string - maybe
I fully agree - the main reason I''ve done this conversion is because I want to show nice graphs in foreman :) and that was not an option to change everyones facter. Ohad On Wed, Mar 10, 2010 at 11:41 PM, Michael DeHaan <michael@reductivelabs.com>wrote:> On Wed, Mar 10, 2010 at 1:24 AM, Ohad Levy <ohadlevy@gmail.com> wrote: > > another option that I use is to extend the string class in ruby, that > would > > allow you to do something like: > > Facter.memorysize.to_gb > > in order to do that add somewhere (e.g. before your custom fact) > > class String > > def to_gb > > begin > > value,unit=self.match(/(\d+|.+) ([KMG]B)$/i)[1..2] > > case unit.to_sym > > when nil, :B, :byte then (value.to_f / 1000_000_000) > > when :GB, :G, :gigabyte then value.to_f > > when :MB, :M, :megabyte then (value.to_f / 1000) > > when :KB, :K, :kilobyte, :kB then (value.to_f / 1000_000) > > else raise "Unknown unit: #{unit.inspect}!" > > end > > rescue > > raise "Unknown string" > > end > > end > > end > > Ohad > > I''d rather look into fixing the problem than doing code monkeypatching > in everyday environments and require folks to write facts to get this > data. > > Let''s look at making things like this available today in facter. > Patch material? > > I generally think facts shouldn''t include units anyway, yet we don''t > want to break existing things that depend on them. > > --Michael > > -- > You received this message because you are subscribed to the Google Groups > "Puppet Users" group. > To post to this group, send email to puppet-users@googlegroups.com. > To unsubscribe from this group, send email to > puppet-users+unsubscribe@googlegroups.com<puppet-users%2Bunsubscribe@googlegroups.com> > . > For more options, visit this group at > http://groups.google.com/group/puppet-users?hl=en. > >-- You received this message because you are subscribed to the Google Groups "Puppet Users" group. To post to this group, send email to puppet-users@googlegroups.com. To unsubscribe from this group, send email to puppet-users+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/puppet-users?hl=en.
Michael DeHaan
2010-Mar-10 16:01 UTC
Re: [Puppet Users] Re: memorysize returned as string - maybe
On Wed, Mar 10, 2010 at 10:51 AM, Ohad Levy <ohadlevy@gmail.com> wrote:> I fully agree - the main reason I''ve done this conversion is because I want > to show nice graphs in foreman :) and that was not an option to change > everyones facter. > OhadI think it is actually an option. In order to trend facts efficiently (regardless of the app), we need numeric facts. Send us a patch for a numeric fact in facter (and for any other facts that have units), though I think we probably /do/ have to keep the existing ones around. --Michael -- You received this message because you are subscribed to the Google Groups "Puppet Users" group. To post to this group, send email to puppet-users@googlegroups.com. To unsubscribe from this group, send email to puppet-users+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/puppet-users?hl=en.