blackstack-nodes 1.2.11 → 1.2.14
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 +4 -4
- data/lib/blackstack-nodes.rb +79 -28
- metadata +2 -14
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4ed42ce28e323788e17215ca87fc900d25493a140adce92d38c5eac9d0469ce8
|
4
|
+
data.tar.gz: 4de3f22c58fb77ea176e6697594be8f44beb4079d1acb6b2a5e722f46be3ddd3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a0ca565b5076a4c50f1a7ac8ceacc81821ffa6147795c3ee24427e115910fe57f7ca6794a153358498fa6f96020619fafa22d48c34b137d2280c94a2b6489114
|
7
|
+
data.tar.gz: '080428a73ccbb5b9cb189b32ea114ec9f7e1c93ec3a266ba42f5e21aed39566cf00616eb3d97bde1460dc1f9dd8ebaebd641894840c3836949492d15d75c1390'
|
data/lib/blackstack-nodes.rb
CHANGED
@@ -76,7 +76,7 @@ module BlackStack
|
|
76
76
|
self.tags = []
|
77
77
|
end
|
78
78
|
# create a logger
|
79
|
-
self.logger = !i_logger.nil? ? i_logger : BlackStack::
|
79
|
+
self.logger = !i_logger.nil? ? i_logger : BlackStack::DummyLogger.new(nil)
|
80
80
|
end # def self.create(h)
|
81
81
|
|
82
82
|
def to_hash
|
@@ -117,27 +117,30 @@ module BlackStack
|
|
117
117
|
self.ssh.close
|
118
118
|
end
|
119
119
|
|
120
|
-
def
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
120
|
+
def exec(
|
121
|
+
command,
|
122
|
+
output_file: "~/bash-command-stdout-buffer",
|
123
|
+
error_file: "~/bash-command-stderr-buffer"
|
124
|
+
)
|
125
|
+
# Construct the remote command with redirection for stdout and stderr
|
126
|
+
remote_command = "#{command} > #{output_file} 2> #{error_file}"
|
127
|
+
|
128
|
+
# Execute the command on the remote server
|
129
|
+
self.ssh.exec!("truncate -s 0 #{output_file} #{error_file} && #{remote_command}")
|
130
|
+
|
131
|
+
# Retrieve the content of the error file from the remote server
|
132
|
+
error_content = self.ssh.exec!("cat #{error_file}").to_s.chomp
|
133
|
+
|
134
|
+
# Check if the error file has any content
|
135
|
+
unless error_content.empty?
|
136
|
+
# Raise an exception with the error message
|
137
|
+
raise "Command failed with the following error:\n#{error_content}"
|
131
138
|
end
|
132
|
-
#puts
|
133
|
-
#puts "s: #{s}"
|
134
|
-
s
|
135
|
-
end
|
136
139
|
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
end
|
140
|
+
# Retrieve and return the content of the output file from the remote server
|
141
|
+
# truncate any last newline character
|
142
|
+
self.ssh.exec!("cat #{output_file}").to_s.chomp
|
143
|
+
end
|
141
144
|
|
142
145
|
def reboot()
|
143
146
|
tries = 0
|
@@ -175,6 +178,62 @@ module BlackStack
|
|
175
178
|
raise 'reboot failed' if !success
|
176
179
|
end # def reboot
|
177
180
|
|
181
|
+
# Return a hash descriptor of the status of the node
|
182
|
+
def usage()
|
183
|
+
ret = {}
|
184
|
+
|
185
|
+
#self.connect
|
186
|
+
|
187
|
+
ret[:b_total_memory] = self.ssh.exec!('cat /proc/meminfo | grep MemTotal').delete('^0-9').to_i*1024
|
188
|
+
ret[:kb_total_memory] = ret[:b_total_memory] / 1024
|
189
|
+
ret[:mb_total_memory] = ret[:kb_total_memory] / 1024
|
190
|
+
ret[:gb_total_memory] = ret[:mb_total_memory] / 1024
|
191
|
+
|
192
|
+
ret[:kb_free_memory] = self.ssh.exec!('cat /proc/meminfo | grep MemFree').delete('^0-9').to_i
|
193
|
+
ret[:mb_free_memory] = ret[:kb_free_memory] / 1024
|
194
|
+
ret[:gb_free_memory] = ret[:mb_free_memory] / 1024
|
195
|
+
|
196
|
+
# run bash commend to get the total disk space
|
197
|
+
ret[:mb_total_disk] = self.ssh.exec!('df -m / | tail -1 | awk \'{print $2}\'').to_i
|
198
|
+
ret[:gb_total_disk] = ret[:mb_total_disk] / 1024
|
199
|
+
# run bash command to get the free disk space
|
200
|
+
ret[:mb_free_disk] = self.ssh.exec!('df -m / | tail -1 | awk \'{print $4}\'').to_i
|
201
|
+
ret[:gb_free_disk] = ret[:mb_free_disk] / 1024
|
202
|
+
|
203
|
+
# run bash command to get hostname
|
204
|
+
ret[:hostname] = self.ssh.exec!('hostname').strip!
|
205
|
+
|
206
|
+
# run bash command to get the CPU load
|
207
|
+
# reference: https://stackoverflow.com/questions/9229333/how-to-get-overall-cpu-usage-e-g-57-on-linux
|
208
|
+
ret[:cpu_load_average] = self.ssh.exec!("awk '{u=$2+$4; t=$2+$4+$5; if (NR==1){u1=u; t1=t;} else print ($2+$4-u1) * 100 / (t-t1) \"%\"; }' <(grep 'cpu ' /proc/stat) <(sleep 1;grep 'cpu ' /proc/stat)").to_s
|
209
|
+
|
210
|
+
# TODO: monitor the overall Network I/O load
|
211
|
+
|
212
|
+
# TODO: monitor the overall Disk I/O load
|
213
|
+
|
214
|
+
# mapping cpu status
|
215
|
+
ret[:cpu_architecture] = self.ssh.exec!('lscpu | grep Architecture').split(':')[1].strip!
|
216
|
+
ret[:cpu_speed] = self.ssh.exec!('lscpu | grep "CPU MHz:"').split(':')[1].strip!.to_f.round
|
217
|
+
#ret[:cpu_model] = self.ssh.exec!('lscpu | grep "Model"').split(':')[1].strip!
|
218
|
+
#ret[:cpu_type] = ret[:cpu_model].split(' ')[0]
|
219
|
+
ret[:cpu_number] = self.ssh.exec!('lscpu | grep "^CPU(s):"').split(':')[1].strip!.to_i
|
220
|
+
|
221
|
+
# mapping disk status
|
222
|
+
#self.disk_total = mb_total_disk.to_i
|
223
|
+
#self.disk_free = mb_free_disk.to_i
|
224
|
+
|
225
|
+
# mapping lan attributes
|
226
|
+
ret[:net_mac_address] = self.ssh.exec!('ifconfig | grep ether').split[1].upcase.strip.gsub(':', '-')
|
227
|
+
|
228
|
+
#self.disconnect
|
229
|
+
|
230
|
+
ret
|
231
|
+
end # def usage
|
232
|
+
|
233
|
+
# return the latest `n`` lines of the file specified by the `filename` parameter
|
234
|
+
def tail(filename, n=10)
|
235
|
+
self.ssh.exec!("tail -n #{n.to_s} #{filename}")
|
236
|
+
end
|
178
237
|
|
179
238
|
end # module NodeModule
|
180
239
|
|
@@ -186,13 +245,5 @@ module BlackStack
|
|
186
245
|
class Node
|
187
246
|
include NodeModule
|
188
247
|
end # class Node
|
189
|
-
=begin
|
190
|
-
# Node Skeleton
|
191
|
-
# This class represents a node, with connection to the database.
|
192
|
-
# Use this class at the server side.
|
193
|
-
class Node < Sequel::Model(:node)
|
194
|
-
include NodeModule
|
195
|
-
end
|
196
|
-
=end
|
197
248
|
end # module Infrastructure
|
198
249
|
end # module BlackStack
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: blackstack-nodes
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.2.
|
4
|
+
version: 1.2.14
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Leandro Daniel Sardi
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2024-09-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: net-ssh
|
@@ -17,9 +17,6 @@ dependencies:
|
|
17
17
|
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
19
|
version: 6.1.0
|
20
|
-
- - ">="
|
21
|
-
- !ruby/object:Gem::Version
|
22
|
-
version: 6.1.0
|
23
20
|
type: :runtime
|
24
21
|
prerelease: false
|
25
22
|
version_requirements: !ruby/object:Gem::Requirement
|
@@ -27,9 +24,6 @@ dependencies:
|
|
27
24
|
- - "~>"
|
28
25
|
- !ruby/object:Gem::Version
|
29
26
|
version: 6.1.0
|
30
|
-
- - ">="
|
31
|
-
- !ruby/object:Gem::Version
|
32
|
-
version: 6.1.0
|
33
27
|
- !ruby/object:Gem::Dependency
|
34
28
|
name: simple_cloud_logging
|
35
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -37,9 +31,6 @@ dependencies:
|
|
37
31
|
- - "~>"
|
38
32
|
- !ruby/object:Gem::Version
|
39
33
|
version: 1.2.2
|
40
|
-
- - ">="
|
41
|
-
- !ruby/object:Gem::Version
|
42
|
-
version: 1.2.2
|
43
34
|
type: :runtime
|
44
35
|
prerelease: false
|
45
36
|
version_requirements: !ruby/object:Gem::Requirement
|
@@ -47,9 +38,6 @@ dependencies:
|
|
47
38
|
- - "~>"
|
48
39
|
- !ruby/object:Gem::Version
|
49
40
|
version: 1.2.2
|
50
|
-
- - ">="
|
51
|
-
- !ruby/object:Gem::Version
|
52
|
-
version: 1.2.2
|
53
41
|
description: "BlackStack Nodes is a simple library to managing a computer remotely
|
54
42
|
via SSH, and perform some common operations.\nThis library is used and extended
|
55
43
|
by many others like: \n- [BlackStack Deployer](https://github.com/leandrosardi/blackstack-deployer)\n-
|