Sha256: 1471864308352d505b2b935f41e8300e1bd70019469f13a08a8e51d6c68fd186

Contents?: true

Size: 1.1 KB

Versions: 15

Compression:

Stored size: 1.1 KB

Contents

# frozen_string_literal: true

module Facter
  module Resolvers
    module Solaris
      class Processors < BaseResolver
        @semaphore = Mutex.new
        @fact_list ||= {}
        class << self
          private

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

          def collect_kstat_info(fact_name)
            return unless File.executable?('/usr/bin/kstat')

            kstat_output = Facter::Core::Execution.execute('/usr/bin/kstat -m cpu_info', logger: log)
            return if kstat_output.empty?

            parse_output(kstat_output.chomp)
            @fact_list[fact_name]
          end

          def parse_output(output)
            @fact_list[:logical_count] = output.scan(/module/).size
            @fact_list[:physical_count] = output.scan(/chip_id .*/).uniq.size
            @fact_list[:speed] = output.scan(/current_clock_Hz .*/).first.gsub(/[a-zA-z\s]+/, '').to_i
            @fact_list[:models] = output.scan(/brand .*/).map { |elem| elem.gsub(/brand(\s+)/, '') }
          end
        end
      end
    end
  end
end

Version data entries

15 entries across 15 versions & 1 rubygems

Version Path
facter-4.0.36 lib/facter/resolvers/solaris/processors.rb
facter-4.0.35 lib/facter/resolvers/solaris/processors.rb
facter-4.0.34 lib/facter/resolvers/solaris/processors.rb
facter-4.0.33 lib/facter/resolvers/solaris/processors.rb
facter-4.0.32 lib/facter/resolvers/solaris/processors.rb
facter-4.0.31 lib/facter/resolvers/solaris/processors.rb
facter-4.0.30 lib/facter/resolvers/solaris/processors.rb
facter-4.0.29 lib/resolvers/solaris/processors.rb
facter-4.0.28 lib/resolvers/solaris/processors.rb
facter-4.0.26 lib/resolvers/solaris/processors.rb
facter-4.0.25 lib/resolvers/solaris/processors.rb
facter-4.0.24 lib/resolvers/solaris/processors.rb
facter-4.0.23 lib/resolvers/solaris/processors.rb
facter-4.0.22 lib/resolvers/solaris/processors.rb
facter-4.0.21 lib/resolvers/solaris/processors.rb