Sha256: 1bf08e9561d211cb4723285a879be4011590c12a5af88acea72e33199f9dbe3c

Contents?: true

Size: 1.2 KB

Versions: 8

Compression:

Stored size: 1.2 KB

Contents

# frozen_string_literal: true

module Facter
  module Resolvers
    module Freebsd
      class SystemMemory < BaseResolver
        @fact_list ||= {}
        class << self
          private

          def post_resolve(fact_name)
            @fact_list.fetch(fact_name) { calculate_system_memory(fact_name) }
          end

          def calculate_system_memory(fact_name)
            read_total_memory_in_bytes
            read_available_memory_in_bytes

            @fact_list[:used_bytes] = @fact_list[:total_bytes] - @fact_list[:available_bytes]
            @fact_list[:capacity] = FilesystemHelper.compute_capacity(@fact_list[:used_bytes], @fact_list[:total_bytes])

            @fact_list[fact_name]
          end

          def read_available_memory_in_bytes
            output = Facter::Core::Execution.execute('vmstat -H --libxo json', logger: log)
            data = JSON.parse(output)
            @fact_list[:available_bytes] = data['memory']['free-memory'] * 1024
          end

          def read_total_memory_in_bytes
            require_relative 'ffi/ffi_helper'

            @fact_list[:total_bytes] = Facter::Freebsd::FfiHelper.sysctl_by_name(:long, 'hw.physmem')
          end
        end
      end
    end
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
facter-4.0.44 lib/facter/resolvers/freebsd/system_memory_resolver.rb
facter-4.0.43 lib/facter/resolvers/freebsd/system_memory_resolver.rb
facter-4.0.42 lib/facter/resolvers/freebsd/system_memory_resolver.rb
facter-4.0.41 lib/facter/resolvers/freebsd/system_memory_resolver.rb
facter-4.0.40 lib/facter/resolvers/freebsd/system_memory_resolver.rb
facter-4.0.39 lib/facter/resolvers/freebsd/system_memory_resolver.rb
facter-4.0.38 lib/facter/resolvers/freebsd/system_memory_resolver.rb
facter-4.0.37 lib/facter/resolvers/freebsd/system_memory_resolver.rb