Sha256: 54060b614c62d98b72186c9d1b988a94e3545593b124138605c18d014329a9fb

Contents?: true

Size: 1.27 KB

Versions: 28

Compression:

Stored size: 1.27 KB

Contents

# frozen_string_literal: true

module Facter
  module Resolvers
    module Freebsd
      class SystemMemory < BaseResolver
        init_resolver

        class << self
          private

          def post_resolve(fact_name, _options)
            @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] = Facter::Util::Resolvers::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

28 entries across 28 versions & 1 rubygems

Version Path
facter-4.5.1 lib/facter/resolvers/freebsd/system_memory.rb
facter-4.5.0 lib/facter/resolvers/freebsd/system_memory.rb
facter-4.4.3 lib/facter/resolvers/freebsd/system_memory.rb
facter-4.4.2 lib/facter/resolvers/freebsd/system_memory.rb
facter-4.4.1 lib/facter/resolvers/freebsd/system_memory.rb
facter-4.4.0 lib/facter/resolvers/freebsd/system_memory.rb
facter-4.3.1 lib/facter/resolvers/freebsd/system_memory.rb
facter-4.3.0 lib/facter/resolvers/freebsd/system_memory.rb
facter-4.2.14 lib/facter/resolvers/freebsd/system_memory.rb
facter-4.2.13 lib/facter/resolvers/freebsd/system_memory.rb
facter-4.2.12 lib/facter/resolvers/freebsd/system_memory.rb
facter-4.2.11 lib/facter/resolvers/freebsd/system_memory.rb
facter-4.2.10 lib/facter/resolvers/freebsd/system_memory.rb
facter-4.2.9 lib/facter/resolvers/freebsd/system_memory.rb
facter-4.2.8 lib/facter/resolvers/freebsd/system_memory.rb
facter-4.2.7 lib/facter/resolvers/freebsd/system_memory.rb
facter-4.2.6 lib/facter/resolvers/freebsd/system_memory.rb
facter-4.2.5 lib/facter/resolvers/freebsd/system_memory.rb
facter-4.2.4 lib/facter/resolvers/freebsd/system_memory.rb
facter-4.2.3 lib/facter/resolvers/freebsd/system_memory.rb