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.
Instance methods
guest
Returns the "guest" stat field.
guest_nice
Returns the "guest_nice" stat field.
idle
Returns the "idle" stat field.
iowait
Returns the "iowait" stat field.
irq
Returns the "irq" stat field.
nice
Returns the "nice" stat field.
softirq
Returns the "softirq" stat field.
steal
Returns the "steal" stat field.
system
Returns the "system" stat field.
usage(previous_cpu : CPU = self) : Float64
Returns each CPU usage in percentage based on the previous CPU.
usage!
Like #usage, but mutates the instance.
cpu = Hardware::CPU.new
loop do
sleep 1
p cpu.usage!.to_i # => 17
end
user
Returns the "user" stat field.