Sha256: ce204fd1bfa1739155fe6f1dc759f226f60badc72f69eba99ebdaf363e9b6ab2
Contents?: true
Size: 1.18 KB
Versions: 25
Compression:
Stored size: 1.18 KB
Contents
# frozen_string_literal: true module Facter module Resolvers module Linux class Lscpu < BaseResolver init_resolver ITEMS = { threads_per_core: "-e 'Thread(s)'", cores_per_socket: "-e 'Core(s)'" }.freeze class << self #:cores_per_socket #:threads_per_core private def post_resolve(fact_name, _options) @fact_list.fetch(fact_name) { read_cpuinfo(fact_name) } end def read_cpuinfo(fact_name) lscpu_output = Facter::Core::Execution.execute("lscpu | grep #{ITEMS.values.join(' ')}", logger: log) build_fact_list(lscpu_output.split("\n")) @fact_list[fact_name] end def build_fact_list(processors_data) build_threads_per_core(processors_data[0]) build_cores_per_socket(processors_data[1]) end def build_threads_per_core(index) @fact_list[:threads_per_core] = index.split(': ')[1].to_i end def build_cores_per_socket(index) @fact_list[:cores_per_socket] = index.split(': ')[1].to_i end end end end end end
Version data entries
25 entries across 25 versions & 1 rubygems