struct

Hardware::CPU

Inherits Struct / Value / Object

CPU related informations of your system.

cpu = Hardware::CPU.new
loop do
  sleep 1
  p cpu.usage!.to_i # => 17
end

Constructors

new(number : Int32 | Nil = nil, parse_stats : Bool = true)

Creates a new CPU stat to monitor the given core.

Must be lower than System.cpu_count, or nil for the whole cores in total.

Source

Instance methods

guest

Returns the "guest" stat field.

guest_nice

Returns the "guest_nice" stat field.

idle

Returns the "idle" stat field.

idle_total

Sum of idle and iowait.

Source
iowait

Returns the "iowait" stat field.

irq

Returns the "irq" stat field.

nice

Returns the "nice" stat field.

number

CPU number. nil means the whole cores in total.

Source
softirq

Returns the "softirq" stat field.

steal

Returns the "steal" stat field.

system

Returns the "system" stat field.

total

Sum of used and idle_total

Source
usage(previous_cpu : CPU = self) : Float64

Returns each CPU usage in percentage based on the previous CPU.

Source
usage!

Like #usage, but mutates the instance.

cpu = Hardware::CPU.new
loop do
  sleep 1
  p cpu.usage!.to_i # => 17
end
Source
used

Sum of user, nice, system, irq, softirq and steal.

Source
user

Returns the "user" stat field.