Kumina | Blog

Facter facts for memory in bytes

code

code

By default Facter returns the free and total memory and swap of a machine only in GB or MB:
facter | egrep “mem|swap”
memoryfree => 8.95 GB
memorysize => 11.76 GB
swapfree => 972.68 MB
swapsize => 972.68 MB

As we wanted to let the buffer pool size and cache size of a mysql server depend dynamically on the available memory this information wasn’t enough. To remedy this we rewrote the memory.rb bundled with Puppet to return the numbers in bytes. This file can be put in /lib/facter/ in any module. The new output looks like:
sudo facter –puppet | grep inbytes
memoryfreeinbytes => 9608507392
memorysizeinbytes => 12631347200
swapfreeinbytes => 1019924480
swapsizeinbytes => 1019924480

These new facts can be used in a Puppet template as follows:
[mysqld]
key_buffer_size = 64M
innodb_buffer_pool_size = <%= “%.0f” % [memorysizeinbytes.to_f / 2] %>
query_cache_size = <%= “%.0f” % [memorysizeinbytes.to_f / 8] %>

The files:

 

Exit mobile version