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, 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 #

Returns the "guest" stat field.


def guest_nice #

Returns the "guest_nice" stat field.


def idle #

Returns the "idle" stat field.


def idle_total #

Sum of #idle and #iowait.


[View source]
def iowait #

Returns the "iowait" stat field.


def irq #

Returns the "irq" stat field.


def nice #

Returns the "nice" stat field.


def number : Int32? #

CPU number. nil means the whole cores in total.


[View source]
def softirq #

Returns the "softirq" stat field.


def steal #

Returns the "steal" stat field.


def system #

Returns the "system" stat field.


def total #

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 #

[View source]
def user #

Returns the "user" stat field.