Facter facts for memory in bytes

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:

Tags: ,


3 Responses to “Facter facts for memory in bytes”

  1. Chris says:

    Thanks a lot! I was surprised how useless the standard memory-facts still are today. Luckily, now I can finally scale tuning stuff without hacking strings like “1445 MB” first.

  2. Thanks! I’ve been using these facts a lot. It is indeed surprising these are not standard facts

  3. sriram says:

    Great!! Thank you very much.

Leave a Reply