LinuxSystemInfo 0.1.0 → 0.1.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +2 -1
- data/LinuxSystemInfo.gemspec +6 -4
- data/README.md +131 -128
- data/lib/LinuxSystemInfo.rb +8 -143
- data/lib/LinuxSystemInfo/version.rb +1 -1
- data/lib/components/media.rb +26 -0
- data/lib/components/memory.rb +36 -0
- data/lib/components/network.rb +35 -0
- data/lib/components/processors.rb +74 -0
- metadata +33 -15
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 80ca5bf94e96b5ebf648a0bb463d5b357c66a8e5
|
4
|
+
data.tar.gz: caee69a6123d763b33ab3d5298c243f95f3a0638
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ccd70d35fadbd2f321072a0175ba0f934ee9ccf8f98674a42ceb1fe2784f019cab7a6dcb58acb6a9fdb3d8004ce6a8796b65329d597434706f516484e98bd5d0
|
7
|
+
data.tar.gz: 7da123986abd7b2dcbd02fad4aa8110dac5079fd9b6436408907d26e31a3eaf91de9475fa7cb7e1971c1ead2ff42edc82ed394aa1222aad6554262973ea711a4
|
data/.travis.yml
CHANGED
data/LinuxSystemInfo.gemspec
CHANGED
@@ -18,8 +18,10 @@ Gem::Specification.new do |spec|
|
|
18
18
|
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
19
|
spec.require_paths = ['lib']
|
20
20
|
|
21
|
-
spec.
|
22
|
-
|
23
|
-
spec.add_development_dependency '
|
24
|
-
spec.add_development_dependency '
|
21
|
+
spec.add_runtime_dependency 'json'
|
22
|
+
|
23
|
+
spec.add_development_dependency 'bundler'
|
24
|
+
spec.add_development_dependency 'rake'
|
25
|
+
spec.add_development_dependency 'json'
|
26
|
+
spec.add_development_dependency 'rspec'
|
25
27
|
end
|
data/README.md
CHANGED
@@ -7,23 +7,23 @@ Linux System Info is a gem that allows you to get information about you're linux
|
|
7
7
|
computer. It retrieves information such as CPU, RAM, Hard drive etc. This works
|
8
8
|
only for your local computer and for Linux Debain or Redhat based operating system.
|
9
9
|
|
10
|
-
|
10
|
+
# Requirements
|
11
11
|
|
12
12
|
The following utility is needed to get a list of devices connected to the PCI bus.
|
13
13
|
|
14
14
|
Debain based linux (installed by default)
|
15
15
|
|
16
16
|
```bash
|
17
|
-
sudo apt-get install pciutils
|
17
|
+
sudo apt-get install pciutils sysstat
|
18
18
|
````
|
19
19
|
|
20
20
|
RedHat based linux (not installed by default)
|
21
21
|
|
22
22
|
```bash
|
23
|
-
sudo yum install pciutils
|
23
|
+
sudo yum install pciutils sysstat
|
24
24
|
````
|
25
25
|
|
26
|
-
|
26
|
+
# Installation
|
27
27
|
|
28
28
|
Add this line to your application's Gemfile:
|
29
29
|
|
@@ -39,11 +39,11 @@ Or install it yourself as:
|
|
39
39
|
|
40
40
|
$ gem install LinuxSystemInfo
|
41
41
|
|
42
|
-
|
42
|
+
# Usage
|
43
43
|
|
44
|
-
|
44
|
+
### Info
|
45
45
|
|
46
|
-
LinuxSystemInfo.info
|
46
|
+
#### LinuxSystemInfo.info
|
47
47
|
|
48
48
|
```ruby
|
49
49
|
{
|
@@ -53,9 +53,9 @@ LinuxSystemInfo.info
|
|
53
53
|
}
|
54
54
|
```
|
55
55
|
|
56
|
-
|
56
|
+
### CPU
|
57
57
|
|
58
|
-
LinuxSystemInfo.cpu
|
58
|
+
#### LinuxSystemInfo.cpu
|
59
59
|
|
60
60
|
```ruby
|
61
61
|
{
|
@@ -81,9 +81,27 @@ LinuxSystemInfo.cpu
|
|
81
81
|
}
|
82
82
|
```
|
83
83
|
|
84
|
-
####
|
84
|
+
#### LinuxSystemInfo.cpu_usage
|
85
85
|
|
86
|
-
|
86
|
+
```ruby
|
87
|
+
{
|
88
|
+
:user=>"5.71",
|
89
|
+
:nice=>"0.31",
|
90
|
+
:system=>"1.58",
|
91
|
+
:iowait=>"0.32",
|
92
|
+
:irq=>"0.00",
|
93
|
+
:soft=>"0.02",
|
94
|
+
:steal=>"0.00",
|
95
|
+
:guest=>"0.00",
|
96
|
+
:gnice=>"0.00",
|
97
|
+
:idle=>"92.06",
|
98
|
+
:usage=>7.94
|
99
|
+
}
|
100
|
+
```
|
101
|
+
|
102
|
+
### RAM
|
103
|
+
|
104
|
+
#### LinuxSystemInfo.memory
|
87
105
|
|
88
106
|
```ruby
|
89
107
|
{
|
@@ -97,9 +115,9 @@ LinuxSystemInfo.memory
|
|
97
115
|
}
|
98
116
|
```
|
99
117
|
|
100
|
-
|
118
|
+
### Storage
|
101
119
|
|
102
|
-
LinuxSystemInfo.storage
|
120
|
+
#### LinuxSystemInfo.storage
|
103
121
|
|
104
122
|
```ruby
|
105
123
|
{
|
@@ -138,9 +156,9 @@ LinuxSystemInfo.storage
|
|
138
156
|
}
|
139
157
|
```
|
140
158
|
|
141
|
-
|
159
|
+
### Connection
|
142
160
|
|
143
|
-
LinuxSystemInfo.connection
|
161
|
+
#### LinuxSystemInfo.connection
|
144
162
|
|
145
163
|
```ruby
|
146
164
|
{
|
@@ -155,18 +173,18 @@ LinuxSystemInfo.connection
|
|
155
173
|
}
|
156
174
|
```
|
157
175
|
|
158
|
-
|
176
|
+
### Video
|
159
177
|
|
160
|
-
LinuxSystemInfo.video
|
178
|
+
#### LinuxSystemInfo.video
|
161
179
|
|
162
180
|
```ruby
|
163
181
|
[
|
164
182
|
"Intel Corporation Haswell-ULT Integrated Graphics Controller (rev 09)"
|
165
183
|
]
|
166
184
|
```
|
167
|
-
|
185
|
+
### Audio
|
168
186
|
|
169
|
-
LinuxSystemInfo.audio
|
187
|
+
#### LinuxSystemInfo.audio
|
170
188
|
|
171
189
|
```ruby
|
172
190
|
[
|
@@ -175,9 +193,9 @@ LinuxSystemInfo.audio
|
|
175
193
|
]
|
176
194
|
```
|
177
195
|
|
178
|
-
|
196
|
+
### USB
|
179
197
|
|
180
|
-
LinuxSystemInfo.usb
|
198
|
+
#### LinuxSystemInfo.usb
|
181
199
|
|
182
200
|
```ruby
|
183
201
|
[
|
@@ -186,9 +204,9 @@ LinuxSystemInfo.usb
|
|
186
204
|
]
|
187
205
|
```
|
188
206
|
|
189
|
-
|
207
|
+
### Network
|
190
208
|
|
191
|
-
LinuxSystemInfo.network
|
209
|
+
#### LinuxSystemInfo.network
|
192
210
|
|
193
211
|
```ruby
|
194
212
|
[
|
@@ -197,17 +215,17 @@ LinuxSystemInfo.network
|
|
197
215
|
]
|
198
216
|
```
|
199
217
|
|
200
|
-
|
218
|
+
### Host
|
201
219
|
|
202
|
-
LinuxSystemInfo.hostname
|
220
|
+
#### LinuxSystemInfo.hostname
|
203
221
|
|
204
222
|
```
|
205
223
|
"example.com"
|
206
224
|
```
|
207
225
|
|
208
|
-
|
226
|
+
### Processes
|
209
227
|
|
210
|
-
LinuxSystemInfo.processes
|
228
|
+
#### LinuxSystemInfo.processes
|
211
229
|
|
212
230
|
Returns all process that are not by root, nobody, and syslog user.
|
213
231
|
|
@@ -225,127 +243,112 @@ Returns all process that are not by root, nobody, and syslog user.
|
|
225
243
|
}
|
226
244
|
```
|
227
245
|
|
228
|
-
|
246
|
+
### ALL
|
229
247
|
|
230
|
-
LinuxSystemInfo.
|
248
|
+
#### LinuxSystemInfo.all
|
231
249
|
|
232
250
|
```ruby
|
233
251
|
{
|
234
|
-
:
|
235
|
-
|
236
|
-
:
|
237
|
-
:
|
238
|
-
:users => "8"
|
252
|
+
"info": {
|
253
|
+
"os": "Linux version 4.4.0-24-generic (buildd@lgw01-12) (gcc version 5.3.1 20160413 (Ubuntu 5.3.1-14ubuntu2.1) ) #43-Ubuntu SMP Wed Jun 8 19:27:37 UTC 2016",
|
254
|
+
"uptime": "07:43:25 up 1:04",
|
255
|
+
"users": "3 users"
|
239
256
|
},
|
240
|
-
:
|
241
|
-
:
|
242
|
-
|
243
|
-
|
244
|
-
|
245
|
-
|
246
|
-
|
247
|
-
|
248
|
-
|
249
|
-
|
250
|
-
|
251
|
-
|
252
|
-
|
253
|
-
|
254
|
-
|
255
|
-
|
256
|
-
|
257
|
-
:d => "32K",
|
258
|
-
:i => "32K"
|
257
|
+
"hostname": "zen",
|
258
|
+
"cpu": {
|
259
|
+
"info": {
|
260
|
+
"model": {
|
261
|
+
"name": " Intel(R) Core(TM) i7-3537U CPU @ 2.00GHz",
|
262
|
+
"number": "58"
|
263
|
+
},
|
264
|
+
"address_sizes": " 36 bits physical, 48 bits virtual",
|
265
|
+
"architecture": "x86_64",
|
266
|
+
"threads": "2",
|
267
|
+
"cores": "2",
|
268
|
+
"socket": "1",
|
269
|
+
"family": "6",
|
270
|
+
"flags": " fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm pbe syscall nx rdtscp lm constant_tsc arch_perfmon pebs bts rep_good nopl xtopology nonstop_tsc aperfmperf eagerfpu pni pclmulqdq dtes64 monitor ds_cpl vmx est tm2 ssse3 cx16 xtpr pdcm pcid sse4_1 sse4_2 x2apic popcnt tsc_deadline_timer aes xsave avx f16c rdrand lahf_lm epb tpr_shadow vnmi flexpriority ept vpid fsgsbase smep erms xsaveopt dtherm ida arat pln pts",
|
271
|
+
"L1": "32K",
|
272
|
+
"L2": "256K",
|
273
|
+
"L3": "4096K"
|
259
274
|
},
|
260
|
-
:
|
261
|
-
|
275
|
+
"usage": {
|
276
|
+
"user": "5.61",
|
277
|
+
"nice": "0.28",
|
278
|
+
"system": "1.43",
|
279
|
+
"iowait": "0.27",
|
280
|
+
"irq": "0.00",
|
281
|
+
"soft": "0.02",
|
282
|
+
"steal": "0.00",
|
283
|
+
"guest": "0.00",
|
284
|
+
"gnice": "0.00",
|
285
|
+
"idle": "92.39",
|
286
|
+
"usage": 7.61
|
287
|
+
}
|
262
288
|
},
|
263
|
-
:
|
264
|
-
|
265
|
-
:
|
266
|
-
:
|
267
|
-
:
|
268
|
-
:
|
269
|
-
:
|
270
|
-
:
|
271
|
-
:cached => "1836"
|
289
|
+
"ram": {
|
290
|
+
"unit": "Megabyte",
|
291
|
+
"total": "7429",
|
292
|
+
"used": "1415",
|
293
|
+
"free": "4165",
|
294
|
+
"shared": "189",
|
295
|
+
"buffers": "1849",
|
296
|
+
"cached": "5500"
|
272
297
|
},
|
273
|
-
:
|
274
|
-
|
275
|
-
|
276
|
-
|
277
|
-
:
|
278
|
-
:
|
279
|
-
:
|
280
|
-
:used_percentage => "17%",
|
281
|
-
:mount => "/"
|
298
|
+
"storage": {
|
299
|
+
"/dev/sda5": {
|
300
|
+
"size": "59G",
|
301
|
+
"used": "44G",
|
302
|
+
"available": "13G",
|
303
|
+
"used_percentage": "78%",
|
304
|
+
"mount": "/"
|
282
305
|
},
|
283
|
-
"/dev/
|
284
|
-
|
285
|
-
:
|
286
|
-
:
|
287
|
-
:
|
288
|
-
:
|
289
|
-
:mount => "/home"
|
306
|
+
"/dev/sda7": {
|
307
|
+
"size": "175G",
|
308
|
+
"used": "29G",
|
309
|
+
"available": "137G",
|
310
|
+
"used_percentage": "18%",
|
311
|
+
"mount": "/home"
|
290
312
|
},
|
291
|
-
"/dev/
|
292
|
-
|
293
|
-
:
|
294
|
-
:
|
295
|
-
:
|
296
|
-
:
|
297
|
-
:mount => "/repos"
|
298
|
-
},
|
299
|
-
"/dev/sda5" =>
|
300
|
-
{
|
301
|
-
:size => "23G",
|
302
|
-
:used => "3.1G",
|
303
|
-
:available => "20G",
|
304
|
-
:used_percentage => "14%",
|
305
|
-
:mount => "/virtualbox"
|
313
|
+
"/dev/sda1": {
|
314
|
+
"size": "93M",
|
315
|
+
"used": "3.6M",
|
316
|
+
"available": "90M",
|
317
|
+
"used_percentage": "4%",
|
318
|
+
"mount": "/boot/efi"
|
306
319
|
}
|
307
320
|
},
|
308
|
-
:
|
309
|
-
|
310
|
-
"Intel Corporation Ethernet Connection I218-V (rev 04)",
|
311
|
-
"Intel Corporation Wireless 7260 (rev 73)"
|
321
|
+
"network": [
|
322
|
+
"Intel Corporation Centrino Advanced-N 6235 (rev 24)"
|
312
323
|
],
|
313
|
-
:
|
314
|
-
|
315
|
-
|
316
|
-
|
317
|
-
:
|
318
|
-
:
|
319
|
-
:
|
320
|
-
|
321
|
-
|
324
|
+
"connection": {
|
325
|
+
"virbr0": {
|
326
|
+
"mac": "00:00:00:00:00:00",
|
327
|
+
"ip": "192.168.1.1",
|
328
|
+
"mask": "255.255.255.0",
|
329
|
+
"broadcast": "192.168.122.255",
|
330
|
+
"ip6": ""
|
331
|
+
},
|
332
|
+
"wlp2": {
|
333
|
+
"mac": "24:55:18:16:c9:88",
|
334
|
+
"ip": "192.168.0.10",
|
335
|
+
"mask": "255.255.255.0",
|
336
|
+
"broadcast": "192.168.43.255",
|
337
|
+
"ip6": "fe80::5a19:343b:3bd8:cc2c/64"
|
322
338
|
}
|
323
339
|
},
|
324
|
-
:
|
325
|
-
|
326
|
-
"Intel Corporation Haswell-ULT Integrated Graphics Controller (rev 09)"
|
340
|
+
"video": [
|
341
|
+
"Intel Corporation 3rd Gen Core processor Graphics Controller (rev 09)"
|
327
342
|
],
|
328
|
-
:
|
329
|
-
|
330
|
-
"Intel Corporation Haswell-ULT HD Audio Controller (rev 09)",
|
331
|
-
"Intel Corporation Lynx Point-LP HD Audio Controller (rev 04)"
|
343
|
+
"audio": [
|
344
|
+
"Intel Corporation 7 Series/C210 Series Chipset Family High Definition Audio Controller (rev 04)"
|
332
345
|
],
|
333
|
-
:
|
334
|
-
|
335
|
-
"Intel Corporation
|
336
|
-
"Intel Corporation Lynx Point-LP USB EHCI #1 (rev 04)"
|
346
|
+
"usb": [
|
347
|
+
"Intel Corporation 7 Series/C210 Series Chipset Family USB Enhanced Host Controller #2 (rev 04)",
|
348
|
+
"Intel Corporation 7 Series/C210 Series Chipset Family USB Enhanced Host Controller #1 (rev 04)"
|
337
349
|
]
|
338
350
|
}
|
339
351
|
```
|
340
352
|
|
341
353
|
Notice: to_s prints the hash as JSON what is for printing purpose only.
|
342
354
|
Example: LinuxSystemInfo.to_s
|
343
|
-
|
344
|
-
|
345
|
-
## Contributing
|
346
|
-
|
347
|
-
1. Fork it ( https://github.com/SaimonL/LinuxSystemInfo/fork )
|
348
|
-
2. Create your feature branch (`git checkout -b my-new-feature`)
|
349
|
-
3. Commit your changes (`git commit -am 'Add some feature'`)
|
350
|
-
4. Push to the branch (`git push origin my-new-feature`)
|
351
|
-
5. Create a new Pull Request
|
data/lib/LinuxSystemInfo.rb
CHANGED
@@ -1,15 +1,17 @@
|
|
1
1
|
require 'LinuxSystemInfo/version'
|
2
2
|
require 'json'
|
3
3
|
|
4
|
+
require 'components/processors'
|
5
|
+
require 'components/network'
|
6
|
+
require 'components/memory'
|
7
|
+
require 'components/media'
|
8
|
+
|
4
9
|
module LinuxSystemInfo
|
5
10
|
class << self
|
6
11
|
def info
|
7
12
|
uptime = `uptime`.strip
|
8
13
|
uptime = uptime.split(',')
|
9
14
|
|
10
|
-
running_time = ''
|
11
|
-
users = ''
|
12
|
-
|
13
15
|
if uptime[1].match(/\d+ (user|users)/).nil?
|
14
16
|
running_time = [ uptime[0], uptime[1] ].join ', '
|
15
17
|
users = uptime[2]
|
@@ -25,131 +27,6 @@ module LinuxSystemInfo
|
|
25
27
|
}
|
26
28
|
end
|
27
29
|
|
28
|
-
def connection
|
29
|
-
output = Hash.new
|
30
|
-
network = `ifconfig`
|
31
|
-
network = network.split("\n\n")
|
32
|
-
|
33
|
-
network.each do |data|
|
34
|
-
interface = data.scan(/^[a-z]+\d?/).first
|
35
|
-
next if interface == 'lo'
|
36
|
-
next if data.match(/addr:(\d+\.)+\d+/).to_s.sub('addr:', '').empty?
|
37
|
-
output[interface] = {
|
38
|
-
:mac => data.match(/HWaddr [a-z0-9:]+/).to_s.sub('HWaddr ', ''),
|
39
|
-
:ip => data.match(/inet addr:(\d+\.)+\d+/).to_s.sub('inet addr:', ''),
|
40
|
-
:mask => data.match(/Mask:(\d+\.?)+/).to_s.sub('Mask:', ''),
|
41
|
-
:broadcast => data.match(/Bcast:(\d+\.?)+/).to_s.sub('Bcast:', ''),
|
42
|
-
:ip6 => data.match(/inet6 addr: (([a-z]|\d)+([a-z]|\d)+(:|::)+)+(([a-z]|\d)+(\/)*([a-z]|\d)+)/).to_s.sub('inet6 addr:', '').strip
|
43
|
-
}
|
44
|
-
end
|
45
|
-
output
|
46
|
-
end
|
47
|
-
|
48
|
-
def cpu
|
49
|
-
cpu = `lscpu`
|
50
|
-
cpu = cpu.split("\n")
|
51
|
-
|
52
|
-
cpu_detail = `cat /proc/cpuinfo`
|
53
|
-
cpu_detail = cpu_detail.split("\n")
|
54
|
-
|
55
|
-
output = {
|
56
|
-
:model => {
|
57
|
-
:name => cpu_detail.grep(/model name/).first.split(':').last,
|
58
|
-
:number => cpu.grep(/Model/).first.split.last
|
59
|
-
},
|
60
|
-
:address_sizes => cpu_detail.grep(/address sizes/).first.split(':').last,
|
61
|
-
:architecture => cpu.grep(/Architecture/).first.split.last,
|
62
|
-
:threads => cpu.grep(/Thread/).first.split.last,
|
63
|
-
:cores => cpu.grep(/Core/).first.split.last,
|
64
|
-
:socket => cpu.grep(/Socket/).first.split.last,
|
65
|
-
:family => cpu.grep(/family/).first.split.last,
|
66
|
-
:flags => cpu_detail.grep(/flags/).first.split(':').last
|
67
|
-
}
|
68
|
-
|
69
|
-
(1..50).each do |l|
|
70
|
-
find = "L#{l}[a-z]* cache:"
|
71
|
-
unless cpu.grep(/#{find}/) == []
|
72
|
-
output.merge!({ :"L#{l}" => cpu.grep(/#{find}/).first.split(':').last.strip })
|
73
|
-
end
|
74
|
-
end
|
75
|
-
|
76
|
-
output
|
77
|
-
end
|
78
|
-
|
79
|
-
def memory
|
80
|
-
ram = `free -m`
|
81
|
-
ram = ram.split("\n")[1].split
|
82
|
-
{
|
83
|
-
:unit => 'Megabyte',
|
84
|
-
:total => ram[1],
|
85
|
-
:used => ram[2],
|
86
|
-
:free => ram[3],
|
87
|
-
:shared => ram[4],
|
88
|
-
:buffers => ram[5],
|
89
|
-
:cached => ram[6]
|
90
|
-
}
|
91
|
-
end
|
92
|
-
|
93
|
-
def processes
|
94
|
-
users = 'root,nobody,syslog'
|
95
|
-
procs = `ps u -U '#{users}' -u '#{users}' -N`
|
96
|
-
output = Hash.new
|
97
|
-
procs = procs.split("\n")
|
98
|
-
procs.slice!(0)
|
99
|
-
procs.each do |proc|
|
100
|
-
proc = proc.split
|
101
|
-
output[proc[1]] = {
|
102
|
-
user: proc[0], pid: proc[1], cpu: proc[2],
|
103
|
-
mem: proc[3], vsz: proc[4], rss: proc[5],
|
104
|
-
tty: proc[6], stat: proc[7], start: proc[8],
|
105
|
-
time: proc[9], command: proc[10]
|
106
|
-
}
|
107
|
-
end
|
108
|
-
output
|
109
|
-
end
|
110
|
-
|
111
|
-
def storage
|
112
|
-
output = Hash.new
|
113
|
-
storage = `df -h`
|
114
|
-
storage = storage.split("\n")
|
115
|
-
storage.each do |file|
|
116
|
-
file = file.split
|
117
|
-
next if file[0][0..4] != '/dev/'
|
118
|
-
next if file[1].nil?
|
119
|
-
output[file[0]] = {
|
120
|
-
:size => file[1],
|
121
|
-
:used => file[2],
|
122
|
-
:available => file[3],
|
123
|
-
:used_percentage => file[4],
|
124
|
-
:mount => file[5]
|
125
|
-
}
|
126
|
-
end
|
127
|
-
output
|
128
|
-
end
|
129
|
-
|
130
|
-
def video
|
131
|
-
data = Array.new
|
132
|
-
video = `lspci`
|
133
|
-
# Graphics Controller
|
134
|
-
videos = video.split("\n").grep /(VGA|Graphics Controller)/
|
135
|
-
videos.each do |video|
|
136
|
-
video = video.split(':')
|
137
|
-
data.push video[2].strip
|
138
|
-
end
|
139
|
-
data
|
140
|
-
end
|
141
|
-
|
142
|
-
def audio
|
143
|
-
data = Array.new
|
144
|
-
audio = `lspci`
|
145
|
-
audios = audio.split("\n").grep /Audio/
|
146
|
-
audios.each do |audio|
|
147
|
-
audio = audio.split(':')
|
148
|
-
data.push audio[2].strip
|
149
|
-
end
|
150
|
-
data
|
151
|
-
end
|
152
|
-
|
153
30
|
def usb
|
154
31
|
data = Array.new
|
155
32
|
usb = `lspci`
|
@@ -162,27 +39,15 @@ module LinuxSystemInfo
|
|
162
39
|
data
|
163
40
|
end
|
164
41
|
|
165
|
-
def network
|
166
|
-
data = Array.new
|
167
|
-
connection = `lspci`
|
168
|
-
connection = connection.split("\n")
|
169
|
-
connections = connection.grep /(Network|Ethernet)/
|
170
|
-
connections.each do |connection|
|
171
|
-
connection = connection.split(':')
|
172
|
-
data.push connection[2].strip
|
173
|
-
end
|
174
|
-
data
|
175
|
-
end
|
176
|
-
|
177
42
|
def hostname
|
178
43
|
`hostname`.strip
|
179
44
|
end
|
180
45
|
|
181
|
-
def
|
46
|
+
def all
|
182
47
|
{
|
183
48
|
:info => info,
|
184
49
|
:hostname => hostname,
|
185
|
-
:cpu => cpu,
|
50
|
+
:cpu => { info: cpu, usage: cpu_usage },
|
186
51
|
:ram => memory,
|
187
52
|
:storage => storage,
|
188
53
|
:network => network,
|
@@ -194,7 +59,7 @@ module LinuxSystemInfo
|
|
194
59
|
end
|
195
60
|
|
196
61
|
def to_s
|
197
|
-
JSON.pretty_generate(
|
62
|
+
JSON.pretty_generate(all)
|
198
63
|
end
|
199
64
|
end
|
200
65
|
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
module LinuxSystemInfo
|
2
|
+
class << self
|
3
|
+
def video
|
4
|
+
data = Array.new
|
5
|
+
video = `lspci`
|
6
|
+
# Graphics Controller
|
7
|
+
videos = video.split("\n").grep /(VGA|Graphics Controller)/
|
8
|
+
videos.each do |video|
|
9
|
+
video = video.split(':')
|
10
|
+
data.push video[2].strip
|
11
|
+
end
|
12
|
+
data
|
13
|
+
end
|
14
|
+
|
15
|
+
def audio
|
16
|
+
data = Array.new
|
17
|
+
audio = `lspci`
|
18
|
+
audios = audio.split("\n").grep /Audio/
|
19
|
+
audios.each do |audio|
|
20
|
+
audio = audio.split(':')
|
21
|
+
data.push audio[2].strip
|
22
|
+
end
|
23
|
+
data
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
module LinuxSystemInfo
|
2
|
+
class << self
|
3
|
+
def memory
|
4
|
+
ram = `free -m`
|
5
|
+
ram = ram.split("\n")[1].split
|
6
|
+
{
|
7
|
+
:unit => 'Megabyte',
|
8
|
+
:total => ram[1],
|
9
|
+
:used => ram[2],
|
10
|
+
:free => ram[3],
|
11
|
+
:shared => ram[4],
|
12
|
+
:buffers => ram[5],
|
13
|
+
:cached => ram[6]
|
14
|
+
}
|
15
|
+
end
|
16
|
+
|
17
|
+
def storage
|
18
|
+
output = Hash.new
|
19
|
+
storage = `df -h`
|
20
|
+
storage = storage.split("\n")
|
21
|
+
storage.each do |file|
|
22
|
+
file = file.split
|
23
|
+
next if file[0][0..4] != '/dev/'
|
24
|
+
next if file[1].nil?
|
25
|
+
output[file[0]] = {
|
26
|
+
:size => file[1],
|
27
|
+
:used => file[2],
|
28
|
+
:available => file[3],
|
29
|
+
:used_percentage => file[4],
|
30
|
+
:mount => file[5]
|
31
|
+
}
|
32
|
+
end
|
33
|
+
output
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
module LinuxSystemInfo
|
2
|
+
class << self
|
3
|
+
def connection
|
4
|
+
output = Hash.new
|
5
|
+
network = `ifconfig`
|
6
|
+
network = network.split("\n\n")
|
7
|
+
|
8
|
+
network.each do |data|
|
9
|
+
interface = data.scan(/^[a-z]+\d?/).first
|
10
|
+
next if interface == 'lo'
|
11
|
+
next if data.match(/addr:(\d+\.)+\d+/).to_s.sub('addr:', '').empty?
|
12
|
+
output[interface] = {
|
13
|
+
:mac => data.match(/HWaddr [a-z0-9:]+/).to_s.sub('HWaddr ', ''),
|
14
|
+
:ip => data.match(/inet addr:(\d+\.)+\d+/).to_s.sub('inet addr:', ''),
|
15
|
+
:mask => data.match(/Mask:(\d+\.?)+/).to_s.sub('Mask:', ''),
|
16
|
+
:broadcast => data.match(/Bcast:(\d+\.?)+/).to_s.sub('Bcast:', ''),
|
17
|
+
:ip6 => data.match(/inet6 addr: (([a-z]|\d)+([a-z]|\d)+(:|::)+)+(([a-z]|\d)+(\/)*([a-z]|\d)+)/).to_s.sub('inet6 addr:', '').strip
|
18
|
+
}
|
19
|
+
end
|
20
|
+
output
|
21
|
+
end
|
22
|
+
|
23
|
+
def network
|
24
|
+
data = Array.new
|
25
|
+
connection = `lspci`
|
26
|
+
connection = connection.split("\n")
|
27
|
+
connections = connection.grep /(Network|Ethernet)/
|
28
|
+
connections.each do |connection|
|
29
|
+
connection = connection.split(':')
|
30
|
+
data.push connection[2].strip
|
31
|
+
end
|
32
|
+
data
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
@@ -0,0 +1,74 @@
|
|
1
|
+
module LinuxSystemInfo
|
2
|
+
class << self
|
3
|
+
def cpu
|
4
|
+
cpu = `lscpu`
|
5
|
+
cpu = cpu.split("\n")
|
6
|
+
|
7
|
+
cpu_detail = `cat /proc/cpuinfo`
|
8
|
+
cpu_detail = cpu_detail.split("\n")
|
9
|
+
|
10
|
+
output = {
|
11
|
+
:model => {
|
12
|
+
:name => cpu_detail.grep(/model name/).first.split(':').last,
|
13
|
+
:number => cpu.grep(/Model/).first.split.last
|
14
|
+
},
|
15
|
+
:address_sizes => cpu_detail.grep(/address sizes/).first.split(':').last,
|
16
|
+
:architecture => cpu.grep(/Architecture/).first.split.last,
|
17
|
+
:threads => cpu.grep(/Thread/).first.split.last,
|
18
|
+
:cores => cpu.grep(/Core/).first.split.last,
|
19
|
+
:socket => cpu.grep(/Socket/).first.split.last,
|
20
|
+
:family => cpu.grep(/family/).first.split.last,
|
21
|
+
:flags => cpu_detail.grep(/flags/).first.split(':').last
|
22
|
+
}
|
23
|
+
|
24
|
+
(1..50).each do |l|
|
25
|
+
find = "L#{l}[a-z]* cache:"
|
26
|
+
unless cpu.grep(/#{find}/) == []
|
27
|
+
output.merge!({ :"L#{l}" => cpu.grep(/#{find}/).first.split(':').last.strip })
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
output
|
32
|
+
end
|
33
|
+
|
34
|
+
# In percentage
|
35
|
+
def cpu_usage
|
36
|
+
status = `mpstat`.split("\n").last.split
|
37
|
+
usage = (100 - status[12].to_f).round(2)
|
38
|
+
usage = 100 if usage > 100
|
39
|
+
usage = 0 if usage < 0
|
40
|
+
|
41
|
+
{
|
42
|
+
user: status[3],
|
43
|
+
nice: status[4],
|
44
|
+
system: status[5],
|
45
|
+
iowait: status[6],
|
46
|
+
irq: status[7],
|
47
|
+
soft: status[8],
|
48
|
+
steal: status[9],
|
49
|
+
guest: status[10],
|
50
|
+
gnice: status[11],
|
51
|
+
idle: status[12],
|
52
|
+
usage: usage
|
53
|
+
}
|
54
|
+
end
|
55
|
+
|
56
|
+
def processes
|
57
|
+
users = 'root,nobody,syslog'
|
58
|
+
procs = `ps u -U '#{users}' -u '#{users}' -N`
|
59
|
+
output = Hash.new
|
60
|
+
procs = procs.split("\n")
|
61
|
+
procs.slice!(0)
|
62
|
+
procs.each do |proc|
|
63
|
+
proc = proc.split
|
64
|
+
output[proc[1]] = {
|
65
|
+
user: proc[0], pid: proc[1], cpu: proc[2],
|
66
|
+
mem: proc[3], vsz: proc[4], rss: proc[5],
|
67
|
+
tty: proc[6], stat: proc[7], start: proc[8],
|
68
|
+
time: proc[9], command: proc[10]
|
69
|
+
}
|
70
|
+
end
|
71
|
+
output
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
metadata
CHANGED
@@ -1,71 +1,85 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: LinuxSystemInfo
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Saimon Lovell
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2016-06-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: json
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
13
27
|
- !ruby/object:Gem::Dependency
|
14
28
|
name: bundler
|
15
29
|
requirement: !ruby/object:Gem::Requirement
|
16
30
|
requirements:
|
17
|
-
- - "
|
31
|
+
- - ">="
|
18
32
|
- !ruby/object:Gem::Version
|
19
|
-
version: '
|
33
|
+
version: '0'
|
20
34
|
type: :development
|
21
35
|
prerelease: false
|
22
36
|
version_requirements: !ruby/object:Gem::Requirement
|
23
37
|
requirements:
|
24
|
-
- - "
|
38
|
+
- - ">="
|
25
39
|
- !ruby/object:Gem::Version
|
26
|
-
version: '
|
40
|
+
version: '0'
|
27
41
|
- !ruby/object:Gem::Dependency
|
28
42
|
name: rake
|
29
43
|
requirement: !ruby/object:Gem::Requirement
|
30
44
|
requirements:
|
31
|
-
- - "
|
45
|
+
- - ">="
|
32
46
|
- !ruby/object:Gem::Version
|
33
|
-
version: '
|
47
|
+
version: '0'
|
34
48
|
type: :development
|
35
49
|
prerelease: false
|
36
50
|
version_requirements: !ruby/object:Gem::Requirement
|
37
51
|
requirements:
|
38
|
-
- - "
|
52
|
+
- - ">="
|
39
53
|
- !ruby/object:Gem::Version
|
40
|
-
version: '
|
54
|
+
version: '0'
|
41
55
|
- !ruby/object:Gem::Dependency
|
42
56
|
name: json
|
43
57
|
requirement: !ruby/object:Gem::Requirement
|
44
58
|
requirements:
|
45
59
|
- - ">="
|
46
60
|
- !ruby/object:Gem::Version
|
47
|
-
version: '
|
61
|
+
version: '0'
|
48
62
|
type: :development
|
49
63
|
prerelease: false
|
50
64
|
version_requirements: !ruby/object:Gem::Requirement
|
51
65
|
requirements:
|
52
66
|
- - ">="
|
53
67
|
- !ruby/object:Gem::Version
|
54
|
-
version: '
|
68
|
+
version: '0'
|
55
69
|
- !ruby/object:Gem::Dependency
|
56
70
|
name: rspec
|
57
71
|
requirement: !ruby/object:Gem::Requirement
|
58
72
|
requirements:
|
59
73
|
- - ">="
|
60
74
|
- !ruby/object:Gem::Version
|
61
|
-
version: '
|
75
|
+
version: '0'
|
62
76
|
type: :development
|
63
77
|
prerelease: false
|
64
78
|
version_requirements: !ruby/object:Gem::Requirement
|
65
79
|
requirements:
|
66
80
|
- - ">="
|
67
81
|
- !ruby/object:Gem::Version
|
68
|
-
version: '
|
82
|
+
version: '0'
|
69
83
|
description: This gem gives information about RAM, CPU, HARD Drives and more. Works
|
70
84
|
only on Linux OS.
|
71
85
|
email:
|
@@ -84,6 +98,10 @@ files:
|
|
84
98
|
- Rakefile
|
85
99
|
- lib/LinuxSystemInfo.rb
|
86
100
|
- lib/LinuxSystemInfo/version.rb
|
101
|
+
- lib/components/media.rb
|
102
|
+
- lib/components/memory.rb
|
103
|
+
- lib/components/network.rb
|
104
|
+
- lib/components/processors.rb
|
87
105
|
- spec/audio_spec.rb
|
88
106
|
- spec/connection_spec.rb
|
89
107
|
- spec/cpu_spec.rb
|
@@ -115,7 +133,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
115
133
|
version: '0'
|
116
134
|
requirements: []
|
117
135
|
rubyforge_project:
|
118
|
-
rubygems_version: 2.4
|
136
|
+
rubygems_version: 2.6.4
|
119
137
|
signing_key:
|
120
138
|
specification_version: 4
|
121
139
|
summary: Get local linux hardware information.
|