kanrisuru 0.4.0 → 0.4.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 5d0fc79a97a3eebddc661982ea4a728af94aded3dbcf5bd5d7d8b0c03e9f5aaf
4
- data.tar.gz: a37a3d8a00941a4842f3ce0502a1e88fe9ff50343c095f55094dc528f4bddfa4
3
+ metadata.gz: 32ef1fec88bcaf4f6be97051f73a7b2056a18bde09c782044efa79c5e7f322e0
4
+ data.tar.gz: bf6ec2b44a5c7967d3a836421fe1ce787d4c7afe5a6f1665fce987a7721a441f
5
5
  SHA512:
6
- metadata.gz: 34521c6c7ed22da194e55037a4c9653717176e1b6526e79c272107fe57c711e5ffbd8a377c48df8008492910297bbe102d21713c41e5c33635264f32c3c5c231
7
- data.tar.gz: f620bb3a94944cee7c08f0634d43c7b00a4bf00e9c3b64ac13a0934cf8afe01af3439b67dd2d563cecb5134084b2eb9b8845835e22959d00a3639251ffb15f1e
6
+ metadata.gz: 0ba1a8a90c07f1e783b43f0f5ddcf7280b895ab48a3badc889006591474ce5250ed48f8479a3f302392a6a489b27b202703ecda0fa58cb7e4c9b1610edfb7941
7
+ data.tar.gz: 0a81ae9c65d740212c9cac4024ac8fc1b5a1edb3b82a3b72d3f22f27352edf1bf0bea2e3a7d72f046d7db635fd920f833b0c904621a7b0dac1af3807bd1856da
@@ -82,18 +82,18 @@ module Kanrisuru
82
82
  next if values.length < 5
83
83
 
84
84
  socket_stats = SocketStatistics.new
85
-
86
- socket_stats.netid = if headers.include?('Netid')
87
- values.shift
88
- elsif opts[:tcp]
89
- 'tcp'
90
- elsif opts[:udp]
91
- 'udp'
92
- elsif opts[:raw]
93
- 'raw'
94
- else
95
- ''
96
- end
85
+ socket_stats.netid =
86
+ if headers.include?('Netid')
87
+ values.shift
88
+ elsif opts[:tcp]
89
+ 'tcp'
90
+ elsif opts[:udp]
91
+ 'udp'
92
+ elsif opts[:raw]
93
+ 'raw'
94
+ else
95
+ ''
96
+ end
97
97
 
98
98
  socket_stats.state = if headers.include?('State')
99
99
  TCP_STATE_ABBR[values.shift]
@@ -15,6 +15,8 @@ module Kanrisuru
15
15
  os_define :linux, :ps
16
16
  os_define :linux, :kill
17
17
 
18
+ os_define :linux, :kernel_statistics
19
+
18
20
  os_define :linux, :uptime
19
21
 
20
22
  os_define :linux, :w
@@ -60,6 +62,33 @@ module Kanrisuru
60
62
  :flags
61
63
  )
62
64
 
65
+ KernelStatisticCpu = Struct.new(
66
+ :user,
67
+ :nice,
68
+ :system,
69
+ :idle,
70
+ :iowait,
71
+ :irq,
72
+ :softirq,
73
+ :steal,
74
+ :guest,
75
+ :guest_nice
76
+ )
77
+
78
+ KernelStatistic = Struct.new(
79
+ :cpu_total,
80
+ :cpus,
81
+ :interrupt_total,
82
+ :interrupts,
83
+ :ctxt,
84
+ :btime,
85
+ :processes,
86
+ :procs_running,
87
+ :procs_blocked,
88
+ :softirq_total,
89
+ :softirqs,
90
+ )
91
+
63
92
  ProcessInfo = Struct.new(
64
93
  :uid, :user, :gid, :group, :ppid, :pid,
65
94
  :cpu_usage, :memory_usage, :stat, :priority,
@@ -272,6 +301,65 @@ module Kanrisuru
272
301
  Kanrisuru::Result.new(command)
273
302
  end
274
303
 
304
+ def kernel_statistics
305
+ command = Kanrisuru::Command.new('cat /proc/stat')
306
+
307
+ execute_shell(command)
308
+
309
+ Kanrisuru::Result.new(command) do |cmd|
310
+ lines = cmd.to_a
311
+
312
+ result = KernelStatistic.new
313
+ result.cpus = []
314
+
315
+ lines.each do |line|
316
+ values = line.split
317
+ field = values[0]
318
+ values = values[1..-1].map(&:to_i)
319
+
320
+ case field
321
+ when /^cpu$/
322
+ result.cpu_total = KernelStatisticCpu.new
323
+
324
+ result.cpu_total.user = values[0]
325
+ result.cpu_total.nice = values[1]
326
+ result.cpu_total.system = values[2]
327
+ result.cpu_total.idle = values[3]
328
+ result.cpu_total.iowait = values[4]
329
+ result.cpu_total.irq = values[5]
330
+ result.cpu_total.softirq = values[6]
331
+ result.cpu_total.steal = values[7]
332
+ result.cpu_total.guest = values[8]
333
+ result.cpu_total.guest_nice = values[9]
334
+ when /^cpu\d/
335
+ cpu_stat = KernelStatisticCpu.new
336
+ cpu_stat.user = values[0]
337
+ cpu_stat.nice = values[1]
338
+ cpu_stat.system = values[2]
339
+ cpu_stat.idle = values[3]
340
+ cpu_stat.iowait = values[4]
341
+ cpu_stat.irq = values[5]
342
+ cpu_stat.softirq = values[6]
343
+ cpu_stat.steal = values[7]
344
+ cpu_stat.guest = values[8]
345
+ cpu_stat.guest_nice = values[9]
346
+
347
+ result.cpus << cpu_stat
348
+ when 'intr'
349
+ result.interrupt_total = values[0]
350
+ result.interrupts = values[1..-1]
351
+ when 'softirq'
352
+ result.softirq_total = values[0]
353
+ result.softirqs = values[1..-1]
354
+ else
355
+ result[field] = values[0]
356
+ end
357
+ end
358
+
359
+ result
360
+ end
361
+ end
362
+
275
363
  def uptime
276
364
  ## Ported from https://github.com/djberg96/sys-uptime
277
365
  command = Kanrisuru::Command.new('cat /proc/uptime')
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Kanrisuru
4
- VERSION = '0.4.0'
4
+ VERSION = '0.4.1'
5
5
  end
@@ -69,6 +69,27 @@ RSpec.describe Kanrisuru::Core::System do
69
69
  expect(process).to be_empty
70
70
  end
71
71
 
72
+ it 'gets kernel statistics' do
73
+ result = host.kernel_statistics
74
+ expect(result).to be_success
75
+
76
+ expect(result.data).to respond_to(
77
+ :cpu_total,
78
+ :cpus,
79
+ :interrupt_total,
80
+ :interrupts,
81
+ :ctxt,
82
+ :btime,
83
+ :processes,
84
+ :procs_running,
85
+ :procs_blocked,
86
+ :softirq_total,
87
+ :softirqs,
88
+ )
89
+
90
+ expect(result.cpus.length).to eq(host.cpu.cores)
91
+ end
92
+
72
93
  it 'gets process details' do
73
94
  result = host.ps
74
95
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: kanrisuru
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.0
4
+ version: 0.4.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ryan Mammina
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-07-25 00:00:00.000000000 Z
11
+ date: 2021-07-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rspec