Kanrisuru

kernel_statistics

Get kernel statistics of a remote server in ruby
linux manual

Basic Usage

require 'kanrisuru'
host = Kanrisuru::Remote::Host.new(host: '127.0.1.1', username: 'ubuntu', keys: ['~/.ssh/id_rsa'])

result = host.kernel_statistics
result.success?
true

result.

Result

Returns a KernelStatistic struct.

KernelStatistic Fields

Field Type Description
cpu_total KernelStatisticCpu Encapsulates the stats for all cpus of the server.
cpus array Array of individual KernelStatisticCpu structs. Each instance represents the amount of time the CPU has spent performing different kinds of work.
interrupt_total integer The total of all interrupts serviced.
interrupts array A count of service interrupts since boot time for each system interrupt, as represented as the indexed position in the array.
ctxt integer The total number of context switches across all CPUs.
btime integer Boot time, in seconds since the Epoch, 1970-01-01 00:00:00 +0000 (UTC).
processes integer The number of processes and threads created, which includes (but is not limited to) those created by calls to the fork() and clone() system calls.
procs_running integer The number of processes currently running on CPUs.
procs_blocked integer The number of processes currently blocked, waiting for I/O to complete.
softirq_total integer The total of all softirqs.
softirqs arrau The total for the particular softirq.

KernelStatisticCpu Fields

Field Type Description
user integer Normal processes executing in user mode.
nice integer Niced processes executing in user mode.
system integer Processes executing in kernel mode.
idle integer Time spent in the idle task.
iowait integer Time waiting for I/O to complete.
irq integer Time servicing interrupts.
softirq integer Time servicing softirqs.
steal integer The total ticks spent executing other virtual hosts.
guest integer Guest time of the process (time spent running a virtual CPU for a guest operating system), measured in clock ticks.
guest_nice integer Time spent running a niced guest (virtual CPU for guest operating systems under the control of the Linux kernel.

Return Example

host.kstat.data
#<Struct:Kanrisuru::Core::System::KernelStatistic:0x00000640
  btime = 1638819008,
  cpu_total = #<Struct:Kanrisuru::Core::System::KernelStatisticCpu:0x00000668
    guest = 0,
    guest_nice = 0,
    idle = 3000465009,
    iowait = 220655,
    irq = 0,
    nice = 37642,
    softirq = 16981,
    steal = 6536,
    system = 497900,
    user = 974313
  >,
  cpus = [
    [0] #<Struct:Kanrisuru::Core::System::KernelStatisticCpu:0x000006b8
      guest = 0,
      guest_nice = 0,
      idle = 374868746,
      iowait = 35580,
      irq = 0,
      nice = 3642,
      softirq = 8079,
      steal = 879,
      system = 62201,
      user = 135319
    >,
    [1] #<Struct:Kanrisuru::Core::System::KernelStatisticCpu:0x000006e0
      guest = 0,
      guest_nice = 0,
      idle = 375030546,
      iowait = 29886,
      irq = 0,
      nice = 4445,
      softirq = 617,
      steal = 743,
      system = 74533,
      user = 140727
    >,
    [2] #<Struct:Kanrisuru::Core::System::KernelStatisticCpu:0x00000708
      guest = 0,
      guest_nice = 0,
      idle = 375091084,
      iowait = 33608,
      irq = 0,
      nice = 5282,
      softirq = 350,
      steal = 618,
      system = 60031,
      user = 120032
    >,
    [3] .. [4],
    [5] #<Struct:Kanrisuru::Core::System::KernelStatisticCpu:0x00000780
      guest = 0,
      guest_nice = 0,
      idle = 375128926,
      iowait = 33149,
      irq = 0,
      nice = 4997,
      softirq = 372,
      steal = 558,
      system = 54619,
      user = 104484
    >,
    [6] #<Struct:Kanrisuru::Core::System::KernelStatisticCpu:0x000007a8
      guest = 0,
      guest_nice = 0,
      idle = 375107168,
      iowait = 24471,
      irq = 0,
      nice = 4103,
      softirq = 246,
      steal = 663,
      system = 58138,
      user = 103597
    >,
    [7] #<Struct:Kanrisuru::Core::System::KernelStatisticCpu:0x000007d0
      guest = 0,
      guest_nice = 0,
      idle = 375027722,
      iowait = 24198,
      irq = 0,
      nice = 5424,
      softirq = 5943,
      steal = 1384,
      system = 66400,
      user = 140983
    >
  ],
  ctxt = 617697076,
  interrupt_total = 327938951,
  interrupts = [
    [  0] 0,
    [  1] 9,
    [  2] 0,
    [  3] .. [484],
    [485] 0,
    [486] 0,
    [487] 0
  ],
  processes = 175387,
  procs_blocked = 0,
  procs_running = 1,
  softirq_total = 137736702,
  softirqs = [
    [0] 0,
    [1] 53822324,
    [2] 86,
    [3] .. [6],
    [7] 46013049,
    [8] 2777,
    [9] 21003022
  ]
>

Exit Status

Code Description
0 Success
1 Failure

Tested On

  • Ubuntu, Debian, Centos, Fedora, Redhat, OpenSuse, SLES