kanrisuru 0.3.0 → 0.4.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 596f187f09116db8bd36b6eb7a0864f440afdf9e34d784c6215793a5e335f4cd
4
- data.tar.gz: 0056efd85ffcc42a36bf9086961c3f7438d5716f0cee580587fa48c60af3cfa5
3
+ metadata.gz: 32ef1fec88bcaf4f6be97051f73a7b2056a18bde09c782044efa79c5e7f322e0
4
+ data.tar.gz: bf6ec2b44a5c7967d3a836421fe1ce787d4c7afe5a6f1665fce987a7721a441f
5
5
  SHA512:
6
- metadata.gz: f232ff04685236d29e2e8c5c2652ffb7b93e57ca36a7179158787df70553865d7516045e718d03c1bd8e3257a08c793b82941a4cbcb247c39beea667788d57df
7
- data.tar.gz: af237e0803c4229b008f8ff9b3defae4df00d17af4dab9b51fe3f23797c8af406f4844befe43ed678b99685338a8d2c6e19d7c1e3fea919ccd2082e6059e8576
6
+ metadata.gz: 0ba1a8a90c07f1e783b43f0f5ddcf7280b895ab48a3badc889006591474ce5250ed48f8479a3f302392a6a489b27b202703ecda0fa58cb7e4c9b1610edfb7941
7
+ data.tar.gz: 0a81ae9c65d740212c9cac4024ac8fc1b5a1edb3b82a3b72d3f22f27352edf1bf0bea2e3a7d72f046d7db635fd920f833b0c904621a7b0dac1af3807bd1856da
@@ -6,12 +6,13 @@ module Kanrisuru
6
6
  attr_writer :remote_user, :remote_shell, :remote_path, :remote_env
7
7
 
8
8
  def initialize(command)
9
+ @valid_exit_codes = [0]
9
10
  @raw_command = command
10
11
  @raw_result = []
11
12
  end
12
13
 
13
14
  def success?
14
- @exit_status&.zero?
15
+ @valid_exit_codes.include?(@exit_status)
15
16
  end
16
17
 
17
18
  def failure?
@@ -45,8 +46,7 @@ module Kanrisuru
45
46
  end
46
47
 
47
48
  env = @remote_env && !@remote_env.empty? ? "#{@remote_env} " : ''
48
-
49
- "#{env}sudo -u #{@remote_user} #{@remote_shell} -c -l \"#{evaluate}\""
49
+ "#{env}sudo -u #{@remote_user} #{@remote_shell} -c \"#{evaluate}\""
50
50
  else
51
51
  @raw_command
52
52
  end
@@ -95,5 +95,10 @@ module Kanrisuru
95
95
  def append_flag(arg, boolean = 'true')
96
96
  @raw_command = Kanrisuru::Util.present?(boolean) ? "#{@raw_command} #{arg}" : @raw_command
97
97
  end
98
+
99
+ def append_valid_exit_code(code)
100
+ @valid_exit_codes << code if code.instance_of?(Integer)
101
+ @valid_exit_codes.concat(code) if code.instance_of?(Array)
102
+ end
98
103
  end
99
104
  end
@@ -44,7 +44,6 @@ module Kanrisuru
44
44
  date = DateTime.parse("#{values[6]} #{values[7]} #{values[8]}")
45
45
 
46
46
  type = values[1].include?('d') ? 'directory' : 'file'
47
-
48
47
  items <<
49
48
  if id
50
49
  FileInfoId.new(
@@ -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')
@@ -76,7 +76,19 @@ module Kanrisuru
76
76
  end
77
77
 
78
78
  def address_size
79
- @cpu_architecture.byte_order
79
+ @cpu_architecture.address_size
80
+ end
81
+
82
+ def cpu_mhz
83
+ @cpu_architecture.cpu_mhz
84
+ end
85
+
86
+ def cpu_max_mhz
87
+ @cpu_architecture.cpu_max_mhz
88
+ end
89
+
90
+ def cpu_min_mhz
91
+ @cpu_architecture.cpu_min_mhz
80
92
  end
81
93
 
82
94
  def hypervisor
@@ -87,6 +99,10 @@ module Kanrisuru
87
99
  @cpu_architecture.virtualization_type
88
100
  end
89
101
 
102
+ def flags
103
+ @cpu_architecture.flags
104
+ end
105
+
90
106
  def hyperthreading?
91
107
  threads_per_core > 1
92
108
  end
@@ -16,7 +16,7 @@ module Kanrisuru
16
16
  @username = opts[:username]
17
17
  @login_user = @username
18
18
 
19
- @port = opts[:port]
19
+ @port = opts[:port] || 22
20
20
  @password = opts[:password] if opts[:password]
21
21
  @keys = opts[:keys] if opts[:keys]
22
22
  @shell = opts[:shell] || '/bin/bash'
@@ -84,7 +84,7 @@ module Kanrisuru
84
84
  end
85
85
 
86
86
  def ssh
87
- @ssh ||= Net::SSH.start(@host, @username, keys: @keys, password: @password)
87
+ @ssh ||= Net::SSH.start(@host, @username, keys: @keys, password: @password, port: @port)
88
88
  end
89
89
 
90
90
  def ping?
@@ -186,7 +186,7 @@ module Kanrisuru
186
186
  model: 'open_source',
187
187
  state: 'current',
188
188
  type: 'distribution'
189
- },
189
+ }
190
190
  }
191
191
 
192
192
  def self.family_include_distribution?(family, dist)
@@ -136,7 +136,7 @@ module Kanrisuru
136
136
  def self.[](signal)
137
137
  return unless valid?(signal)
138
138
 
139
- if key.instance_of?(Integer)
139
+ if signal.instance_of?(Integer)
140
140
  @linux_inverted[signal]
141
141
  else
142
142
  @linux[translate(signal)]
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Kanrisuru
4
- VERSION = '0.3.0'
4
+ VERSION = '0.4.1'
5
5
  end
@@ -18,6 +18,12 @@ RSpec.describe Kanrisuru::Core::System do
18
18
  host.disconnect
19
19
  end
20
20
 
21
+ it 'gets cpu details' do
22
+ result = host.lscpu
23
+ expect(result).to be_success
24
+ expect(result.data).to be_instance_of(Kanrisuru::Core::System::CPUArchitecture)
25
+ end
26
+
21
27
  it 'gets environment variables' do
22
28
  result = host.load_env
23
29
 
@@ -63,6 +69,27 @@ RSpec.describe Kanrisuru::Core::System do
63
69
  expect(process).to be_empty
64
70
  end
65
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
+
66
93
  it 'gets process details' do
67
94
  result = host.ps
68
95
 
@@ -24,7 +24,7 @@ RSpec.describe Kanrisuru::Remote::Os do
24
24
 
25
25
  case os_name
26
26
  when 'opensuse'
27
- expect(host.os.release).to eq('opensuse-leap')
27
+ expect(host.os.release).to eq('opensuse_leap')
28
28
  else
29
29
  expect(host.os.release).to eq(os_name)
30
30
  end
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.3.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-22 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