linux_stat 0.9.0 → 0.9.2
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/README.md +99 -78
- data/ext/sysconf/sysconf.c +52 -13
- data/lib/linux_stat/battery.rb +166 -11
- data/lib/linux_stat/cpu.rb +55 -10
- data/lib/linux_stat/process_info.rb +3 -2
- data/lib/linux_stat/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 51a901fa3464ea37e42bdc1f798be4feb01bbdf58bc3c00c939166c302f65fc7
|
4
|
+
data.tar.gz: 8edfc5a3d31ae3be01848ad0984314702940e34ad14bbb7016144f2208f9bfb2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2ebcdc193d240a363b7563ddac6c4de631927bd2617f5ec69a7cf4858cda63ec3e712b1b518625729a875b676b74bdf1ca5e6522bbf78bda10eb7abf8aff0efb
|
7
|
+
data.tar.gz: a5903aa2b5a941ac23fb090c6577997383bb8435a41d8c52a4532c174e910b5901a94687a55373bf0f9b0ae87faf91547c1d30507781bbd8b3401e792ad05549
|
data/README.md
CHANGED
@@ -85,27 +85,42 @@ LinuxStat::BIOS.version()
|
|
85
85
|
|
86
86
|
### LinuxStat::Battery
|
87
87
|
```
|
88
|
-
# File: battery.rb | Line:
|
88
|
+
# File: battery.rb | Line: 105
|
89
89
|
# Definition: def charge
|
90
90
|
LinuxStat::Battery.charge()
|
91
91
|
=> 100.0
|
92
92
|
|
93
|
-
# File: battery.rb | Line:
|
93
|
+
# File: battery.rb | Line: 122
|
94
|
+
# Definition: def charge_full_design_wh
|
95
|
+
LinuxStat::Battery.charge_full_design_wh()
|
96
|
+
=> 42.0
|
97
|
+
|
98
|
+
# File: battery.rb | Line: 141
|
99
|
+
# Definition: def charge_full_wh
|
100
|
+
LinuxStat::Battery.charge_full_wh()
|
101
|
+
=> 23.79
|
102
|
+
|
103
|
+
# File: battery.rb | Line: 78
|
94
104
|
# Definition: def charging?
|
95
105
|
LinuxStat::Battery.charging?()
|
96
106
|
=> true
|
97
107
|
|
98
|
-
# File: battery.rb | Line:
|
108
|
+
# File: battery.rb | Line: 184
|
109
|
+
# Definition: def devices_stat
|
110
|
+
LinuxStat::Battery.devices_stat()
|
111
|
+
=> {:AC=>{:type=>"Mains", :online=>1}, :BAT0=>{:model=>"DELL CYMGM77", :manufacturer=>"Samsung SDI", :type=>"Battery", :status=>"Full", :capacity=>100, :voltage_min_design=>11.4, :charge_full_design=>3.684, :charge_full_design_wh=>42.0, :voltage_now=>12....
|
112
|
+
|
113
|
+
# File: battery.rb | Line: 87
|
99
114
|
# Definition: def discharging?
|
100
115
|
LinuxStat::Battery.discharging?()
|
101
116
|
=> false
|
102
117
|
|
103
|
-
# File: battery.rb | Line:
|
118
|
+
# File: battery.rb | Line: 96
|
104
119
|
# Definition: def full?
|
105
120
|
LinuxStat::Battery.full?()
|
106
121
|
=> true
|
107
122
|
|
108
|
-
# File: battery.rb | Line:
|
123
|
+
# File: battery.rb | Line: 47
|
109
124
|
# Definition: def manufacturer
|
110
125
|
LinuxStat::Battery.manufacturer()
|
111
126
|
=> "Samsung SDI"
|
@@ -125,26 +140,26 @@ LinuxStat::Battery.present?()
|
|
125
140
|
LinuxStat::Battery.stat()
|
126
141
|
=> {:model=>"DELL CYMGM77", :manufacturer=>"Samsung SDI", :technology=>"Li-ion", :status=>"Full", :charge=>100.0, :charging=>true, :discharging=>false, :full=>true}
|
127
142
|
|
128
|
-
# File: battery.rb | Line:
|
143
|
+
# File: battery.rb | Line: 68
|
129
144
|
# Definition: def status
|
130
145
|
LinuxStat::Battery.status()
|
131
146
|
=> "Full"
|
132
147
|
|
133
|
-
# File: battery.rb | Line:
|
148
|
+
# File: battery.rb | Line: 57
|
134
149
|
# Definition: def technology
|
135
150
|
LinuxStat::Battery.technology()
|
136
151
|
=> "Li-ion"
|
137
152
|
|
138
|
-
# File: battery.rb | Line:
|
153
|
+
# File: battery.rb | Line: 160
|
139
154
|
# Definition: def voltage_now
|
140
155
|
LinuxStat::Battery.voltage_now()
|
141
|
-
=> 12.
|
156
|
+
=> 12.561
|
142
157
|
|
143
158
|
```
|
144
159
|
|
145
160
|
### LinuxStat::CPU
|
146
161
|
```
|
147
|
-
# File: cpu.rb | Line:
|
162
|
+
# File: cpu.rb | Line: 287
|
148
163
|
# Definition: def available_governors
|
149
164
|
LinuxStat::CPU.available_governors()
|
150
165
|
=> {"cpu0"=>["performance", "powersave"], "cpu1"=>["performance", "powersave"], "cpu2"=>["performance", "powersave"], "cpu3"=>["performance", "powersave"]}
|
@@ -154,37 +169,42 @@ LinuxStat::CPU.available_governors()
|
|
154
169
|
LinuxStat::CPU.count()
|
155
170
|
=> 4
|
156
171
|
|
157
|
-
# File: cpu.rb | Line:
|
172
|
+
# File: cpu.rb | Line: 103
|
173
|
+
# Definition: def count_online
|
174
|
+
LinuxStat::CPU.count_online()
|
175
|
+
=> 4
|
176
|
+
|
177
|
+
# File: cpu.rb | Line: 197
|
158
178
|
# Definition: def cur_freq
|
159
179
|
LinuxStat::CPU.cur_freq()
|
160
|
-
=> {"cpu0"=>
|
180
|
+
=> {"cpu0"=>2000033, "cpu1"=>2000014, "cpu2"=>2000085, "cpu3"=>2000299}
|
161
181
|
|
162
|
-
# File: cpu.rb | Line:
|
182
|
+
# File: cpu.rb | Line: 265
|
163
183
|
# Definition: def governor
|
164
184
|
LinuxStat::CPU.governor()
|
165
185
|
=> {"cpu0"=>"performance", "cpu1"=>"performance", "cpu2"=>"performance", "cpu3"=>"performance"}
|
166
186
|
|
167
|
-
# File: cpu.rb | Line:
|
187
|
+
# File: cpu.rb | Line: 241
|
168
188
|
# Definition: def max_freq
|
169
189
|
LinuxStat::CPU.max_freq()
|
170
190
|
=> {"cpu0"=>2000000, "cpu1"=>2000000, "cpu2"=>2000000, "cpu3"=>2000000}
|
171
191
|
|
172
|
-
# File: cpu.rb | Line:
|
192
|
+
# File: cpu.rb | Line: 219
|
173
193
|
# Definition: def min_freq
|
174
194
|
LinuxStat::CPU.min_freq()
|
175
195
|
=> {"cpu0"=>2000000, "cpu1"=>2000000, "cpu2"=>2000000, "cpu3"=>2000000}
|
176
196
|
|
177
|
-
# File: cpu.rb | Line:
|
197
|
+
# File: cpu.rb | Line: 184
|
178
198
|
# Definition: def model
|
179
199
|
LinuxStat::CPU.model()
|
180
200
|
=> "Intel(R) Core(TM) i3-6006U CPU @ 2.00GHz"
|
181
201
|
|
182
|
-
# File: cpu.rb | Line:
|
202
|
+
# File: cpu.rb | Line: 163
|
183
203
|
# Definition: def offline
|
184
204
|
LinuxStat::CPU.offline()
|
185
205
|
=> []
|
186
206
|
|
187
|
-
# File: cpu.rb | Line:
|
207
|
+
# File: cpu.rb | Line: 132
|
188
208
|
# Definition: def online
|
189
209
|
LinuxStat::CPU.online()
|
190
210
|
=> [0, 1, 2, 3]
|
@@ -192,29 +212,29 @@ LinuxStat::CPU.online()
|
|
192
212
|
# File: cpu.rb | Line: 23
|
193
213
|
# Definition: def stat(sleep = ticks_to_ms_t5)
|
194
214
|
LinuxStat::CPU.stat(sleep)
|
195
|
-
=> {0=>
|
215
|
+
=> {0=>14.29, 1=>20.0, 2=>20.0, 3=>16.67, 4=>0.0}
|
196
216
|
|
197
217
|
# File: cpu.rb | Line: 63
|
198
218
|
# Definition: def total_usage(sleep = ticks_to_ms_t5)
|
199
219
|
LinuxStat::CPU.total_usage(sleep)
|
200
|
-
=>
|
220
|
+
=> 5.26
|
201
221
|
|
202
222
|
# File: cpu.rb | Line: 63
|
203
223
|
# Definition: def total_usage(sleep = ticks_to_ms_t5)
|
204
224
|
LinuxStat::CPU.usage(sleep)
|
205
|
-
=> 5.
|
225
|
+
=> 5.26
|
206
226
|
|
207
227
|
# File: cpu.rb | Line: 23
|
208
228
|
# Definition: def stat(sleep = ticks_to_ms_t5)
|
209
229
|
LinuxStat::CPU.usages(sleep)
|
210
|
-
=> {0=>
|
230
|
+
=> {0=>10.0, 1=>20.0, 2=>16.67, 3=>16.67, 4=>16.67}
|
211
231
|
|
212
232
|
```
|
213
233
|
|
214
234
|
### LinuxStat::FS
|
215
235
|
```
|
216
236
|
LinuxStat::FS.stat(arg = "/")
|
217
|
-
=> {:block_size=>4096, :fragment_size=>4096, :blocks=>29292283, :block_free=>
|
237
|
+
=> {:block_size=>4096, :fragment_size=>4096, :blocks=>29292283, :block_free=>12254480, :block_avail_unpriv=>12254480, :inodes=>58612160, :free_inodes=>56866575, :filesystem_id=>2050, :mount_flags=>1024, :max_filename_length=>255}
|
218
238
|
|
219
239
|
```
|
220
240
|
|
@@ -223,32 +243,32 @@ LinuxStat::FS.stat(arg = "/")
|
|
223
243
|
# File: filesystem.rb | Line: 92
|
224
244
|
# Definition: def available(fs = ?..freeze)
|
225
245
|
LinuxStat::Filesystem.available(fs)
|
226
|
-
=>
|
246
|
+
=> 50194350080
|
227
247
|
|
228
248
|
# File: filesystem.rb | Line: 58
|
229
249
|
# Definition: def free(fs = ?..freeze)
|
230
250
|
LinuxStat::Filesystem.free(fs)
|
231
|
-
=>
|
251
|
+
=> 50194350080
|
232
252
|
|
233
253
|
# File: filesystem.rb | Line: 19
|
234
254
|
# Definition: def stat(fs = ?..freeze)
|
235
255
|
LinuxStat::Filesystem.stat(fs)
|
236
|
-
=> {:total=>
|
256
|
+
=> {:total=>119981191168, :free=>50194350080, :used=>69786841088}
|
237
257
|
|
238
258
|
# File: filesystem.rb | Line: 108
|
239
259
|
# Definition: def stat_raw(fs = ?..freeze)
|
240
260
|
LinuxStat::Filesystem.stat_raw(fs)
|
241
|
-
=> {:block_size=>4096, :fragment_size=>4096, :blocks=>
|
261
|
+
=> {:block_size=>4096, :fragment_size=>4096, :blocks=>29292283, :block_free=>12254480, :block_avail_unpriv=>12254480, :inodes=>58612160, :free_inodes=>56866575, :filesystem_id=>2050, :mount_flags=>1024, :max_filename_length=>255}
|
242
262
|
|
243
263
|
# File: filesystem.rb | Line: 39
|
244
264
|
# Definition: def total(fs = ?..freeze)
|
245
265
|
LinuxStat::Filesystem.total(fs)
|
246
|
-
=>
|
266
|
+
=> 119981191168
|
247
267
|
|
248
268
|
# File: filesystem.rb | Line: 73
|
249
269
|
# Definition: def used(fs = ?..freeze)
|
250
270
|
LinuxStat::Filesystem.used(fs)
|
251
|
-
=>
|
271
|
+
=> 69786841088
|
252
272
|
|
253
273
|
```
|
254
274
|
|
@@ -311,32 +331,32 @@ LinuxStat::Kernel.version()
|
|
311
331
|
# File: memory.rb | Line: 50
|
312
332
|
# Definition: def available
|
313
333
|
LinuxStat::Memory.available()
|
314
|
-
=>
|
334
|
+
=> 1137124
|
315
335
|
|
316
336
|
# File: memory.rb | Line: 81
|
317
337
|
# Definition: def percent_available
|
318
338
|
LinuxStat::Memory.percent_available()
|
319
|
-
=>
|
339
|
+
=> 29.64
|
320
340
|
|
321
341
|
# File: memory.rb | Line: 70
|
322
342
|
# Definition: def percent_used
|
323
343
|
LinuxStat::Memory.percent_used()
|
324
|
-
=>
|
344
|
+
=> 70.36
|
325
345
|
|
326
346
|
# File: memory.rb | Line: 11
|
327
347
|
# Definition: def stat
|
328
348
|
LinuxStat::Memory.stat()
|
329
|
-
=> {:total=>
|
349
|
+
=> {:total=>3836228, :used=>2699104, :available=>1137124, :percent_used=>70.36, :percent_available=>29.64}
|
330
350
|
|
331
351
|
# File: memory.rb | Line: 40
|
332
352
|
# Definition: def total
|
333
353
|
LinuxStat::Memory.total()
|
334
|
-
=>
|
354
|
+
=> 3836228
|
335
355
|
|
336
356
|
# File: memory.rb | Line: 60
|
337
357
|
# Definition: def used
|
338
358
|
LinuxStat::Memory.used()
|
339
|
-
=>
|
359
|
+
=> 2699104
|
340
360
|
|
341
361
|
```
|
342
362
|
|
@@ -345,7 +365,7 @@ LinuxStat::Memory.used()
|
|
345
365
|
# File: mounts.rb | Line: 179
|
346
366
|
# Definition: def device_stat(dev = root)
|
347
367
|
LinuxStat::Mounts.device_stat(dev)
|
348
|
-
=> {:mountpoint=>"/", :total=>119981191168, :free=>
|
368
|
+
=> {:mountpoint=>"/", :total=>119981191168, :free=>50194350080, :available=>50194350080, :used=>69786841088, :percent_used=>58.16, :percent_free=>41.84, :percent_available=>41.84}
|
349
369
|
|
350
370
|
# File: mounts.rb | Line: 137
|
351
371
|
# Definition: def devices_stat
|
@@ -355,12 +375,12 @@ LinuxStat::Mounts.devices_stat()
|
|
355
375
|
# File: mounts.rb | Line: 11
|
356
376
|
# Definition: def list
|
357
377
|
LinuxStat::Mounts.list()
|
358
|
-
=> ["proc /proc proc rw,nosuid,nodev,noexec,relatime 0 0", "sys /sys sysfs rw,nosuid,nodev,noexec,relatime 0 0", "dev /dev devtmpfs rw,nosuid,relatime,size=
|
378
|
+
=> ["proc /proc proc rw,nosuid,nodev,noexec,relatime 0 0", "sys /sys sysfs rw,nosuid,nodev,noexec,relatime 0 0", "dev /dev devtmpfs rw,nosuid,relatime,size=1892900k,nr_inodes=473225,mode=755 0 0", "run /run tmpfs rw,nosuid,nodev,relatime,mode=755 0 0", "...
|
359
379
|
|
360
380
|
# File: mounts.rb | Line: 20
|
361
381
|
# Definition: def list_devices
|
362
382
|
LinuxStat::Mounts.list_devices()
|
363
|
-
=> ["proc", "sys", "dev", "run", "/dev/sda2", "securityfs", "tmpfs", "devpts", "tmpfs", "cgroup2", "cgroup", "pstore", "none", "cgroup", "cgroup", "cgroup", "cgroup", "cgroup", "cgroup", "cgroup", "cgroup", "cgroup", "cgroup", "cgroup", "systemd-1", "
|
383
|
+
=> ["proc", "sys", "dev", "run", "/dev/sda2", "securityfs", "tmpfs", "devpts", "tmpfs", "cgroup2", "cgroup", "pstore", "none", "cgroup", "cgroup", "cgroup", "cgroup", "cgroup", "cgroup", "cgroup", "cgroup", "cgroup", "cgroup", "cgroup", "systemd-1", "hug...
|
364
384
|
|
365
385
|
# File: mounts.rb | Line: 109
|
366
386
|
# Definition: def list_devices_mount_point
|
@@ -399,7 +419,7 @@ LinuxStat::Mounts.tmpfs()
|
|
399
419
|
# File: net.rb | Line: 80
|
400
420
|
# Definition: def usage(interval = 0.1)
|
401
421
|
LinuxStat::Net.current_usage(interval)
|
402
|
-
=> {:received=>
|
422
|
+
=> {:received=>1020.0, :transmitted=>940.0}
|
403
423
|
|
404
424
|
# File: net.rb | Line: 10
|
405
425
|
# Definition: def ipv4_private
|
@@ -409,17 +429,17 @@ LinuxStat::Net.ipv4_private()
|
|
409
429
|
# File: net.rb | Line: 23
|
410
430
|
# Definition: def total_bytes
|
411
431
|
LinuxStat::Net.total_bytes()
|
412
|
-
=> {:received=>
|
432
|
+
=> {:received=>336164612, :transmitted=>69471921}
|
413
433
|
|
414
434
|
# File: net.rb | Line: 41
|
415
435
|
# Definition: def total_bytes_received
|
416
436
|
LinuxStat::Net.total_bytes_received()
|
417
|
-
=>
|
437
|
+
=> 336164612
|
418
438
|
|
419
439
|
# File: net.rb | Line: 54
|
420
440
|
# Definition: def total_bytes_transmitted
|
421
441
|
LinuxStat::Net.total_bytes_transmitted()
|
422
|
-
=>
|
442
|
+
=> 69471921
|
423
443
|
|
424
444
|
# File: net.rb | Line: 80
|
425
445
|
# Definition: def usage(interval = 0.1)
|
@@ -428,10 +448,6 @@ LinuxStat::Net.usage(interval)
|
|
428
448
|
|
429
449
|
```
|
430
450
|
|
431
|
-
### LinuxStat::Nproc
|
432
|
-
```
|
433
|
-
```
|
434
|
-
|
435
451
|
### LinuxStat::OS
|
436
452
|
```
|
437
453
|
# File: os.rb | Line: 97
|
@@ -472,7 +488,7 @@ LinuxStat::OS.os_release()
|
|
472
488
|
# File: os.rb | Line: 110
|
473
489
|
# Definition: def uptime
|
474
490
|
LinuxStat::OS.uptime()
|
475
|
-
=> {:hour=>
|
491
|
+
=> {:hour=>12, :minute=>11, :second=>45.16}
|
476
492
|
|
477
493
|
```
|
478
494
|
|
@@ -480,23 +496,23 @@ LinuxStat::OS.uptime()
|
|
480
496
|
```
|
481
497
|
# File: prettify_bytes.rb | Line: 42
|
482
498
|
# Definition: def convert_binary(n)
|
483
|
-
LinuxStat::PrettifyBytes.convert_binary(n =
|
484
|
-
=> "
|
499
|
+
LinuxStat::PrettifyBytes.convert_binary(n = 122600299243524)
|
500
|
+
=> "111.50 tebibytes"
|
485
501
|
|
486
502
|
# File: prettify_bytes.rb | Line: 19
|
487
503
|
# Definition: def convert_decimal(n)
|
488
|
-
LinuxStat::PrettifyBytes.convert_decimal(n =
|
489
|
-
=> "
|
504
|
+
LinuxStat::PrettifyBytes.convert_decimal(n = 610088277227728)
|
505
|
+
=> "610.09 terabytes"
|
490
506
|
|
491
507
|
# File: prettify_bytes.rb | Line: 90
|
492
508
|
# Definition: def convert_short_binary(n)
|
493
|
-
LinuxStat::PrettifyBytes.convert_short_binary(n =
|
494
|
-
=> "
|
509
|
+
LinuxStat::PrettifyBytes.convert_short_binary(n = 117789985929175)
|
510
|
+
=> "107.13 TiB"
|
495
511
|
|
496
512
|
# File: prettify_bytes.rb | Line: 65
|
497
513
|
# Definition: def convert_short_decimal(n)
|
498
|
-
LinuxStat::PrettifyBytes.convert_short_decimal(n =
|
499
|
-
=> "
|
514
|
+
LinuxStat::PrettifyBytes.convert_short_decimal(n = 598923420265643)
|
515
|
+
=> "598.92 TB"
|
500
516
|
|
501
517
|
```
|
502
518
|
|
@@ -505,17 +521,17 @@ LinuxStat::PrettifyBytes.convert_short_decimal(n = 957289578618866)
|
|
505
521
|
# File: process.rb | Line: 19
|
506
522
|
# Definition: def count
|
507
523
|
LinuxStat::Process.count()
|
508
|
-
=>
|
524
|
+
=> 208
|
509
525
|
|
510
526
|
# File: process.rb | Line: 71
|
511
527
|
# Definition: def idle
|
512
528
|
LinuxStat::Process.idle()
|
513
|
-
=> [3, 4, 6, 9, 12, 23, 30, 37, 39, 49, 102, 103, 104, 106, 107, 108, 109, 110, 117,
|
529
|
+
=> [3, 4, 6, 9, 12, 23, 30, 37, 39, 49, 102, 103, 104, 106, 107, 108, 109, 110, 117, 119, 120, 122, 132, 135, 141, 153, 154, 170, 172, 174, 175, 178, 183, 184, 185, 186, 187, 188, 231, 263, 270, 331, 337, 5813, 9989, 16385, 17981, 18103, 18138, 18800, 18...
|
514
530
|
|
515
531
|
# File: process.rb | Line: 8
|
516
532
|
# Definition: def list
|
517
533
|
LinuxStat::Process.list()
|
518
|
-
=> [1, 2, 3, 4, 6, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 23, 24, 25, 26, 27, 28, 30, 31, 32, 33, 34, 35, 37, 38, 39, 40, 41, 42, 46, 47, 48, 49, 50, 51, 52, 102, 103, 104, 106, 107, 108, 109, 110, 112, 114, 115, 117,
|
534
|
+
=> [1, 2, 3, 4, 6, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 23, 24, 25, 26, 27, 28, 30, 31, 32, 33, 34, 35, 37, 38, 39, 40, 41, 42, 46, 47, 48, 49, 50, 51, 52, 102, 103, 104, 106, 107, 108, 109, 110, 112, 114, 115, 117, 119, 120, 122, 132, 135,...
|
519
535
|
|
520
536
|
# File: process.rb | Line: 25
|
521
537
|
# Definition: def names
|
@@ -525,12 +541,12 @@ LinuxStat::Process.names()
|
|
525
541
|
# File: process.rb | Line: 97
|
526
542
|
# Definition: def running
|
527
543
|
LinuxStat::Process.running()
|
528
|
-
=> [
|
544
|
+
=> [20187, 20447]
|
529
545
|
|
530
546
|
# File: process.rb | Line: 58
|
531
547
|
# Definition: def sleeping
|
532
548
|
LinuxStat::Process.sleeping()
|
533
|
-
=> [1, 2, 10, 11, 13, 14, 15, 16, 17, 18, 19, 20, 21, 24, 25, 26, 27, 28, 31, 32, 33, 34, 35, 38, 40, 41, 42, 46, 47, 48, 50, 51, 52, 112, 114, 115,
|
549
|
+
=> [1, 2, 10, 11, 13, 14, 15, 16, 17, 18, 19, 20, 21, 24, 25, 26, 27, 28, 31, 32, 33, 34, 35, 38, 40, 41, 42, 46, 47, 48, 50, 51, 52, 112, 114, 115, 169, 171, 189, 218, 235, 308, 309, 310, 311, 326, 356, 357, 358, 359, 375, 378, 381, 408, 426, 428, 429,...
|
534
550
|
|
535
551
|
# File: process.rb | Line: 37
|
536
552
|
# Definition: def types
|
@@ -564,7 +580,7 @@ LinuxStat::ProcessInfo.count_cpu(pid)
|
|
564
580
|
# File: process_info.rb | Line: 247
|
565
581
|
# Definition: def cpu_stat(pid: $$, sleep: ticks_to_ms_t5)
|
566
582
|
LinuxStat::ProcessInfo.cpu_stat(pid:, sleep:)
|
567
|
-
=> {:cpu_usage=>0.0, :threads=>1, :last_executed_cpu=>
|
583
|
+
=> {:cpu_usage=>0.0, :threads=>1, :last_executed_cpu=>2}
|
568
584
|
|
569
585
|
# File: process_info.rb | Line: 307
|
570
586
|
# Definition: def cpu_usage(pid: $$, sleep: ticks_to_ms_t5)
|
@@ -579,17 +595,17 @@ LinuxStat::ProcessInfo.gid(pid)
|
|
579
595
|
# File: process_info.rb | Line: 433
|
580
596
|
# Definition: def last_executed_cpu(pid = $$)
|
581
597
|
LinuxStat::ProcessInfo.last_executed_cpu(pid)
|
582
|
-
=>
|
598
|
+
=> 2
|
583
599
|
|
584
600
|
# File: process_info.rb | Line: 114
|
585
601
|
# Definition: def mem_stat(pid = $$)
|
586
602
|
LinuxStat::ProcessInfo.mem_stat(pid)
|
587
|
-
=> {:memory=>
|
603
|
+
=> {:memory=>12484.608, :virtual_memory=>84090.88, :resident_memory=>18665.472}
|
588
604
|
|
589
605
|
# File: process_info.rb | Line: 147
|
590
606
|
# Definition: def memory(pid = $$)
|
591
607
|
LinuxStat::ProcessInfo.memory(pid)
|
592
|
-
=>
|
608
|
+
=> 12484.608
|
593
609
|
|
594
610
|
# File: process_info.rb | Line: 607
|
595
611
|
# Definition: def nice(pid = $$)
|
@@ -609,7 +625,7 @@ LinuxStat::ProcessInfo.owner(pid)
|
|
609
625
|
# File: process_info.rb | Line: 197
|
610
626
|
# Definition: def resident_memory(pid = $$)
|
611
627
|
LinuxStat::ProcessInfo.resident_memory(pid)
|
612
|
-
=>
|
628
|
+
=> 18665.472
|
613
629
|
|
614
630
|
# File: process_info.rb | Line: 563
|
615
631
|
# Definition: def running_time(pid = $$)
|
@@ -619,12 +635,12 @@ LinuxStat::ProcessInfo.running_time(pid)
|
|
619
635
|
# File: process_info.rb | Line: 544
|
620
636
|
# Definition: def start_time(pid = $$)
|
621
637
|
LinuxStat::ProcessInfo.start_time(pid)
|
622
|
-
=> 2020-12-
|
638
|
+
=> 2020-12-23 00:57:33 +0530
|
623
639
|
|
624
640
|
# File: process_info.rb | Line: 513
|
625
641
|
# Definition: def start_time_epoch(pid = $$)
|
626
642
|
LinuxStat::ProcessInfo.start_time_epoch(pid)
|
627
|
-
=>
|
643
|
+
=> 1608665253
|
628
644
|
|
629
645
|
# File: process_info.rb | Line: 592
|
630
646
|
# Definition: def state(pid = $$)
|
@@ -644,7 +660,7 @@ LinuxStat::ProcessInfo.threads(pid)
|
|
644
660
|
# File: process_info.rb | Line: 23
|
645
661
|
# Definition: def total_io(pid = $$)
|
646
662
|
LinuxStat::ProcessInfo.total_io(pid)
|
647
|
-
=> {:read_bytes=>
|
663
|
+
=> {:read_bytes=>4096, :write_bytes=>0}
|
648
664
|
|
649
665
|
# File: process_info.rb | Line: 446
|
650
666
|
# Definition: def uid(pid = $$)
|
@@ -654,7 +670,7 @@ LinuxStat::ProcessInfo.uid(pid)
|
|
654
670
|
# File: process_info.rb | Line: 172
|
655
671
|
# Definition: def virtual_memory(pid = $$)
|
656
672
|
LinuxStat::ProcessInfo.virtual_memory(pid)
|
657
|
-
=>
|
673
|
+
=> 84090.88
|
658
674
|
|
659
675
|
```
|
660
676
|
|
@@ -668,27 +684,27 @@ LinuxStat::Swap.any?()
|
|
668
684
|
# File: swap.rb | Line: 68
|
669
685
|
# Definition: def available
|
670
686
|
LinuxStat::Swap.available()
|
671
|
-
=>
|
687
|
+
=> 4058184
|
672
688
|
|
673
689
|
# File: swap.rb | Line: 8
|
674
690
|
# Definition: def list
|
675
691
|
LinuxStat::Swap.list()
|
676
|
-
=> {"/dev/zram0"=>[:partition, 4194300,
|
692
|
+
=> {"/dev/zram0"=>[:partition, 4194300, 136116, -2]}
|
677
693
|
|
678
694
|
# File: swap.rb | Line: 103
|
679
695
|
# Definition: def percent_available
|
680
696
|
LinuxStat::Swap.percent_available()
|
681
|
-
=>
|
697
|
+
=> 96.75
|
682
698
|
|
683
699
|
# File: swap.rb | Line: 89
|
684
700
|
# Definition: def percent_used
|
685
701
|
LinuxStat::Swap.percent_used()
|
686
|
-
=>
|
702
|
+
=> 3.25
|
687
703
|
|
688
704
|
# File: swap.rb | Line: 32
|
689
705
|
# Definition: def stat
|
690
706
|
LinuxStat::Swap.stat()
|
691
|
-
=> {:total=>4194300, :used=>
|
707
|
+
=> {:total=>4194300, :used=>136116, :available=>4058184, :percent_used=>3.25, :percent_available=>96.75}
|
692
708
|
|
693
709
|
# File: swap.rb | Line: 57
|
694
710
|
# Definition: def total
|
@@ -698,14 +714,14 @@ LinuxStat::Swap.total()
|
|
698
714
|
# File: swap.rb | Line: 80
|
699
715
|
# Definition: def used
|
700
716
|
LinuxStat::Swap.used()
|
701
|
-
=>
|
717
|
+
=> 136116
|
702
718
|
|
703
719
|
```
|
704
720
|
|
705
721
|
### LinuxStat::Sysconf
|
706
722
|
```
|
707
723
|
LinuxStat::Sysconf.child_max()
|
708
|
-
=>
|
724
|
+
=> nil
|
709
725
|
|
710
726
|
LinuxStat::Sysconf.expr_nest_max()
|
711
727
|
=> 32
|
@@ -741,7 +757,7 @@ LinuxStat::Sysconf.pagesize()
|
|
741
757
|
=> 4096
|
742
758
|
|
743
759
|
LinuxStat::Sysconf.posix_version()
|
744
|
-
=>
|
760
|
+
=> 4201
|
745
761
|
|
746
762
|
LinuxStat::Sysconf.processor_configured()
|
747
763
|
=> 4
|
@@ -1009,7 +1025,12 @@ By using `LinuxStat::CPU.online.count` you count the actual online CPU on your s
|
|
1009
1025
|
|
1010
1026
|
Any n number of CPU can get hotplugged in and out, and this will report that correctly.
|
1011
1027
|
|
1012
|
-
It just gets the info from /sys/devices/system/cpu/online
|
1028
|
+
It just gets the info from /proc/stat; but if it fails it will read /sys/devices/system/cpu/online
|
1029
|
+
and parse the output to get an array.
|
1030
|
+
|
1031
|
+
4. The `LinuxStat::CPU.count_online`
|
1032
|
+
It's a more robust method that counts the online CPU. It shouldn't fail in most if not all cases!
|
1033
|
+
But if it fails for some really spooky reasons, it will return nil.
|
1013
1034
|
|
1014
1035
|
4. The `LinuxStat::CPU.offline()`:
|
1015
1036
|
|
data/ext/sysconf/sysconf.c
CHANGED
@@ -12,55 +12,94 @@
|
|
12
12
|
#endif
|
13
13
|
|
14
14
|
static VALUE getTick(VALUE obj) {
|
15
|
-
|
15
|
+
short int val = sysconf(_SC_CLK_TCK) ;
|
16
|
+
if (val < 0) return Qnil ;
|
17
|
+
|
18
|
+
return INT2FIX(val) ;
|
16
19
|
}
|
17
20
|
|
18
21
|
static VALUE getChildMax(VALUE obj) {
|
19
|
-
|
22
|
+
short int val = sysconf(_SC_CHILD_MAX) ;
|
23
|
+
if (val < 0) return Qnil ;
|
24
|
+
|
25
|
+
return INT2FIX(val) ;
|
20
26
|
}
|
21
27
|
|
22
28
|
static VALUE getHostnameMax(VALUE obj) {
|
23
|
-
|
29
|
+
short int val = sysconf(_SC_HOST_NAME_MAX) ;
|
30
|
+
if (val < 0) return Qnil ;
|
31
|
+
|
32
|
+
return INT2FIX(val) ;
|
24
33
|
}
|
25
34
|
|
26
35
|
static VALUE getLoginNameMax(VALUE obj) {
|
27
|
-
|
36
|
+
short int val = sysconf(_SC_LOGIN_NAME_MAX) ;
|
37
|
+
if (val < 0) return Qnil ;
|
38
|
+
|
39
|
+
return INT2FIX(val) ;
|
28
40
|
}
|
29
41
|
|
30
42
|
static VALUE getOpenMax(VALUE obj) {
|
31
|
-
|
43
|
+
short int val = sysconf(_SC_OPEN_MAX) ;
|
44
|
+
if (val < 0) return Qnil ;
|
45
|
+
|
46
|
+
return INT2FIX(val) ;
|
32
47
|
}
|
33
48
|
|
34
49
|
static VALUE getPageSize(VALUE obj) {
|
35
|
-
|
50
|
+
short int val = sysconf(_SC_PAGESIZE) ;
|
51
|
+
if (val < 0) return Qnil ;
|
52
|
+
|
53
|
+
return INT2FIX(val) ;
|
36
54
|
}
|
37
55
|
|
38
56
|
static VALUE getStreamMax(VALUE obj) {
|
39
|
-
|
57
|
+
short int val = sysconf(_SC_STREAM_MAX) ;
|
58
|
+
if (val < 0) return Qnil ;
|
59
|
+
|
60
|
+
return INT2FIX(val) ;
|
40
61
|
}
|
41
62
|
|
42
63
|
static VALUE getTTYNameMax(VALUE obj) {
|
43
|
-
|
64
|
+
short int val = sysconf(_SC_TTY_NAME_MAX) ;
|
65
|
+
if (val < 0) return Qnil ;
|
66
|
+
|
67
|
+
return INT2FIX(val) ;
|
44
68
|
}
|
45
69
|
|
46
70
|
static VALUE getPosixVersion(VALUE obj) {
|
47
|
-
|
71
|
+
short int val = sysconf(_SC_VERSION) ;
|
72
|
+
if (val < 0) return Qnil ;
|
73
|
+
|
74
|
+
return INT2FIX(val) ;
|
48
75
|
}
|
49
76
|
|
50
77
|
static VALUE getLineMax(VALUE obj) {
|
51
|
-
|
78
|
+
short int val = sysconf(_SC_LINE_MAX) ;
|
79
|
+
if (val < 0) return Qnil ;
|
80
|
+
|
81
|
+
return INT2FIX(val) ;
|
52
82
|
}
|
53
83
|
|
54
84
|
static VALUE getExprNestMax(VALUE obj) {
|
55
|
-
|
85
|
+
short int val = sysconf(_SC_EXPR_NEST_MAX) ;
|
86
|
+
if (val < 0) return Qnil ;
|
87
|
+
|
88
|
+
return INT2FIX(val) ;
|
56
89
|
}
|
57
90
|
|
58
91
|
static VALUE getProcessorConfigured(VALUE obj) {
|
59
|
-
|
92
|
+
short int val = sysconf(_SC_NPROCESSORS_CONF) ;
|
93
|
+
if (val < 0) return Qnil ;
|
94
|
+
|
95
|
+
return INT2FIX(val) ;
|
60
96
|
}
|
61
97
|
|
62
98
|
static VALUE getProcessorOnline(VALUE obj) {
|
63
|
-
|
99
|
+
short int val = sysconf(_SC_NPROCESSORS_ONLN) ;
|
100
|
+
if (val < 0) return Qnil ;
|
101
|
+
|
102
|
+
return INT2FIX(val) ;
|
64
103
|
}
|
65
104
|
|
66
105
|
static VALUE getUser(VALUE obj) {
|
data/lib/linux_stat/battery.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
module LinuxStat
|
2
2
|
module Battery
|
3
|
-
PATH = "/sys/class/power_supply/BAT0"
|
3
|
+
PATH = "/sys/class/power_supply/BAT0".freeze
|
4
4
|
|
5
5
|
class << self
|
6
6
|
##
|
@@ -34,8 +34,10 @@ module LinuxStat
|
|
34
34
|
#
|
35
35
|
# If the battery is not present or the information isn't available it will return an empty String.
|
36
36
|
def model
|
37
|
-
|
38
|
-
|
37
|
+
@@mn_file = File.join(PATH, 'model_name')
|
38
|
+
return ''.freeze unless File.readable?(@@mn_file)
|
39
|
+
|
40
|
+
IO.read(@@mn_file).tap(&:strip!)
|
39
41
|
end
|
40
42
|
|
41
43
|
##
|
@@ -43,8 +45,9 @@ module LinuxStat
|
|
43
45
|
#
|
44
46
|
# If the battery is not present or the information is not available, it will return an empty String.
|
45
47
|
def manufacturer
|
48
|
+
@@manufacturer_file ||= File.join(PATH, 'manufacturer')
|
46
49
|
return ''.freeze unless manufacturer_readable?
|
47
|
-
IO.read(
|
50
|
+
IO.read(@@manufacturer_file).tap(&:strip!)
|
48
51
|
end
|
49
52
|
|
50
53
|
##
|
@@ -52,8 +55,9 @@ module LinuxStat
|
|
52
55
|
#
|
53
56
|
# If the battery is not present or the information is not available, it will return an empty String.
|
54
57
|
def technology
|
58
|
+
@@technology_file ||= File.join(PATH, 'technology')
|
55
59
|
return ''.freeze unless tech_readable?
|
56
|
-
IO.read(
|
60
|
+
IO.read(@@technology_file).tap(&:strip!)
|
57
61
|
end
|
58
62
|
|
59
63
|
##
|
@@ -62,8 +66,9 @@ module LinuxStat
|
|
62
66
|
#
|
63
67
|
# If the battery is not present or the information is not available, it will return an empty frozen String.
|
64
68
|
def status
|
69
|
+
@@status_file ||= File.join(PATH, 'status'.freeze)
|
65
70
|
return ''.freeze unless status_readable?
|
66
|
-
IO.read(
|
71
|
+
IO.read(@@status_file).tap(&:strip!)
|
67
72
|
end
|
68
73
|
|
69
74
|
##
|
@@ -81,7 +86,7 @@ module LinuxStat
|
|
81
86
|
# If the battery is not present or the information is not available, it will return nil.
|
82
87
|
def discharging?
|
83
88
|
return nil if status.empty?
|
84
|
-
status.downcase == 'discharging'
|
89
|
+
status.downcase == 'discharging'.freeze
|
85
90
|
end
|
86
91
|
|
87
92
|
##
|
@@ -90,7 +95,7 @@ module LinuxStat
|
|
90
95
|
# If the battery is not present or the information is not available, it will return nil.
|
91
96
|
def full?
|
92
97
|
return nil if status.empty?
|
93
|
-
status.downcase == 'full'
|
98
|
+
status.downcase == 'full'.freeze
|
94
99
|
end
|
95
100
|
|
96
101
|
##
|
@@ -111,6 +116,47 @@ module LinuxStat
|
|
111
116
|
percentage > 100 ? 100.0 : percentage < 0 ? 0.0 : percentage
|
112
117
|
end
|
113
118
|
|
119
|
+
##
|
120
|
+
# Returns the charge full design WH of the battery as Integer
|
121
|
+
# However if the info isn't available or there's no BAT0 in the system, this will return nil
|
122
|
+
def charge_full_design_wh
|
123
|
+
# voltage min design
|
124
|
+
@@vmd_f ||= File.join(PATH, 'voltage_min_design'.freeze)
|
125
|
+
v_m_d = File.readable?(@@vmd_f) ? IO.read(@@vmd_f).to_i : nil
|
126
|
+
|
127
|
+
# charge full design
|
128
|
+
@@cfd_f ||= File.join(PATH, 'charge_full_design'.freeze)
|
129
|
+
c_f_d = File.readable?(@@cfd_f) ? IO.read(@@cfd_f).to_i : nil
|
130
|
+
|
131
|
+
if v_m_d && c_f_d
|
132
|
+
v_m_d.fdiv(1_000_000).*(c_f_d.fdiv(1_000_000)).round(2)
|
133
|
+
else
|
134
|
+
nil
|
135
|
+
end
|
136
|
+
end
|
137
|
+
|
138
|
+
##
|
139
|
+
# Returns the charge full WH of the battery as Integer
|
140
|
+
# However if the info isn't available or there's no BAT0 in the system, this will return nil
|
141
|
+
def charge_full_wh
|
142
|
+
# voltage min design
|
143
|
+
@@vmd_f ||= File.join(PATH, 'voltage_min_design'.freeze)
|
144
|
+
v_m_d = File.readable?(@@vmd_f) ? IO.read(@@vmd_f).to_i : nil
|
145
|
+
|
146
|
+
# charge full
|
147
|
+
@@cf_f ||= File.join(PATH, 'charge_full'.freeze)
|
148
|
+
c_f = File.readable?(@@cf_f) ? IO.read(@@cf_f).to_i : nil
|
149
|
+
|
150
|
+
if v_m_d && c_f
|
151
|
+
v_m_d.fdiv(1_000_000).*(c_f.fdiv(1_000_000)).round(2)
|
152
|
+
else
|
153
|
+
nil
|
154
|
+
end
|
155
|
+
end
|
156
|
+
|
157
|
+
##
|
158
|
+
# Returns the voltage of the battery as Integer
|
159
|
+
# However if the info isn't available or there's no BAT0 in the system, this will return nil
|
114
160
|
def voltage_now
|
115
161
|
@@voltage_file ||= File.join(PATH, 'voltage_now'.freeze)
|
116
162
|
@@voltage_readable ||= File.readable?(@@voltage_file)
|
@@ -119,11 +165,120 @@ module LinuxStat
|
|
119
165
|
IO.read(@@voltage_file, 16).to_f.fdiv(1000000)
|
120
166
|
end
|
121
167
|
|
122
|
-
|
123
|
-
|
124
|
-
|
168
|
+
##
|
169
|
+
# A linux system can have multiple batteries. This method attempts to
|
170
|
+
# find all of them and return a Hash based on the availibility of the
|
171
|
+
# information.
|
172
|
+
#
|
173
|
+
# This method is somewhat slower than other Battery module singleton methods.
|
174
|
+
# Because it does various checks and opens various files from /sys/
|
175
|
+
#
|
176
|
+
# For example, a sample output can be like this (taken on a test system):
|
177
|
+
#
|
178
|
+
# LinuxStat::Battery.devices_stat
|
179
|
+
# => {:AC=>{:type=>"Mains", :online=>1}, :BAT0=>{:model=>"DELL CYMGM77", :manufacturer=>"Samsung SDI", :type=>"Battery", :status=>"Full", :capacity=>100, :voltage_min_design=>11.4, :charge_full_design=>3.684, :charge_full_design_wh=>42.0, :voltage_now=>12.558, :charge_now=>2.087, :charge_now_wh=>26.21, :charge_full_wh=>23.79, :charge_percentage=>100.0}, :hidpp_battery_0=>{:model=>"Wireless Keyboard", :manufacturer=>"Logitech", :type=>"Battery", :status=>"Discharging", :online=>1}}
|
180
|
+
#
|
181
|
+
# If you need info about lots of batteries, use this method.
|
182
|
+
# If the informations are not available, it will return empty Hash for each devices.
|
183
|
+
# If the system has no batteries, it will return an empty Hash.
|
184
|
+
def devices_stat
|
185
|
+
h = {}
|
186
|
+
Dir["/sys/class/power_supply/*/".freeze].tap(&:sort!).each do |x|
|
187
|
+
# model name
|
188
|
+
mn_file = File.join(x, 'model_name'.freeze).freeze
|
189
|
+
model_name = File.readable?(mn_file) ? IO.read(mn_file).strip : nil
|
190
|
+
|
191
|
+
# manufacturer
|
192
|
+
m_f = File.join(x, 'manufacturer'.freeze).freeze
|
193
|
+
manufacturer = File.readable?(m_f) ? IO.read(m_f).strip : nil
|
194
|
+
|
195
|
+
# type
|
196
|
+
t_f = File.join(x, 'type'.freeze).freeze
|
197
|
+
type = File.readable?(t_f) ? IO.read(t_f).strip : nil
|
198
|
+
|
199
|
+
# capacity
|
200
|
+
c_file = File.join(x, 'capacity'.freeze).freeze
|
201
|
+
capacity = File.readable?(c_file) ? IO.read(c_file).to_i : nil
|
202
|
+
|
203
|
+
# voltage now
|
204
|
+
vn_f = File.join(x, 'voltage_now'.freeze).freeze
|
205
|
+
voltage_now = File.readable?(vn_f) ? IO.read(vn_f).to_i.fdiv(1_000_000) : nil
|
206
|
+
|
207
|
+
# charge now
|
208
|
+
cn_f = File.join(x, 'charge_now'.freeze).freeze
|
209
|
+
charge_now = File.readable?(cn_f) ? IO.read(cn_f).to_i.fdiv(1_000_000) : nil
|
210
|
+
|
211
|
+
# voltage min design
|
212
|
+
vmd_f = File.join(x, 'voltage_min_design'.freeze).freeze
|
213
|
+
v_m_d = File.readable?(vmd_f) ? IO.read(vmd_f).to_i.fdiv(1_000_000) : nil
|
214
|
+
|
215
|
+
# charge full design
|
216
|
+
cfd_f = File.join(x, 'charge_full_design'.freeze).freeze
|
217
|
+
c_f_d = File.readable?(cfd_f) ? IO.read(cfd_f).to_i.fdiv(1_000_000) : nil
|
218
|
+
|
219
|
+
# charge full
|
220
|
+
cf_f = File.join(x, 'charge_full'.freeze).freeze
|
221
|
+
charge_full = File.readable?(cf_f) ? IO.read(cf_f).to_i.fdiv(1_000_000) : nil
|
222
|
+
|
223
|
+
# status
|
224
|
+
s_f = File.join(x, 'status'.freeze).freeze
|
225
|
+
status = File.readable?(s_f) ? IO.read(s_f).strip : nil
|
226
|
+
|
227
|
+
# online
|
228
|
+
o_f = File.join(x, 'online'.freeze).freeze
|
229
|
+
online = File.readable?(o_f) ? IO.read(o_f).to_i : nil
|
230
|
+
|
231
|
+
charge_percentage = if charge_now && charge_full
|
232
|
+
charge_now.*(100).fdiv(charge_full).round(2)
|
233
|
+
else
|
234
|
+
nil
|
235
|
+
end
|
236
|
+
|
237
|
+
# full_charge_design (WH)
|
238
|
+
c_f_d_wh = if c_f_d && v_m_d
|
239
|
+
v_m_d.*(c_f_d).round(2)
|
240
|
+
else
|
241
|
+
nil
|
242
|
+
end
|
243
|
+
|
244
|
+
c_n_wh = if voltage_now && charge_now
|
245
|
+
voltage_now.*(charge_now).round(2)
|
246
|
+
else
|
247
|
+
nil
|
248
|
+
end
|
249
|
+
|
250
|
+
c_f_wh = if v_m_d && charge_full
|
251
|
+
v_m_d.*(charge_full).round(2)
|
252
|
+
else
|
253
|
+
nil
|
254
|
+
end
|
255
|
+
|
256
|
+
ret = {}
|
257
|
+
ret[:model] = model_name if model_name
|
258
|
+
ret[:manufacturer] = manufacturer if manufacturer
|
259
|
+
ret[:type] = type if type
|
260
|
+
|
261
|
+
ret[:status] = status if status
|
262
|
+
ret[:online] = online if online
|
263
|
+
ret[:capacity] = capacity if capacity
|
264
|
+
|
265
|
+
ret[:voltage_min_design] = v_m_d if v_m_d
|
266
|
+
ret[:charge_full_design] = c_f_d if c_f_d
|
267
|
+
ret[:charge_full_design_wh] = c_f_d_wh if c_f_d_wh
|
268
|
+
|
269
|
+
ret[:voltage_now] = voltage_now if voltage_now
|
270
|
+
ret[:charge_now] = charge_now if charge_now
|
271
|
+
|
272
|
+
ret[:charge_now_wh] = c_n_wh if c_n_wh
|
273
|
+
ret[:charge_full_wh] = c_f_wh if c_f_wh
|
274
|
+
ret[:charge_percentage] = charge_percentage if charge_percentage
|
275
|
+
|
276
|
+
h.merge!(File.split(x)[-1].to_sym => ret)
|
277
|
+
end
|
278
|
+
h
|
125
279
|
end
|
126
280
|
|
281
|
+
private
|
127
282
|
def manufacturer_readable?
|
128
283
|
@@manufacturer_readable ||= File.readable?(File.join(PATH, 'manufacturer'))
|
129
284
|
end
|
data/lib/linux_stat/cpu.rb
CHANGED
@@ -63,9 +63,9 @@ module LinuxStat
|
|
63
63
|
def total_usage(sleep = ticks_to_ms_t5)
|
64
64
|
return nil unless stat?
|
65
65
|
|
66
|
-
data = IO.foreach('/proc/stat').first.split.tap(&:shift).map!(&:to_f)
|
66
|
+
data = IO.foreach('/proc/stat'.freeze).first.split.tap(&:shift).map!(&:to_f)
|
67
67
|
sleep(sleep)
|
68
|
-
data2 = IO.foreach('/proc/stat').first.split.tap(&:shift).map!(&:to_f)
|
68
|
+
data2 = IO.foreach('/proc/stat'.freeze).first.split.tap(&:shift).map!(&:to_f)
|
69
69
|
|
70
70
|
user, nice, sys, idle, iowait, irq, softirq, steal = *data
|
71
71
|
user2, nice2, sys2, idle2, iowait2, irq2, softirq2, steal2 = *data2
|
@@ -82,7 +82,7 @@ module LinuxStat
|
|
82
82
|
#
|
83
83
|
# It returns an Integer.
|
84
84
|
#
|
85
|
-
# If the information isn't available, it will return
|
85
|
+
# If the information isn't available, it will return nil.
|
86
86
|
def count
|
87
87
|
@@cpu_count ||= LinuxStat::Sysconf.processor_configured
|
88
88
|
end
|
@@ -90,21 +90,65 @@ module LinuxStat
|
|
90
90
|
##
|
91
91
|
# Returns the total number of CPU online in the sysetm.
|
92
92
|
#
|
93
|
+
# It first reads /proc/stat, if that fails, it will
|
94
|
+
# read /sys/devices/system/cpu/online,
|
95
|
+
# if that fails it will open /proc/cpuinfo.
|
96
|
+
# If neither of the procedures work, it will get the
|
97
|
+
# LinuxStat::Sysconf.processor_online
|
98
|
+
#
|
93
99
|
# It opens /sys/devices/system/cpu/offline and
|
94
100
|
# performs various job to get one Ruby array.
|
95
101
|
#
|
96
102
|
# If the information isn't available, it will return an empty Array.
|
103
|
+
def count_online
|
104
|
+
@@cpuinfo_file ||= '/proc/cpuinfo'.freeze
|
105
|
+
@@cpuinfo_readable ||= File.readable?(@@cpuinfo_file)
|
106
|
+
|
107
|
+
@@stat_file ||= '/proc/stat'.freeze
|
108
|
+
|
109
|
+
# Not much slow, not blazing fast, somewhat reliable
|
110
|
+
get_online = online
|
111
|
+
|
112
|
+
if !get_online.empty?
|
113
|
+
get_online.length
|
114
|
+
elsif @@cpuinfo_readable
|
115
|
+
# Way slower but reliable!
|
116
|
+
IO.readlines(@@cpuinfo_file).count { |x| x.strip[/\Aprocessor.*\d*\z/] }
|
117
|
+
else
|
118
|
+
# Way faster but absolutely unrealiable!
|
119
|
+
LinuxStat::Sysconf.processor_online
|
120
|
+
end
|
121
|
+
end
|
122
|
+
|
123
|
+
##
|
124
|
+
# Returns the total number of CPU online in the sysetm.
|
125
|
+
#
|
126
|
+
# It will read /proc/stat to get the info.
|
127
|
+
#
|
128
|
+
# If the info isn't available, it reads /sys/devices/system/cpu/onfline and
|
129
|
+
# performs various job to get one Ruby array.
|
130
|
+
#
|
131
|
+
# If the information isn't available, it will return an empty Array.
|
97
132
|
def online
|
98
133
|
@@online_file ||= '/sys/devices/system/cpu/online'.freeze
|
99
134
|
@@online_readable ||= File.readable?(@@online_file)
|
100
|
-
|
135
|
+
|
136
|
+
@@stat_file ||= '/proc/stat'.freeze
|
101
137
|
|
102
138
|
ret = []
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
139
|
+
|
140
|
+
if stat?
|
141
|
+
IO.readlines(@@stat_file).map { |x|
|
142
|
+
v = x.strip[/\Acpu\d*/] &.[](/\d/)
|
143
|
+
ret << v.to_i if v
|
144
|
+
}
|
145
|
+
elsif @@online_readable
|
146
|
+
IO.read(@@online_file).split(?,.freeze).each { |x|
|
147
|
+
x.strip!
|
148
|
+
c = x.split(?-.freeze).map(&:to_i)
|
149
|
+
ret.concat(c.length == 2 ? Range.new(*c).to_a : c)
|
150
|
+
}
|
151
|
+
end
|
108
152
|
|
109
153
|
ret
|
110
154
|
end
|
@@ -269,7 +313,8 @@ module LinuxStat
|
|
269
313
|
# ticks to ms times 5
|
270
314
|
# If the ticks is 100, it will return 0.05
|
271
315
|
def ticks_to_ms_t5
|
272
|
-
@@
|
316
|
+
@@sc_clk_tck ||= LinuxStat::Sysconf.sc_clk_tck.to_i
|
317
|
+
@@ms_t5 ||= 1.0 / (@@sc_clk_tck < 1 ? 100 : @@sc_clk_tck) * 5
|
273
318
|
end
|
274
319
|
|
275
320
|
def cpus
|
@@ -645,7 +645,8 @@ module LinuxStat
|
|
645
645
|
|
646
646
|
private
|
647
647
|
def get_ticks
|
648
|
-
@@
|
648
|
+
@@sc_clk_tck ||= LinuxStat::Sysconf.sc_clk_tck
|
649
|
+
@@ticks ||= @@sc_clk_tck < 1 ? 100 : @@sc_clk_tck
|
649
650
|
end
|
650
651
|
|
651
652
|
# Just to avoid multiple calculations!...
|
@@ -656,7 +657,7 @@ module LinuxStat
|
|
656
657
|
end
|
657
658
|
|
658
659
|
def pagesize
|
659
|
-
@@pagesize ||= LinuxStat::Sysconf.pagesize
|
660
|
+
@@pagesize ||= LinuxStat::Sysconf.pagesize.to_i
|
660
661
|
end
|
661
662
|
|
662
663
|
def cpu_count
|
data/lib/linux_stat/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: linux_stat
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.9.
|
4
|
+
version: 0.9.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Sourav Goswami
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-12-
|
11
|
+
date: 2020-12-22 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: Linux only, efficient linux system utilization reporting and system monitoring
|
14
14
|
gem
|