class

Ctop::Collectors::CPU

Inherits Ctop::Collectors::Base < Reference < Object

Collects CPU usage metrics for total and per-core.

cpu = Ctop::Collectors::CPU.new
loop do
  sleep 1
  snapshot = cpu.collect
  puts "Total: #{snapshot.usage.round(1)}%"
  snapshot.per_core.each_with_index { |u, i| puts "Core #{i}: #{u.round(1)}%" }
end

NOTE: Per-core stats currently return zero due to a parsing bug in the hardware library. Total CPU usage works correctly.

Constructors

Instance methods

collect

Collect current CPU usage. First call establishes baseline.

Source
core_count

Number of CPU cores

Source