module

System::CPU

Constants

CPU_INFO_PATH = "/proc/cpuinfo"
CPU_STAT_PATH = "/proc/stat"
CPU_STATE_IDLE = 4
CPU_STATES = 5
HOST_CPU_LOAD_INFO = 3
HOST_CPU_LOAD_INFO_COUNT = 4
LOAD_AVG_PATH = "/proc/loadavg"
VERSION = "0.2.0"

Instance methods

[](name : String, cpu_index : Int = 0) : AttributeValue

Returns a parsed cpuinfo field from the requested processor index.

Source
[]?(name : String, cpu_index : Int = 0) : AttributeValue | Nil

Returns a parsed cpuinfo field when present, otherwise nil.

Source
architecture

Returns the machine architecture string, such as "amd64".

Source
cpu_stats

Reads raw jiffy counters from /proc/stat for total and per-CPU entries.

Source
cpu_usage(*, sample_time : Number | Nil = 1.0, samples : Int | Nil = 2)

Returns the current CPU usage as a percentage, averaged over a sampling interval.

By default, this method samples CPU usage over a 1-second interval and averages two measurements. You can customize the interval and number of samples by passing the sample_time (in seconds) and samples keyword arguments. For example, cpu_usage(sample_time: 0.5, samples: 4) takes four samples, each 0.5 seconds apart, and returns the average CPU usage over that period.

Passing nil, 0, or a negative value for either argument falls back to the defaults (1.0 seconds and 2 samples) to keep behavior consistent across platforms.

Returns a Float64 percentage rounded to one decimal place, or nil if CPU usage cannot be determined.

Example usage: System::CPU.cpu_usage # => 12.3 System::CPU.cpu_usage(sample_time: 2, samples: 3) # => 10.7 System::CPU.cpu_usage(sample_time: 0, samples: 0) # => 12.3

Source
freq

Returns CPU frequency in MHz when the platform exposes it.

Source
load_avg

Returns the 1, 5, and 15 minute load averages.

Source
machine

Returns the FreeBSD machine class, such as "amd64" or "arm64".

Source
model

Returns the kernel-reported CPU model string.

Source
num_cpu

Returns the number of logical CPUs reported by the kernel.

Source
processors

Returns a Processor wrapper for each parsed /proc/cpuinfo record.

Source
processors

Yields each parsed processor record without exposing the internal cache directly.

Source

Nested types