struct Hardware::CPU

Overview

CPU related informations of your system.

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

Defined in:

cpu.cr

Constructors

Instance Method Summary

Constructor Detail

def self.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.


[View source]

Instance Method Detail

def guest : Int64 #

Returns the "guest" stat field.


def guest_nice : Int64 #

Returns the "guest_nice" stat field.


def idle : Int64 #

Returns the "idle" stat field.


def idle_total : Int64 #

Sum of #idle and #iowait.


[View source]
def iowait : Int64 #

Returns the "iowait" stat field.


def irq : Int64 #

Returns the "irq" stat field.


def nice : Int64 #

Returns the "nice" stat field.


def number : Int32 | Nil #

CPU number. nil means the whole cores in total.


[View source]
def softirq : Int64 #

Returns the "softirq" stat field.


def steal : Int64 #

Returns the "steal" stat field.


def system : Int64 #

Returns the "system" stat field.


def total : Int64 #

Sum of #used and #idle_total


[View source]
def usage(previous_cpu : CPU = self) : Float64 #

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


[View source]
def usage! : Float64 #

Like #usage, but mutates the instance.

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

[View source]
def used : Int64 #

[View source]
def user : Int64 #

Returns the "user" stat field.