Sha256: 49af812866a76f0d0c695efbd3b3a4b13dc0b2e0c0391c496e8efaaf4e7b5ddd

Contents?: true

Size: 1.55 KB

Versions: 8

Compression:

Stored size: 1.55 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_used_memory_in_bytes

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

            @fact_list[fact_name]
          end

          def pagesize
            @pagesize ||= Facter::Freebsd::FfiHelper.sysctl_by_name(:long, 'vm.stats.vm.v_page_size')
          end

          def read_used_memory_in_bytes
            require_relative 'ffi/ffi_helper'

            @fact_list[:used_bytes] = pagesize * (
              Facter::Freebsd::FfiHelper.sysctl_by_name(:long, 'vm.stats.vm.v_active_count') +
              Facter::Freebsd::FfiHelper.sysctl_by_name(:long, 'vm.stats.vm.v_wire_count')
            )
          end

          def read_total_memory_in_bytes
            require_relative 'ffi/ffi_helper'

            @fact_list[:total_bytes] = pagesize *
                                       Facter::Freebsd::FfiHelper.sysctl_by_name(:long, 'vm.stats.vm.v_page_count')
          end
        end
      end
    end
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
facter-4.10.0 lib/facter/resolvers/freebsd/system_memory.rb
facter-4.9.0 lib/facter/resolvers/freebsd/system_memory.rb
facter-4.8.0 lib/facter/resolvers/freebsd/system_memory.rb
facter-4.7.1 lib/facter/resolvers/freebsd/system_memory.rb
facter-4.7.0 lib/facter/resolvers/freebsd/system_memory.rb
facter-4.6.1 lib/facter/resolvers/freebsd/system_memory.rb
facter-4.6.0 lib/facter/resolvers/freebsd/system_memory.rb
facter-4.5.2 lib/facter/resolvers/freebsd/system_memory.rb