linux_stat 1.0.3 → 1.1.0
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 +108 -84
- data/lib/linux_stat.rb +1 -0
- data/lib/linux_stat/pci.rb +311 -0
- data/lib/linux_stat/usb.rb +11 -9
- data/lib/linux_stat/version.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 86307b8ccfb101dbd829b5fdf36d6c9bf4eaffb555e1387311f34f10d5cb748e
|
4
|
+
data.tar.gz: 5576fa510cffef8567df558cd096afe91ccb5afa536532f5625f04be19279ae6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c6960ddec53d610b61e44de4c7432f4e05fb00c7588629924fd34d17d711357c00867bd80c48497082332507879c6b7ad5472f0b66f188fab14d34d0d491d579
|
7
|
+
data.tar.gz: 1f31b0c48520ec826bc9b74fb48e5d752fb61aedab841911c2de92e9027861226ebafb03e210fea67667b5d1ab8b68a271f7859fe2ae2acd25b5f50efc9e2c7d
|
data/README.md
CHANGED
@@ -153,7 +153,7 @@ LinuxStat::Battery.technology()
|
|
153
153
|
# File: battery.rb | Line: 160
|
154
154
|
# Definition: def voltage_now
|
155
155
|
LinuxStat::Battery.voltage_now()
|
156
|
-
=> 12.
|
156
|
+
=> 12.541
|
157
157
|
|
158
158
|
```
|
159
159
|
|
@@ -177,7 +177,7 @@ LinuxStat::CPU.count_online()
|
|
177
177
|
# File: cpu.rb | Line: 197
|
178
178
|
# Definition: def cur_freq
|
179
179
|
LinuxStat::CPU.cur_freq()
|
180
|
-
=> {"cpu0"=>
|
180
|
+
=> {"cpu0"=>2000006, "cpu1"=>2000050, "cpu2"=>2000024, "cpu3"=>2000195}
|
181
181
|
|
182
182
|
# File: cpu.rb | Line: 265
|
183
183
|
# Definition: def governor
|
@@ -212,29 +212,29 @@ LinuxStat::CPU.online()
|
|
212
212
|
# File: cpu.rb | Line: 23
|
213
213
|
# Definition: def stat(sleep = ticks_to_ms_t5)
|
214
214
|
LinuxStat::CPU.stat(sleep)
|
215
|
-
=> {0=>
|
215
|
+
=> {0=>9.52, 1=>0.0, 2=>0.0, 3=>0.0, 4=>0.0}
|
216
216
|
|
217
217
|
# File: cpu.rb | Line: 63
|
218
218
|
# Definition: def total_usage(sleep = ticks_to_ms_t5)
|
219
219
|
LinuxStat::CPU.total_usage(sleep)
|
220
|
-
=>
|
220
|
+
=> 0.0
|
221
221
|
|
222
222
|
# File: cpu.rb | Line: 63
|
223
223
|
# Definition: def total_usage(sleep = ticks_to_ms_t5)
|
224
224
|
LinuxStat::CPU.usage(sleep)
|
225
|
-
=>
|
225
|
+
=> 14.29
|
226
226
|
|
227
227
|
# File: cpu.rb | Line: 23
|
228
228
|
# Definition: def stat(sleep = ticks_to_ms_t5)
|
229
229
|
LinuxStat::CPU.usages(sleep)
|
230
|
-
=> {0=>5.
|
230
|
+
=> {0=>5.0, 1=>0.0, 2=>20.0, 3=>20.0, 4=>16.67}
|
231
231
|
|
232
232
|
```
|
233
233
|
|
234
234
|
### LinuxStat::FS
|
235
235
|
```
|
236
236
|
LinuxStat::FS.stat(arg = "/")
|
237
|
-
=> {:block_size=>4096, :fragment_size=>4096, :blocks=>29292283, :block_free=>
|
237
|
+
=> {:block_size=>4096, :fragment_size=>4096, :blocks=>29292283, :block_free=>10607830, :block_avail_unpriv=>10607830, :inodes=>58612160, :free_inodes=>56826206, :filesystem_id=>2050, :mount_flags=>1024, :max_filename_length=>255}
|
238
238
|
|
239
239
|
```
|
240
240
|
|
@@ -243,22 +243,22 @@ LinuxStat::FS.stat(arg = "/")
|
|
243
243
|
# File: filesystem.rb | Line: 92
|
244
244
|
# Definition: def available(fs = ?..freeze)
|
245
245
|
LinuxStat::Filesystem.available(fs)
|
246
|
-
=>
|
246
|
+
=> 43449671680
|
247
247
|
|
248
248
|
# File: filesystem.rb | Line: 58
|
249
249
|
# Definition: def free(fs = ?..freeze)
|
250
250
|
LinuxStat::Filesystem.free(fs)
|
251
|
-
=>
|
251
|
+
=> 43449671680
|
252
252
|
|
253
253
|
# File: filesystem.rb | Line: 19
|
254
254
|
# Definition: def stat(fs = ?..freeze)
|
255
255
|
LinuxStat::Filesystem.stat(fs)
|
256
|
-
=> {:total=>119981191168, :free=>
|
256
|
+
=> {:total=>119981191168, :free=>43449671680, :used=>76531519488}
|
257
257
|
|
258
258
|
# File: filesystem.rb | Line: 108
|
259
259
|
# Definition: def stat_raw(fs = ?..freeze)
|
260
260
|
LinuxStat::Filesystem.stat_raw(fs)
|
261
|
-
=> {:block_size=>4096, :fragment_size=>4096, :blocks=>29292283, :block_free=>
|
261
|
+
=> {:block_size=>4096, :fragment_size=>4096, :blocks=>29292283, :block_free=>10607830, :block_avail_unpriv=>10607830, :inodes=>58612160, :free_inodes=>56826206, :filesystem_id=>2050, :mount_flags=>1024, :max_filename_length=>255}
|
262
262
|
|
263
263
|
# File: filesystem.rb | Line: 39
|
264
264
|
# Definition: def total(fs = ?..freeze)
|
@@ -268,7 +268,7 @@ LinuxStat::Filesystem.total(fs)
|
|
268
268
|
# File: filesystem.rb | Line: 73
|
269
269
|
# Definition: def used(fs = ?..freeze)
|
270
270
|
LinuxStat::Filesystem.used(fs)
|
271
|
-
=>
|
271
|
+
=> 76531519488
|
272
272
|
|
273
273
|
```
|
274
274
|
|
@@ -277,12 +277,12 @@ LinuxStat::Filesystem.used(fs)
|
|
277
277
|
# File: kernel.rb | Line: 86
|
278
278
|
# Definition: def build_date
|
279
279
|
LinuxStat::Kernel.build_date()
|
280
|
-
=> 2020-
|
280
|
+
=> 2020-12-24 18:28:16 +0000
|
281
281
|
|
282
282
|
# File: kernel.rb | Line: 140
|
283
283
|
# Definition: def build_date_string
|
284
284
|
LinuxStat::Kernel.build_date_string()
|
285
|
-
=> "
|
285
|
+
=> "24 Dec 2020 18:28:16 +0000"
|
286
286
|
|
287
287
|
# File: kernel.rb | Line: 21
|
288
288
|
# Definition: def build_user
|
@@ -307,12 +307,12 @@ LinuxStat::Kernel.compiler_version()
|
|
307
307
|
# File: kernel.rb | Line: 10
|
308
308
|
# Definition: def version
|
309
309
|
LinuxStat::Kernel.release()
|
310
|
-
=> "5.
|
310
|
+
=> "5.10.2-xanmod1-cacule-1-cacule"
|
311
311
|
|
312
312
|
# File: kernel.rb | Line: 169
|
313
313
|
# Definition: def string
|
314
314
|
LinuxStat::Kernel.string()
|
315
|
-
=> "Linux version 5.
|
315
|
+
=> "Linux version 5.10.2-xanmod1-cacule-1-cacule (souravgoswami@archlinux) (gcc (GCC) 10.2.0, GNU ld (GNU Binutils) 2.35.1) #1 SMP PREEMPT Thu, 24 Dec 2020 18:28:16 +0000"
|
316
316
|
|
317
317
|
# File: kernel.rb | Line: 179
|
318
318
|
# Definition: def ticks
|
@@ -322,7 +322,7 @@ LinuxStat::Kernel.ticks()
|
|
322
322
|
# File: kernel.rb | Line: 10
|
323
323
|
# Definition: def version
|
324
324
|
LinuxStat::Kernel.version()
|
325
|
-
=> "5.
|
325
|
+
=> "5.10.2-xanmod1-cacule-1-cacule"
|
326
326
|
|
327
327
|
```
|
328
328
|
|
@@ -331,32 +331,32 @@ LinuxStat::Kernel.version()
|
|
331
331
|
# File: memory.rb | Line: 50
|
332
332
|
# Definition: def available
|
333
333
|
LinuxStat::Memory.available()
|
334
|
-
=>
|
334
|
+
=> 1000240
|
335
335
|
|
336
336
|
# File: memory.rb | Line: 81
|
337
337
|
# Definition: def percent_available
|
338
338
|
LinuxStat::Memory.percent_available()
|
339
|
-
=>
|
339
|
+
=> 26.07
|
340
340
|
|
341
341
|
# File: memory.rb | Line: 70
|
342
342
|
# Definition: def percent_used
|
343
343
|
LinuxStat::Memory.percent_used()
|
344
|
-
=>
|
344
|
+
=> 73.93
|
345
345
|
|
346
346
|
# File: memory.rb | Line: 11
|
347
347
|
# Definition: def stat
|
348
348
|
LinuxStat::Memory.stat()
|
349
|
-
=> {:total=>
|
349
|
+
=> {:total=>3836036, :used=>2835796, :available=>1000240, :percent_used=>73.93, :percent_available=>26.07}
|
350
350
|
|
351
351
|
# File: memory.rb | Line: 40
|
352
352
|
# Definition: def total
|
353
353
|
LinuxStat::Memory.total()
|
354
|
-
=>
|
354
|
+
=> 3836036
|
355
355
|
|
356
356
|
# File: memory.rb | Line: 60
|
357
357
|
# Definition: def used
|
358
358
|
LinuxStat::Memory.used()
|
359
|
-
=>
|
359
|
+
=> 2835796
|
360
360
|
|
361
361
|
```
|
362
362
|
|
@@ -365,7 +365,7 @@ LinuxStat::Memory.used()
|
|
365
365
|
# File: mounts.rb | Line: 179
|
366
366
|
# Definition: def device_stat(dev = root)
|
367
367
|
LinuxStat::Mounts.device_stat(dev)
|
368
|
-
=> {:mountpoint=>"/", :total=>119981191168, :free=>
|
368
|
+
=> {:mountpoint=>"/", :total=>119981191168, :free=>43449671680, :available=>43449671680, :used=>76531519488, :percent_used=>63.79, :percent_free=>36.21, :percent_available=>36.21}
|
369
369
|
|
370
370
|
# File: mounts.rb | Line: 137
|
371
371
|
# Definition: def devices_stat
|
@@ -375,17 +375,17 @@ LinuxStat::Mounts.devices_stat()
|
|
375
375
|
# File: mounts.rb | Line: 11
|
376
376
|
# Definition: def list
|
377
377
|
LinuxStat::Mounts.list()
|
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=
|
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=1909256k,nr_inodes=477314,mode=755,inode64 0 0", "run /run tmpfs rw,nosuid,nodev,relatime,mode=755...
|
379
379
|
|
380
380
|
# File: mounts.rb | Line: 20
|
381
381
|
# Definition: def list_devices
|
382
382
|
LinuxStat::Mounts.list_devices()
|
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", "
|
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", "mqu...
|
384
384
|
|
385
385
|
# File: mounts.rb | Line: 109
|
386
386
|
# Definition: def list_devices_mount_point
|
387
387
|
LinuxStat::Mounts.list_devices_mount_point()
|
388
|
-
=> {"proc"=>"/proc", "sys"=>"/sys", "dev"=>"/dev", "run"=>"/run", "/dev/sda2"=>"/", "securityfs"=>"/sys/kernel/security", "tmpfs"=>"/run/user/1000", "devpts"=>"/dev/pts", "cgroup2"=>"/sys/fs/cgroup/unified", "cgroup"=>"/sys/fs/cgroup/
|
388
|
+
=> {"proc"=>"/proc", "sys"=>"/sys", "dev"=>"/dev", "run"=>"/run", "/dev/sda2"=>"/", "securityfs"=>"/sys/kernel/security", "tmpfs"=>"/run/user/1000", "devpts"=>"/dev/pts", "cgroup2"=>"/sys/fs/cgroup/unified", "cgroup"=>"/sys/fs/cgroup/pids", "pstore"=>"/s...
|
389
389
|
|
390
390
|
# File: mounts.rb | Line: 80
|
391
391
|
# Definition: def mount_point(dev = root)
|
@@ -410,13 +410,13 @@ LinuxStat::Mounts.root_mount_options()
|
|
410
410
|
# File: mounts.rb | Line: 56
|
411
411
|
# Definition: def tmpfs
|
412
412
|
LinuxStat::Mounts.tmpfs()
|
413
|
-
=> {"/dev/shm"=>"tmpfs /dev/shm tmpfs rw,nosuid,nodev 0 0", "/sys/fs/cgroup"=>"tmpfs /sys/fs/cgroup tmpfs ro,nosuid,nodev,noexec,size=4096k,nr_inodes=1024,mode=755 0 0", "/
|
413
|
+
=> {"/dev/shm"=>"tmpfs /dev/shm tmpfs rw,nosuid,nodev,inode64 0 0", "/sys/fs/cgroup"=>"tmpfs /sys/fs/cgroup tmpfs ro,nosuid,nodev,noexec,size=4096k,nr_inodes=1024,mode=755,inode64 0 0", "/tmp"=>"tmpfs /tmp tmpfs rw,nosuid,nodev,relatime,size=4194304k,ino...
|
414
414
|
|
415
415
|
```
|
416
416
|
|
417
417
|
### LinuxStat::Net
|
418
418
|
```
|
419
|
-
# File: net.rb | Line:
|
419
|
+
# File: net.rb | Line: 84
|
420
420
|
# Definition: def usage(interval = 0.1)
|
421
421
|
LinuxStat::Net.current_usage(interval)
|
422
422
|
=> {:received=>0.0, :transmitted=>0.0}
|
@@ -426,22 +426,22 @@ LinuxStat::Net.current_usage(interval)
|
|
426
426
|
LinuxStat::Net.ipv4_private()
|
427
427
|
=> "192.168.0.102"
|
428
428
|
|
429
|
-
# File: net.rb | Line:
|
429
|
+
# File: net.rb | Line: 25
|
430
430
|
# Definition: def total_bytes
|
431
431
|
LinuxStat::Net.total_bytes()
|
432
|
-
=> {:received=>
|
432
|
+
=> {:received=>4509667469, :transmitted=>172614974}
|
433
433
|
|
434
|
-
# File: net.rb | Line:
|
434
|
+
# File: net.rb | Line: 43
|
435
435
|
# Definition: def total_bytes_received
|
436
436
|
LinuxStat::Net.total_bytes_received()
|
437
|
-
=>
|
437
|
+
=> 4509667469
|
438
438
|
|
439
|
-
# File: net.rb | Line:
|
439
|
+
# File: net.rb | Line: 56
|
440
440
|
# Definition: def total_bytes_transmitted
|
441
441
|
LinuxStat::Net.total_bytes_transmitted()
|
442
|
-
=>
|
442
|
+
=> 172614974
|
443
443
|
|
444
|
-
# File: net.rb | Line:
|
444
|
+
# File: net.rb | Line: 84
|
445
445
|
# Definition: def usage(interval = 0.1)
|
446
446
|
LinuxStat::Net.usage(interval)
|
447
447
|
=> {:received=>0.0, :transmitted=>0.0}
|
@@ -450,45 +450,69 @@ LinuxStat::Net.usage(interval)
|
|
450
450
|
|
451
451
|
### LinuxStat::OS
|
452
452
|
```
|
453
|
-
# File: os.rb | Line:
|
453
|
+
# File: os.rb | Line: 99
|
454
454
|
# Definition: def bits
|
455
455
|
LinuxStat::OS.bits()
|
456
456
|
=> 64
|
457
457
|
|
458
|
-
# File: os.rb | Line:
|
458
|
+
# File: os.rb | Line: 44
|
459
459
|
# Definition: def distribution
|
460
460
|
LinuxStat::OS.distribution()
|
461
461
|
=> "Arch Linux"
|
462
462
|
|
463
|
-
# File: os.rb | Line:
|
463
|
+
# File: os.rb | Line: 83
|
464
464
|
# Definition: def hostname
|
465
465
|
LinuxStat::OS.hostname()
|
466
466
|
=> "archlinux"
|
467
467
|
|
468
|
-
# File: os.rb | Line:
|
468
|
+
# File: os.rb | Line: 33
|
469
469
|
# Definition: def lsb_release
|
470
470
|
LinuxStat::OS.lsb_release()
|
471
471
|
=> {:LSB_VERSION=>"1.4", :DISTRIB_ID=>"Arch", :DISTRIB_RELEASE=>"rolling", :DISTRIB_DESCRIPTION=>"Arch Linux"}
|
472
472
|
|
473
|
-
# File: os.rb | Line:
|
473
|
+
# File: os.rb | Line: 66
|
474
474
|
# Definition: def machine
|
475
475
|
LinuxStat::OS.machine()
|
476
476
|
=> "x86_64"
|
477
477
|
|
478
|
-
# File: os.rb | Line:
|
478
|
+
# File: os.rb | Line: 74
|
479
479
|
# Definition: def nodename
|
480
480
|
LinuxStat::OS.nodename()
|
481
481
|
=> "archlinux"
|
482
482
|
|
483
|
-
# File: os.rb | Line:
|
483
|
+
# File: os.rb | Line: 17
|
484
484
|
# Definition: def os_release
|
485
485
|
LinuxStat::OS.os_release()
|
486
486
|
=> {:NAME=>"Arch Linux", :PRETTY_NAME=>"Arch Linux", :ID=>"arch", :BUILD_ID=>"rolling", :ANSI_COLOR=>"38;2;23;147;209", :HOME_URL=>"https://www.archlinux.org/", :DOCUMENTATION_URL=>"https://wiki.archlinux.org/", :SUPPORT_URL=>"https://bbs.archlinux.org/"...
|
487
487
|
|
488
|
-
# File: os.rb | Line:
|
488
|
+
# File: os.rb | Line: 114
|
489
489
|
# Definition: def uptime
|
490
490
|
LinuxStat::OS.uptime()
|
491
|
-
=> {:hour=>
|
491
|
+
=> {:hour=>8, :minute=>50, :second=>58.38}
|
492
|
+
|
493
|
+
```
|
494
|
+
|
495
|
+
### LinuxStat::PCI
|
496
|
+
```
|
497
|
+
# File: pci.rb | Line: 211
|
498
|
+
# Definition: def count
|
499
|
+
LinuxStat::PCI.count()
|
500
|
+
=> 13
|
501
|
+
|
502
|
+
# File: pci.rb | Line: 211
|
503
|
+
# Definition: def count
|
504
|
+
LinuxStat::PCI.count_devices()
|
505
|
+
=> 13
|
506
|
+
|
507
|
+
# File: pci.rb | Line: 52
|
508
|
+
# Definition: def devices_info(hwdata: true)
|
509
|
+
LinuxStat::PCI.devices_info(hwdata:)
|
510
|
+
=> [{:id=>"8086:1904", :vendor=>"8086", :device=>"1904", :irq=>0, :kernel_driver=>"skl_uncore", :hwdata=>{:vendor=>"Intel Corporation", :product=>"Xeon E3-1200 v5/E3-1500 v5/6th Gen Core Processor Host Bridge/DRAM Registers"}}, {:id=>"8086:1916", :vendor...
|
511
|
+
|
512
|
+
# File: pci.rb | Line: 128
|
513
|
+
# Definition: def devices_stat(hwdata: true)
|
514
|
+
LinuxStat::PCI.devices_stat(hwdata:)
|
515
|
+
=> [{:path=>"/sys/bus/pci/devices/0000:00:00.0/", :id=>"8086:1904", :vendor=>"8086", :device=>"1904", :sub_vendor=>"1028", :sub_device=>"077d", :kernel_driver=>"skl_uncore", :revision=>"0x08", :irq=>0, :enable=>false, :hwdata=>{:vendor=>"Intel Corporatio...
|
492
516
|
|
493
517
|
```
|
494
518
|
|
@@ -496,23 +520,23 @@ LinuxStat::OS.uptime()
|
|
496
520
|
```
|
497
521
|
# File: prettify_bytes.rb | Line: 42
|
498
522
|
# Definition: def convert_binary(n)
|
499
|
-
LinuxStat::PrettifyBytes.convert_binary(n =
|
500
|
-
=> "
|
523
|
+
LinuxStat::PrettifyBytes.convert_binary(n = 339049244499630)
|
524
|
+
=> "308.36 tebibytes"
|
501
525
|
|
502
526
|
# File: prettify_bytes.rb | Line: 19
|
503
527
|
# Definition: def convert_decimal(n)
|
504
|
-
LinuxStat::PrettifyBytes.convert_decimal(n =
|
505
|
-
=> "
|
528
|
+
LinuxStat::PrettifyBytes.convert_decimal(n = 963970414034560)
|
529
|
+
=> "963.97 terabytes"
|
506
530
|
|
507
531
|
# File: prettify_bytes.rb | Line: 90
|
508
532
|
# Definition: def convert_short_binary(n)
|
509
|
-
LinuxStat::PrettifyBytes.convert_short_binary(n =
|
510
|
-
=> "
|
533
|
+
LinuxStat::PrettifyBytes.convert_short_binary(n = 954637976904599)
|
534
|
+
=> "868.24 TiB"
|
511
535
|
|
512
536
|
# File: prettify_bytes.rb | Line: 65
|
513
537
|
# Definition: def convert_short_decimal(n)
|
514
|
-
LinuxStat::PrettifyBytes.convert_short_decimal(n =
|
515
|
-
=> "
|
538
|
+
LinuxStat::PrettifyBytes.convert_short_decimal(n = 464855754781732)
|
539
|
+
=> "464.86 TB"
|
516
540
|
|
517
541
|
```
|
518
542
|
|
@@ -521,37 +545,37 @@ LinuxStat::PrettifyBytes.convert_short_decimal(n = 238518247519978)
|
|
521
545
|
# File: process.rb | Line: 19
|
522
546
|
# Definition: def count
|
523
547
|
LinuxStat::Process.count()
|
524
|
-
=>
|
548
|
+
=> 203
|
525
549
|
|
526
550
|
# File: process.rb | Line: 71
|
527
551
|
# Definition: def idle
|
528
552
|
LinuxStat::Process.idle()
|
529
|
-
=> [3, 4,
|
553
|
+
=> [3, 4, 7, 9, 12, 23, 30, 37, 39, 45, 99, 100, 101, 104, 105, 106, 107, 108, 116, 117, 119, 122, 131, 134, 140, 152, 153, 172, 174, 176, 177, 181, 185, 186, 187, 188, 189, 190, 212, 233, 282, 339, 341, 351, 3101, 3102, 3103, 3104, 3105, 3106, 20589, 20...
|
530
554
|
|
531
555
|
# File: process.rb | Line: 8
|
532
556
|
# Definition: def list
|
533
557
|
LinuxStat::Process.list()
|
534
|
-
=> [1, 2, 3, 4,
|
558
|
+
=> [1, 2, 3, 4, 7, 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, 43, 44, 45, 46, 47, 48, 99, 100, 101, 104, 105, 106, 107, 108, 111, 113, 114, 116, 117, 119, 122, 131, 134, 140,...
|
535
559
|
|
536
560
|
# File: process.rb | Line: 25
|
537
561
|
# Definition: def names
|
538
562
|
LinuxStat::Process.names()
|
539
|
-
=> {1=>"systemd", 2=>"kthreadd", 3=>"rcu_gp", 4=>"rcu_par_gp",
|
563
|
+
=> {1=>"systemd", 2=>"kthreadd", 3=>"rcu_gp", 4=>"rcu_par_gp", 7=>"kworker/0:0H-kblockd", 9=>"mm_percpu_wq", 10=>"ksoftirqd/0", 11=>"rcuc/0", 12=>"rcu_preempt", 13=>"rcub/0", 14=>"migration/0", 15=>"idle_inject/0", 16=>"cpuhp/0", 17=>"cpuhp/1", 18=>"idle...
|
540
564
|
|
541
565
|
# File: process.rb | Line: 97
|
542
566
|
# Definition: def running
|
543
567
|
LinuxStat::Process.running()
|
544
|
-
=> [
|
568
|
+
=> [28, 23778, 24066]
|
545
569
|
|
546
570
|
# File: process.rb | Line: 58
|
547
571
|
# Definition: def sleeping
|
548
572
|
LinuxStat::Process.sleeping()
|
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,
|
573
|
+
=> [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, 43, 44, 46, 47, 48, 111, 113, 114, 171, 173, 191, 221, 239, 309, 311, 314, 315, 316, 338, 340, 366, 367, 368, 369, 383, 386, 389, 404, 407, 411,...
|
550
574
|
|
551
575
|
# File: process.rb | Line: 37
|
552
576
|
# Definition: def types
|
553
577
|
LinuxStat::Process.types()
|
554
|
-
=> {1=>:sleeping, 2=>:sleeping, 3=>:idle, 4=>:idle,
|
578
|
+
=> {1=>:sleeping, 2=>:sleeping, 3=>:idle, 4=>:idle, 7=>:idle, 9=>:idle, 10=>:sleeping, 11=>:sleeping, 12=>:idle, 13=>:sleeping, 14=>:sleeping, 15=>:sleeping, 16=>:sleeping, 17=>:sleeping, 18=>:sleeping, 19=>:sleeping, 20=>:sleeping, 21=>:sleeping, 23=>:i...
|
555
579
|
|
556
580
|
# File: process.rb | Line: 84
|
557
581
|
# Definition: def zombie
|
@@ -580,7 +604,7 @@ LinuxStat::ProcessInfo.count_cpu(pid)
|
|
580
604
|
# File: process_info.rb | Line: 247
|
581
605
|
# Definition: def cpu_stat(pid: $$, sleep: ticks_to_ms_t5)
|
582
606
|
LinuxStat::ProcessInfo.cpu_stat(pid:, sleep:)
|
583
|
-
=> {:cpu_usage=>0.0, :threads=>1, :last_executed_cpu=>
|
607
|
+
=> {:cpu_usage=>0.0, :threads=>1, :last_executed_cpu=>2}
|
584
608
|
|
585
609
|
# File: process_info.rb | Line: 307
|
586
610
|
# Definition: def cpu_usage(pid: $$, sleep: ticks_to_ms_t5)
|
@@ -595,17 +619,17 @@ LinuxStat::ProcessInfo.gid(pid)
|
|
595
619
|
# File: process_info.rb | Line: 433
|
596
620
|
# Definition: def last_executed_cpu(pid = $$)
|
597
621
|
LinuxStat::ProcessInfo.last_executed_cpu(pid)
|
598
|
-
=>
|
622
|
+
=> 2
|
599
623
|
|
600
624
|
# File: process_info.rb | Line: 114
|
601
625
|
# Definition: def mem_stat(pid = $$)
|
602
626
|
LinuxStat::ProcessInfo.mem_stat(pid)
|
603
|
-
=> {:memory=>
|
627
|
+
=> {:memory=>27025.408, :virtual_memory=>98074.624, :resident_memory=>33210.368}
|
604
628
|
|
605
629
|
# File: process_info.rb | Line: 147
|
606
630
|
# Definition: def memory(pid = $$)
|
607
631
|
LinuxStat::ProcessInfo.memory(pid)
|
608
|
-
=>
|
632
|
+
=> 27025.408
|
609
633
|
|
610
634
|
# File: process_info.rb | Line: 607
|
611
635
|
# Definition: def nice(pid = $$)
|
@@ -625,22 +649,22 @@ LinuxStat::ProcessInfo.owner(pid)
|
|
625
649
|
# File: process_info.rb | Line: 197
|
626
650
|
# Definition: def resident_memory(pid = $$)
|
627
651
|
LinuxStat::ProcessInfo.resident_memory(pid)
|
628
|
-
=>
|
652
|
+
=> 33210.368
|
629
653
|
|
630
654
|
# File: process_info.rb | Line: 563
|
631
655
|
# Definition: def running_time(pid = $$)
|
632
656
|
LinuxStat::ProcessInfo.running_time(pid)
|
633
|
-
=>
|
657
|
+
=> 1.05
|
634
658
|
|
635
659
|
# File: process_info.rb | Line: 544
|
636
660
|
# Definition: def start_time(pid = $$)
|
637
661
|
LinuxStat::ProcessInfo.start_time(pid)
|
638
|
-
=> 2020-12-
|
662
|
+
=> 2020-12-27 04:20:42 +0530
|
639
663
|
|
640
664
|
# File: process_info.rb | Line: 513
|
641
665
|
# Definition: def start_time_epoch(pid = $$)
|
642
666
|
LinuxStat::ProcessInfo.start_time_epoch(pid)
|
643
|
-
=>
|
667
|
+
=> 1609023042
|
644
668
|
|
645
669
|
# File: process_info.rb | Line: 592
|
646
670
|
# Definition: def state(pid = $$)
|
@@ -670,7 +694,7 @@ LinuxStat::ProcessInfo.uid(pid)
|
|
670
694
|
# File: process_info.rb | Line: 172
|
671
695
|
# Definition: def virtual_memory(pid = $$)
|
672
696
|
LinuxStat::ProcessInfo.virtual_memory(pid)
|
673
|
-
=>
|
697
|
+
=> 98213.888
|
674
698
|
|
675
699
|
```
|
676
700
|
|
@@ -684,27 +708,27 @@ LinuxStat::Swap.any?()
|
|
684
708
|
# File: swap.rb | Line: 68
|
685
709
|
# Definition: def available
|
686
710
|
LinuxStat::Swap.available()
|
687
|
-
=>
|
711
|
+
=> 3759868
|
688
712
|
|
689
713
|
# File: swap.rb | Line: 8
|
690
714
|
# Definition: def list
|
691
715
|
LinuxStat::Swap.list()
|
692
|
-
=> {"/dev/zram0"=>[:partition, 4194300,
|
716
|
+
=> {"/dev/zram0"=>[:partition, 4194300, 434432, -2]}
|
693
717
|
|
694
718
|
# File: swap.rb | Line: 103
|
695
719
|
# Definition: def percent_available
|
696
720
|
LinuxStat::Swap.percent_available()
|
697
|
-
=>
|
721
|
+
=> 89.64
|
698
722
|
|
699
723
|
# File: swap.rb | Line: 89
|
700
724
|
# Definition: def percent_used
|
701
725
|
LinuxStat::Swap.percent_used()
|
702
|
-
=>
|
726
|
+
=> 10.36
|
703
727
|
|
704
728
|
# File: swap.rb | Line: 32
|
705
729
|
# Definition: def stat
|
706
730
|
LinuxStat::Swap.stat()
|
707
|
-
=> {:total=>4194300, :used=>
|
731
|
+
=> {:total=>4194300, :used=>434432, :available=>3759868, :percent_used=>10.36, :percent_available=>89.64}
|
708
732
|
|
709
733
|
# File: swap.rb | Line: 57
|
710
734
|
# Definition: def total
|
@@ -714,14 +738,14 @@ LinuxStat::Swap.total()
|
|
714
738
|
# File: swap.rb | Line: 80
|
715
739
|
# Definition: def used
|
716
740
|
LinuxStat::Swap.used()
|
717
|
-
=>
|
741
|
+
=> 434432
|
718
742
|
|
719
743
|
```
|
720
744
|
|
721
745
|
### LinuxStat::Sysconf
|
722
746
|
```
|
723
747
|
LinuxStat::Sysconf.child_max()
|
724
|
-
=>
|
748
|
+
=> 2000000
|
725
749
|
|
726
750
|
LinuxStat::Sysconf.expr_nest_max()
|
727
751
|
=> 32
|
@@ -757,7 +781,7 @@ LinuxStat::Sysconf.pagesize()
|
|
757
781
|
=> 4096
|
758
782
|
|
759
783
|
LinuxStat::Sysconf.posix_version()
|
760
|
-
=>
|
784
|
+
=> 200809
|
761
785
|
|
762
786
|
LinuxStat::Sysconf.processor_configured()
|
763
787
|
=> 4
|
@@ -778,17 +802,17 @@ LinuxStat::Sysconf.tty_name_max()
|
|
778
802
|
|
779
803
|
### LinuxStat::USB
|
780
804
|
```
|
781
|
-
# File: usb.rb | Line:
|
805
|
+
# File: usb.rb | Line: 135
|
782
806
|
# Definition: def count
|
783
807
|
LinuxStat::USB.count()
|
784
|
-
=>
|
808
|
+
=> 11
|
785
809
|
|
786
|
-
# File: usb.rb | Line:
|
810
|
+
# File: usb.rb | Line: 135
|
787
811
|
# Definition: def count
|
788
812
|
LinuxStat::USB.count_devices()
|
789
|
-
=>
|
813
|
+
=> 11
|
790
814
|
|
791
|
-
# File: usb.rb | Line:
|
815
|
+
# File: usb.rb | Line: 47
|
792
816
|
# Definition: def devices_stat(hwdata: true)
|
793
817
|
LinuxStat::USB.devices_stat(hwdata:)
|
794
818
|
=> [{:path=>"/sys/bus/usb/devices/1-1.2/", :id=>"04d9:1203", :vendor_id=>"04d9", :product_id=>"1203", :bus_num=>1, :dev_num=>4, :hwdata=>{:vendor=>"Holtek Semiconductor, Inc.", :product=>"Keyboard"}, :authorized=>true, :b_max_power=>"100mA", :b_max_packe...
|
@@ -804,13 +828,13 @@ LinuxStat::Uname.nodename()
|
|
804
828
|
=> "archlinux"
|
805
829
|
|
806
830
|
LinuxStat::Uname.release()
|
807
|
-
=> "5.
|
831
|
+
=> "5.10.2-xanmod1-cacule-1-cacule"
|
808
832
|
|
809
833
|
LinuxStat::Uname.sysname()
|
810
834
|
=> "Linux"
|
811
835
|
|
812
836
|
LinuxStat::Uname.version()
|
813
|
-
=> "#1 SMP PREEMPT
|
837
|
+
=> "#1 SMP PREEMPT Thu, 24 Dec 2020 18:28:16 +0000"
|
814
838
|
|
815
839
|
```
|
816
840
|
|
data/lib/linux_stat.rb
CHANGED
@@ -0,0 +1,311 @@
|
|
1
|
+
module LinuxStat
|
2
|
+
module PCI
|
3
|
+
class << self
|
4
|
+
##
|
5
|
+
# = devices_info(hwdata: true)
|
6
|
+
#
|
7
|
+
# [ Not to be confused with devices_stat ]
|
8
|
+
#
|
9
|
+
# Take a look at system_stat for more results.
|
10
|
+
#
|
11
|
+
# Returns details about the devices found in /proc/bus/pci/devices file.
|
12
|
+
#
|
13
|
+
# The details doesn't contain a lot of details, it's short and opens just one file once.
|
14
|
+
#
|
15
|
+
# The return value is an Array of multiple Hashes. If there's no info available,
|
16
|
+
# it will rather return an empty Array.
|
17
|
+
#
|
18
|
+
# On Android Termux for example, it can not list the directories because they are
|
19
|
+
# not readable the the regular user.
|
20
|
+
#
|
21
|
+
# It can have information like:
|
22
|
+
#
|
23
|
+
# id, vendor, device, irq, and kernel_driver
|
24
|
+
#
|
25
|
+
# An example of the returned sample from a test machine is:
|
26
|
+
# LinuxStat::PCI.devices_info
|
27
|
+
#
|
28
|
+
# => [{:id=>"8086:1904", :vendor=>"8086", :device=>"1904", :irq=>0, :kernel_driver=>"skl_uncore", :hwdata=>{:vendor=>"Intel Corporation", :product=>"Xeon E3-1200 v5/E3-1500 v5/6th Gen Core Processor Host Bridge/DRAM Registers"}}]
|
29
|
+
#
|
30
|
+
# Right, it's an Array of Hashes.
|
31
|
+
#
|
32
|
+
# It also takes one option. The hwdata, which is true by default.
|
33
|
+
#
|
34
|
+
# Information about usb devices is found inside /usr/share/hwdata/pci.ids
|
35
|
+
#
|
36
|
+
# The data contains the vendor and the product, the subvendor and the subproduct.
|
37
|
+
#
|
38
|
+
# If the option is enabled, it will try read /usr/share/hwdata/pci.ids
|
39
|
+
#
|
40
|
+
# But the file will be read only once. The consecutive calls to this method
|
41
|
+
# won't open the hwdata all the times.
|
42
|
+
#
|
43
|
+
# But if there's no hwdata, the Hash returned by this method will not contain
|
44
|
+
# hwdata key.
|
45
|
+
#
|
46
|
+
# The data is only populated if it's available. For example, if there's no
|
47
|
+
# manufacturer available for the product, the returned Hash will not contain the
|
48
|
+
# information about the manufacturer.
|
49
|
+
#
|
50
|
+
# Also note that if there's no info available or no PCI enabled devices, it will return an empty
|
51
|
+
# Hash.
|
52
|
+
def devices_info(hwdata: true)
|
53
|
+
@@proc_pci_readable ||= File.readable?('/proc/bus/pci/devices')
|
54
|
+
return {} unless @@proc_pci_readable
|
55
|
+
|
56
|
+
IO.readlines('/proc/bus/pci/devices'.freeze).map! { |dev|
|
57
|
+
x = dev.split
|
58
|
+
|
59
|
+
vendor = x[1][0..3]
|
60
|
+
device = x[1][4..-1]
|
61
|
+
irq = x[2].to_i(16)
|
62
|
+
kernel_driver = x[-1]
|
63
|
+
|
64
|
+
query = if hwdata
|
65
|
+
query_hwdata(vendor, device)
|
66
|
+
else
|
67
|
+
{}
|
68
|
+
end
|
69
|
+
|
70
|
+
ret = {
|
71
|
+
id: "#{vendor}:#{device}",
|
72
|
+
vendor: vendor, device: device,
|
73
|
+
irq: irq,
|
74
|
+
kernel_driver: kernel_driver
|
75
|
+
}
|
76
|
+
|
77
|
+
ret.merge!(hwdata: query) unless query.empty?
|
78
|
+
|
79
|
+
ret
|
80
|
+
}
|
81
|
+
end
|
82
|
+
|
83
|
+
##
|
84
|
+
# = devices_stat(hwdata: true)
|
85
|
+
#
|
86
|
+
# Returns details about the devices found in /sys/bus/pci/devices/
|
87
|
+
#
|
88
|
+
# The return value is an Array of multiple Hashes. If there's no info available,
|
89
|
+
# it will rather return an empty Array.
|
90
|
+
#
|
91
|
+
# On Android Termux for example, it can not list the directories because they are
|
92
|
+
# not readable the the regular user.
|
93
|
+
#
|
94
|
+
# It can have information like:
|
95
|
+
#
|
96
|
+
# path, id, vendor, device, subvendor, sub_device,
|
97
|
+
# kernel_driver, revision, irq, enable, hwdata.
|
98
|
+
#
|
99
|
+
# An example of the returned sample from a test machine is:
|
100
|
+
# LinuxStat::PCI.devices_stat
|
101
|
+
#
|
102
|
+
# => [{:path=>"/sys/bus/pci/devices/0000:00:00.0/", :id=>"8086:1904", :vendor=>"8086", :device=>"1904", :sub_vendor=>"1028", :sub_device=>"077d", :kernel_driver=>"skl_uncore", :revision=>"0x08", :irq=>0, :enable=>false, :hwdata=>{:vendor=>"Intel Corporation", :product=>"Xeon E3-1200 v5/E3-1500 v5/6th Gen Core Processor Host Bridge/DRAM Registers", :sub_system=>nil}}]
|
103
|
+
#
|
104
|
+
# Right, it's an Array of Hashes.
|
105
|
+
#
|
106
|
+
# It also takes one option. The hwdata, which is true by default.
|
107
|
+
#
|
108
|
+
# Information about usb devices is found inside /usr/share/hwdata/pci.ids
|
109
|
+
#
|
110
|
+
# The data contains the vendor and the product, the subvendor and the subproduct.
|
111
|
+
#
|
112
|
+
# If the option is enabled, it will try read /usr/share/hwdata/pci.ids
|
113
|
+
#
|
114
|
+
# But the file will be read only once. The consecutive calls to this method
|
115
|
+
# won't open the hwdata all the times.
|
116
|
+
#
|
117
|
+
# But if there's no hwdata, the Hash returned by this method will not contain
|
118
|
+
# hwdata key.
|
119
|
+
#
|
120
|
+
# The data is only populated if it's available. For example, if there's no
|
121
|
+
# manufacturer available for the product, the returned Hash will not contain the
|
122
|
+
# information about the manufacturer.
|
123
|
+
#
|
124
|
+
# If there's no /sys/bus/pci/devices/, it will call LinuxStat::PCI.devices_info
|
125
|
+
#
|
126
|
+
# Also note that if there's no info available or no PCI enabled devices, it will return an empty
|
127
|
+
# Hash.
|
128
|
+
def devices_stat(hwdata: true)
|
129
|
+
@@sys_pci_readable ||= File.readable?('/sys/bus/pci/devices/')
|
130
|
+
return devices_info(hwdata: hwdata) unless @@sys_pci_readable
|
131
|
+
|
132
|
+
Dir['/sys/bus/pci/devices/*/'.freeze].sort!.map! { |x|
|
133
|
+
_vendor_file = File.join(x, 'vendor'.freeze)
|
134
|
+
next unless File.readable?(_vendor_file)
|
135
|
+
vendor = IO.read(_vendor_file).to_i(16).to_s(16)
|
136
|
+
prepend_0(vendor)
|
137
|
+
|
138
|
+
_device_file = File.join(x, 'device'.freeze)
|
139
|
+
next unless File.readable?(_device_file)
|
140
|
+
device = IO.read(_device_file).to_i(16).to_s(16)
|
141
|
+
prepend_0(device)
|
142
|
+
|
143
|
+
_sub_vendor_file = File.join(x, 'subsystem_vendor'.freeze)
|
144
|
+
sub_vendor = File.readable?(_sub_vendor_file) ? IO.read(_sub_vendor_file).to_i(16).to_s(16) : nil
|
145
|
+
prepend_0(sub_vendor) if sub_vendor
|
146
|
+
|
147
|
+
_sub_device_file = File.join(x, 'subsystem_device'.freeze)
|
148
|
+
sub_device = File.readable?(_sub_device_file) ? IO.read(_sub_device_file).to_i(16).to_s(16) : nil
|
149
|
+
prepend_0(sub_device) if sub_device
|
150
|
+
|
151
|
+
_uevent = File.join(x, 'uevent'.freeze)
|
152
|
+
uevent = File.readable?(_uevent) ? IO.foreach(_uevent) : nil
|
153
|
+
|
154
|
+
kernel_driver = if uevent
|
155
|
+
uevent.find { |_x|
|
156
|
+
_x.split(?=.freeze)[0].to_s.tap(&:strip!) == 'DRIVER'.freeze
|
157
|
+
} &.split(?=) &.[](1) &.tap(&:strip!)
|
158
|
+
else
|
159
|
+
nil
|
160
|
+
end
|
161
|
+
|
162
|
+
_revision_file = File.join(x, 'revision'.freeze)
|
163
|
+
revision = File.readable?(_revision_file) ? IO.read(_revision_file).tap(&:strip!) : ''.freeze
|
164
|
+
|
165
|
+
_irq_file = File.join(x, 'irq'.freeze)
|
166
|
+
irq = File.readable?(_irq_file) ? IO.read(_irq_file).to_i : nil
|
167
|
+
|
168
|
+
_enable_file = File.join(x, 'enable'.freeze)
|
169
|
+
enable = File.readable?(_enable_file) ? IO.read(_enable_file).to_i == 1 : nil
|
170
|
+
|
171
|
+
query = if hwdata && sub_vendor && sub_device
|
172
|
+
query_hwdata(vendor, device, sub_vendor, sub_device)
|
173
|
+
elsif hwdata && sub_vendor
|
174
|
+
query_hwdata(vendor, device, sub_vendor)
|
175
|
+
elsif hwdata
|
176
|
+
query_hwdata(vendor, device)
|
177
|
+
else
|
178
|
+
{}
|
179
|
+
end
|
180
|
+
|
181
|
+
ret = {
|
182
|
+
path: x, id: "#{vendor}:#{device}",
|
183
|
+
vendor: vendor, device: device
|
184
|
+
}
|
185
|
+
|
186
|
+
ret.merge!(sub_vendor: sub_vendor) if sub_vendor
|
187
|
+
ret.merge!(sub_device: sub_device) if sub_device
|
188
|
+
|
189
|
+
ret.merge!(kernel_driver: kernel_driver) if kernel_driver
|
190
|
+
ret.merge!(revision: revision) unless revision.empty?
|
191
|
+
ret.merge!(irq: irq) if irq
|
192
|
+
ret.merge!(enable: enable) unless enable.nil?
|
193
|
+
ret.merge!(hwdata: query) unless query.empty?
|
194
|
+
|
195
|
+
ret
|
196
|
+
}
|
197
|
+
end
|
198
|
+
|
199
|
+
##
|
200
|
+
# Reads /proc/bus/pci/devices, counts and returns the total number of lines.
|
201
|
+
#
|
202
|
+
# But if the information isn't available, it will look into the contents of
|
203
|
+
# /sys/bus/pci/devices, and counts the total number of
|
204
|
+
# devices connected to the PCI.
|
205
|
+
# It checks for devices with vendor and device id files.
|
206
|
+
# If there's no such file, it will not count them as a PCI connected device.
|
207
|
+
#
|
208
|
+
# The return type is an integer.
|
209
|
+
#
|
210
|
+
# But if the information isn't available, it will return nil.
|
211
|
+
def count
|
212
|
+
@@proc_pci_readable ||= File.readable?('/proc/bus/pci/devices')
|
213
|
+
@@sys_pci_readable ||= File.readable?('/sys/bus/pci/devices/')
|
214
|
+
|
215
|
+
if @@proc_pci_readable
|
216
|
+
IO.readlines('/proc/bus/pci/devices'.freeze).length
|
217
|
+
|
218
|
+
elsif @@sys_pci_readable
|
219
|
+
Dir['/sys/bus/pci/devices/*/'.freeze].count { |x|
|
220
|
+
id_vendor_file = File.join(x, 'vendor'.freeze)
|
221
|
+
id_product_file = File.join(x, 'device'.freeze)
|
222
|
+
File.readable?(id_vendor_file) && File.readable?(id_product_file)
|
223
|
+
}
|
224
|
+
|
225
|
+
else
|
226
|
+
nil
|
227
|
+
end
|
228
|
+
end
|
229
|
+
|
230
|
+
alias count_devices count
|
231
|
+
|
232
|
+
private
|
233
|
+
def hwdata
|
234
|
+
@@hwdata_file ||= "/usr/share/hwdata/pci.ids"
|
235
|
+
|
236
|
+
@@hwdata ||= if File.readable?(@@hwdata_file)
|
237
|
+
ret, vendor_id, device_id, device = {}, nil, nil, nil
|
238
|
+
i = -1
|
239
|
+
|
240
|
+
file_data = IO.readlines(@@hwdata_file, encoding: 'ASCII-8BIT')
|
241
|
+
file_data_size = file_data.size
|
242
|
+
|
243
|
+
while (i += 1) < file_data_size
|
244
|
+
x = file_data[i]
|
245
|
+
|
246
|
+
_lstripped = x.lstrip
|
247
|
+
next if _lstripped[0] == ?#.freeze || _lstripped.empty?
|
248
|
+
|
249
|
+
if x[0..1] == "\t\t".freeze
|
250
|
+
next unless device_id
|
251
|
+
|
252
|
+
x.strip!
|
253
|
+
sub_device_id = x[/\A.*?\s/].to_s.strip
|
254
|
+
sub_device = x[device_id.length..-1].to_s.strip
|
255
|
+
|
256
|
+
if ret[vendor_id] &.at(1) &.[](device_id) &.[](1)
|
257
|
+
sub_system_id = sub_device[/\A.*?\s/].to_s.strip
|
258
|
+
sub_system_device = sub_device[sub_system_id.length..-1].to_s.strip
|
259
|
+
|
260
|
+
ret[vendor_id][1][device_id][1].merge!(sub_device_id => {sub_system_id => sub_system_device})
|
261
|
+
end
|
262
|
+
|
263
|
+
elsif x[0] == ?\t.freeze
|
264
|
+
next unless vendor_id
|
265
|
+
|
266
|
+
x.strip!
|
267
|
+
device_id = x[/\A.*?\s/].to_s.strip
|
268
|
+
device = x[device_id.length..-1].to_s.strip
|
269
|
+
ret[vendor_id][1][device_id] = [device, {}]
|
270
|
+
|
271
|
+
else
|
272
|
+
x.strip!
|
273
|
+
vendor_id = x[/\A.*?\s/].to_s.strip
|
274
|
+
vendor = x[vendor_id.length..-1].to_s.strip
|
275
|
+
ret[vendor_id] = [vendor, {}]
|
276
|
+
end
|
277
|
+
end
|
278
|
+
|
279
|
+
ret.freeze
|
280
|
+
else
|
281
|
+
{}
|
282
|
+
end
|
283
|
+
end
|
284
|
+
|
285
|
+
def prepend_0(n)
|
286
|
+
n[0, 0] = ?0.*(4 - n.length).freeze if n.length < 4
|
287
|
+
n
|
288
|
+
end
|
289
|
+
|
290
|
+
def query_hwdata(vendor_id, product_id, sub_vendor_id = nil, sub_device_id = nil)
|
291
|
+
vendor = hwdata[vendor_id]
|
292
|
+
|
293
|
+
if vendor
|
294
|
+
ret = {
|
295
|
+
vendor: vendor[0],
|
296
|
+
product: vendor.dig(1, product_id, 0),
|
297
|
+
}
|
298
|
+
|
299
|
+
if sub_vendor_id && sub_device_id
|
300
|
+
sub_product = vendor.dig(1, product_id, 1, sub_vendor_id, sub_device_id)
|
301
|
+
ret.merge!(sub_system: sub_product) if sub_product
|
302
|
+
end
|
303
|
+
|
304
|
+
ret
|
305
|
+
else
|
306
|
+
{}
|
307
|
+
end
|
308
|
+
end
|
309
|
+
end
|
310
|
+
end
|
311
|
+
end
|
data/lib/linux_stat/usb.rb
CHANGED
@@ -14,13 +14,13 @@ module LinuxStat
|
|
14
14
|
#
|
15
15
|
# It can have information like:
|
16
16
|
#
|
17
|
-
# id, vendor id, product id, manufacturer, serial, bus number, dev number,
|
17
|
+
# path, id, vendor id, product id, manufacturer, serial, bus number, dev number,
|
18
18
|
# b_max_power, b_max_packet_size, etc.
|
19
19
|
#
|
20
20
|
# An example of the returned sample from a test machine is:
|
21
21
|
# LinuxStat::USB.devices_stat
|
22
22
|
#
|
23
|
-
# [{:path=>"/sys/bus/usb/devices/1-1.2/", :id=>"04d9:1203", :vendor_id=>"04d9", :product_id=>"1203", :bus_num=>1, :dev_num=>4, :hwdata=>{:vendor=>"Holtek Semiconductor, Inc.", :product=>"Keyboard"}, :authorized=>true, :b_max_power=>"100mA", :b_max_packet_size0=>8}
|
23
|
+
# => [{:path=>"/sys/bus/usb/devices/1-1.2/", :id=>"04d9:1203", :vendor_id=>"04d9", :product_id=>"1203", :bus_num=>1, :dev_num=>4, :hwdata=>{:vendor=>"Holtek Semiconductor, Inc.", :product=>"Keyboard"}, :authorized=>true, :b_max_power=>"100mA", :b_max_packet_size0=>8}
|
24
24
|
#
|
25
25
|
# Right, it's an array of Hashes.
|
26
26
|
#
|
@@ -114,6 +114,8 @@ module LinuxStat
|
|
114
114
|
|
115
115
|
ret.merge!(b_max_power: b_max_power) unless b_max_power.empty?
|
116
116
|
ret.merge!(b_max_packet_size0: b_max_packet_size0) if b_max_packet_size0
|
117
|
+
|
118
|
+
ret
|
117
119
|
}.tap(&:compact!)
|
118
120
|
end
|
119
121
|
|
@@ -163,19 +165,19 @@ module LinuxStat
|
|
163
165
|
if x[0] == ?\t.freeze
|
164
166
|
next unless vendor_id
|
165
167
|
|
166
|
-
|
167
|
-
device_id =
|
168
|
-
device =
|
168
|
+
x.strip!
|
169
|
+
device_id = x[/\A.*?\s/].to_s.strip
|
170
|
+
device = x[device_id.length..-1].to_s.strip
|
169
171
|
ret[vendor_id][1][device_id] = device
|
170
172
|
else
|
171
|
-
|
172
|
-
vendor_id =
|
173
|
-
vendor =
|
173
|
+
x.strip!
|
174
|
+
vendor_id = x[/\A.*?\s/].to_s.strip
|
175
|
+
vendor = x[vendor_id.length..-1].to_s.strip
|
174
176
|
ret[vendor_id] = [vendor, {}]
|
175
177
|
end
|
176
178
|
end
|
177
179
|
|
178
|
-
ret
|
180
|
+
ret.freeze
|
179
181
|
else
|
180
182
|
{}
|
181
183
|
end
|
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: 1.0
|
4
|
+
version: 1.1.0
|
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-26 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: Linux only, efficient linux system utilization reporting and system monitoring
|
14
14
|
gem
|
@@ -47,6 +47,7 @@ files:
|
|
47
47
|
- lib/linux_stat/mounts.rb
|
48
48
|
- lib/linux_stat/net.rb
|
49
49
|
- lib/linux_stat/os.rb
|
50
|
+
- lib/linux_stat/pci.rb
|
50
51
|
- lib/linux_stat/prettify_bytes.rb
|
51
52
|
- lib/linux_stat/process.rb
|
52
53
|
- lib/linux_stat/process_info.rb
|