linux_stat 0.9.2 → 1.0.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 +74 -55
- data/lib/linux_stat.rb +1 -0
- data/lib/linux_stat/mounts.rb +4 -4
- data/lib/linux_stat/usb.rb +192 -0
- 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: dfecb2c10d06e8e8cc76c1b03df8a518442f63d30fc7d556cb61649d1fc11957
|
4
|
+
data.tar.gz: beb60db61f4668cf82b4f551de0c08761bd935e91c6f631cf47f79adfc4803aa
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3812d0d70ce53bfb24df7941252e711c37ff3ae9ecae87009a7f0cab13c82db99bc3dfdfeae02a370e9a8337c08ab13372f33768ee09b3d01e8caf7d3e4dea50
|
7
|
+
data.tar.gz: b600994a6566b315cb6b2a69563039d203f8a8b563135491978fd0f8c81499ac6dc784f40f3ec745520c4e8e8b787efbf3019150b578842e6be933938ae786fe
|
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.453
|
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"=>1971347, "cpu1"=>2000253, "cpu2"=>1916631, "cpu3"=>2000064}
|
181
181
|
|
182
182
|
# File: cpu.rb | Line: 265
|
183
183
|
# Definition: def governor
|
@@ -212,7 +212,7 @@ 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=>5.0, 1=>16.67, 2=>0.0, 3=>0.0, 4=>16.67}
|
216
216
|
|
217
217
|
# File: cpu.rb | Line: 63
|
218
218
|
# Definition: def total_usage(sleep = ticks_to_ms_t5)
|
@@ -222,19 +222,19 @@ LinuxStat::CPU.total_usage(sleep)
|
|
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
|
+
=> 9.52
|
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=>
|
230
|
+
=> {0=>5.26, 1=>16.67, 2=>0.0, 3=>0.0, 4=>0.0}
|
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=>11703573, :block_avail_unpriv=>11703573, :inodes=>58612160, :free_inodes=>56863418, :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
|
+
=> 47937835008
|
247
247
|
|
248
248
|
# File: filesystem.rb | Line: 58
|
249
249
|
# Definition: def free(fs = ?..freeze)
|
250
250
|
LinuxStat::Filesystem.free(fs)
|
251
|
-
=>
|
251
|
+
=> 47937835008
|
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=>47937835008, :used=>72043356160}
|
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=>11703573, :block_avail_unpriv=>11703573, :inodes=>58612160, :free_inodes=>56863418, :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
|
+
=> 72043356160
|
272
272
|
|
273
273
|
```
|
274
274
|
|
@@ -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
|
+
=> 1597312
|
335
335
|
|
336
336
|
# File: memory.rb | Line: 81
|
337
337
|
# Definition: def percent_available
|
338
338
|
LinuxStat::Memory.percent_available()
|
339
|
-
=>
|
339
|
+
=> 41.64
|
340
340
|
|
341
341
|
# File: memory.rb | Line: 70
|
342
342
|
# Definition: def percent_used
|
343
343
|
LinuxStat::Memory.percent_used()
|
344
|
-
=>
|
344
|
+
=> 58.36
|
345
345
|
|
346
346
|
# File: memory.rb | Line: 11
|
347
347
|
# Definition: def stat
|
348
348
|
LinuxStat::Memory.stat()
|
349
|
-
=> {:total=>
|
349
|
+
=> {:total=>3836236, :used=>2238924, :available=>1597312, :percent_used=>58.36, :percent_available=>41.64}
|
350
350
|
|
351
351
|
# File: memory.rb | Line: 40
|
352
352
|
# Definition: def total
|
353
353
|
LinuxStat::Memory.total()
|
354
|
-
=>
|
354
|
+
=> 3836236
|
355
355
|
|
356
356
|
# File: memory.rb | Line: 60
|
357
357
|
# Definition: def used
|
358
358
|
LinuxStat::Memory.used()
|
359
|
-
=>
|
359
|
+
=> 2238924
|
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=>47937835008, :available=>47937835008, :used=>72043356160, :percent_used=>60.05, :percent_free=>39.95, :percent_available=>39.95}
|
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=1892904k,nr_inodes=473226,mode=755 0 0", "run /run tmpfs rw,nosuid,nodev,relatime,mode=755 0 0", "...
|
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", "tra...
|
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/memory", "pstore"=>"...
|
389
389
|
|
390
390
|
# File: mounts.rb | Line: 80
|
391
391
|
# Definition: def mount_point(dev = root)
|
@@ -419,7 +419,7 @@ LinuxStat::Mounts.tmpfs()
|
|
419
419
|
# File: net.rb | Line: 80
|
420
420
|
# Definition: def usage(interval = 0.1)
|
421
421
|
LinuxStat::Net.current_usage(interval)
|
422
|
-
=> {:received=>
|
422
|
+
=> {:received=>0.0, :transmitted=>0.0}
|
423
423
|
|
424
424
|
# File: net.rb | Line: 10
|
425
425
|
# Definition: def ipv4_private
|
@@ -429,17 +429,17 @@ LinuxStat::Net.ipv4_private()
|
|
429
429
|
# File: net.rb | Line: 23
|
430
430
|
# Definition: def total_bytes
|
431
431
|
LinuxStat::Net.total_bytes()
|
432
|
-
=> {:received=>
|
432
|
+
=> {:received=>687677565, :transmitted=>149550163}
|
433
433
|
|
434
434
|
# File: net.rb | Line: 41
|
435
435
|
# Definition: def total_bytes_received
|
436
436
|
LinuxStat::Net.total_bytes_received()
|
437
|
-
=>
|
437
|
+
=> 687677565
|
438
438
|
|
439
439
|
# File: net.rb | Line: 54
|
440
440
|
# Definition: def total_bytes_transmitted
|
441
441
|
LinuxStat::Net.total_bytes_transmitted()
|
442
|
-
=>
|
442
|
+
=> 149550163
|
443
443
|
|
444
444
|
# File: net.rb | Line: 80
|
445
445
|
# Definition: def usage(interval = 0.1)
|
@@ -488,7 +488,7 @@ LinuxStat::OS.os_release()
|
|
488
488
|
# File: os.rb | Line: 110
|
489
489
|
# Definition: def uptime
|
490
490
|
LinuxStat::OS.uptime()
|
491
|
-
=> {:hour=>
|
491
|
+
=> {:hour=>6, :minute=>50, :second=>39.61}
|
492
492
|
|
493
493
|
```
|
494
494
|
|
@@ -496,23 +496,23 @@ LinuxStat::OS.uptime()
|
|
496
496
|
```
|
497
497
|
# File: prettify_bytes.rb | Line: 42
|
498
498
|
# Definition: def convert_binary(n)
|
499
|
-
LinuxStat::PrettifyBytes.convert_binary(n =
|
500
|
-
=> "
|
499
|
+
LinuxStat::PrettifyBytes.convert_binary(n = 200152828322898)
|
500
|
+
=> "182.04 tebibytes"
|
501
501
|
|
502
502
|
# File: prettify_bytes.rb | Line: 19
|
503
503
|
# Definition: def convert_decimal(n)
|
504
|
-
LinuxStat::PrettifyBytes.convert_decimal(n =
|
505
|
-
=> "
|
504
|
+
LinuxStat::PrettifyBytes.convert_decimal(n = 434440373786022)
|
505
|
+
=> "434.44 terabytes"
|
506
506
|
|
507
507
|
# File: prettify_bytes.rb | Line: 90
|
508
508
|
# Definition: def convert_short_binary(n)
|
509
|
-
LinuxStat::PrettifyBytes.convert_short_binary(n =
|
510
|
-
=> "
|
509
|
+
LinuxStat::PrettifyBytes.convert_short_binary(n = 88309228425306)
|
510
|
+
=> "80.32 TiB"
|
511
511
|
|
512
512
|
# File: prettify_bytes.rb | Line: 65
|
513
513
|
# Definition: def convert_short_decimal(n)
|
514
|
-
LinuxStat::PrettifyBytes.convert_short_decimal(n =
|
515
|
-
=> "
|
514
|
+
LinuxStat::PrettifyBytes.convert_short_decimal(n = 238518247519978)
|
515
|
+
=> "238.52 TB"
|
516
516
|
|
517
517
|
```
|
518
518
|
|
@@ -521,17 +521,17 @@ LinuxStat::PrettifyBytes.convert_short_decimal(n = 598923420265643)
|
|
521
521
|
# File: process.rb | Line: 19
|
522
522
|
# Definition: def count
|
523
523
|
LinuxStat::Process.count()
|
524
|
-
=>
|
524
|
+
=> 195
|
525
525
|
|
526
526
|
# File: process.rb | Line: 71
|
527
527
|
# Definition: def idle
|
528
528
|
LinuxStat::Process.idle()
|
529
|
-
=> [3, 4, 6, 9, 12, 23, 30, 37, 39, 49, 102, 103, 104, 106, 107, 108, 109, 110, 117, 119,
|
529
|
+
=> [3, 4, 6, 9, 12, 23, 30, 37, 39, 49, 102, 103, 104, 106, 107, 108, 109, 110, 117, 118, 119, 121, 131, 134, 140, 152, 153, 173, 175, 177, 180, 182, 186, 187, 188, 189, 190, 191, 193, 237, 273, 325, 329, 335, 9051, 9055, 9056, 9057, 9058, 9059, 9060, 13...
|
530
530
|
|
531
531
|
# File: process.rb | Line: 8
|
532
532
|
# Definition: def list
|
533
533
|
LinuxStat::Process.list()
|
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,
|
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, 118, 119, 121, 131, 134,...
|
535
535
|
|
536
536
|
# File: process.rb | Line: 25
|
537
537
|
# Definition: def names
|
@@ -541,12 +541,12 @@ LinuxStat::Process.names()
|
|
541
541
|
# File: process.rb | Line: 97
|
542
542
|
# Definition: def running
|
543
543
|
LinuxStat::Process.running()
|
544
|
-
=> [
|
544
|
+
=> [15978]
|
545
545
|
|
546
546
|
# File: process.rb | Line: 58
|
547
547
|
# Definition: def sleeping
|
548
548
|
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, 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, 172, 174, 192, 222, 238, 310, 311, 312, 313, 315, 324, 327, 332, 333, 334, 336, 347, 349, 351, 384, 412,...
|
550
550
|
|
551
551
|
# File: process.rb | Line: 37
|
552
552
|
# Definition: def types
|
@@ -565,7 +565,7 @@ LinuxStat::Process.zombie()
|
|
565
565
|
# File: process_info.rb | Line: 54
|
566
566
|
# Definition: def cmdline(pid = $$)
|
567
567
|
LinuxStat::ProcessInfo.cmdline(pid)
|
568
|
-
=> "ruby /
|
568
|
+
=> "/usr/bin/ruby /home/sourav/.gem/ruby/2.7.0/bin/linuxstat.rb -md"
|
569
569
|
|
570
570
|
# File: process_info.rb | Line: 78
|
571
571
|
# Definition: def command_name(pid = $$)
|
@@ -580,7 +580,7 @@ LinuxStat::ProcessInfo.count_cpu(pid)
|
|
580
580
|
# File: process_info.rb | Line: 247
|
581
581
|
# Definition: def cpu_stat(pid: $$, sleep: ticks_to_ms_t5)
|
582
582
|
LinuxStat::ProcessInfo.cpu_stat(pid:, sleep:)
|
583
|
-
=> {:cpu_usage=>0.0, :threads=>1, :last_executed_cpu=>
|
583
|
+
=> {:cpu_usage=>0.0, :threads=>1, :last_executed_cpu=>3}
|
584
584
|
|
585
585
|
# File: process_info.rb | Line: 307
|
586
586
|
# Definition: def cpu_usage(pid: $$, sleep: ticks_to_ms_t5)
|
@@ -595,17 +595,17 @@ LinuxStat::ProcessInfo.gid(pid)
|
|
595
595
|
# File: process_info.rb | Line: 433
|
596
596
|
# Definition: def last_executed_cpu(pid = $$)
|
597
597
|
LinuxStat::ProcessInfo.last_executed_cpu(pid)
|
598
|
-
=>
|
598
|
+
=> 3
|
599
599
|
|
600
600
|
# File: process_info.rb | Line: 114
|
601
601
|
# Definition: def mem_stat(pid = $$)
|
602
602
|
LinuxStat::ProcessInfo.mem_stat(pid)
|
603
|
-
=> {:memory=>
|
603
|
+
=> {:memory=>12627.968, :virtual_memory=>84221.952, :resident_memory=>18743.296}
|
604
604
|
|
605
605
|
# File: process_info.rb | Line: 147
|
606
606
|
# Definition: def memory(pid = $$)
|
607
607
|
LinuxStat::ProcessInfo.memory(pid)
|
608
|
-
=>
|
608
|
+
=> 12627.968
|
609
609
|
|
610
610
|
# File: process_info.rb | Line: 607
|
611
611
|
# Definition: def nice(pid = $$)
|
@@ -625,7 +625,7 @@ LinuxStat::ProcessInfo.owner(pid)
|
|
625
625
|
# File: process_info.rb | Line: 197
|
626
626
|
# Definition: def resident_memory(pid = $$)
|
627
627
|
LinuxStat::ProcessInfo.resident_memory(pid)
|
628
|
-
=>
|
628
|
+
=> 18743.296
|
629
629
|
|
630
630
|
# File: process_info.rb | Line: 563
|
631
631
|
# Definition: def running_time(pid = $$)
|
@@ -635,12 +635,12 @@ LinuxStat::ProcessInfo.running_time(pid)
|
|
635
635
|
# File: process_info.rb | Line: 544
|
636
636
|
# Definition: def start_time(pid = $$)
|
637
637
|
LinuxStat::ProcessInfo.start_time(pid)
|
638
|
-
=> 2020-12-
|
638
|
+
=> 2020-12-24 19:05:51 +0530
|
639
639
|
|
640
640
|
# File: process_info.rb | Line: 513
|
641
641
|
# Definition: def start_time_epoch(pid = $$)
|
642
642
|
LinuxStat::ProcessInfo.start_time_epoch(pid)
|
643
|
-
=>
|
643
|
+
=> 1608816951
|
644
644
|
|
645
645
|
# File: process_info.rb | Line: 592
|
646
646
|
# Definition: def state(pid = $$)
|
@@ -660,7 +660,7 @@ LinuxStat::ProcessInfo.threads(pid)
|
|
660
660
|
# File: process_info.rb | Line: 23
|
661
661
|
# Definition: def total_io(pid = $$)
|
662
662
|
LinuxStat::ProcessInfo.total_io(pid)
|
663
|
-
=> {:read_bytes=>
|
663
|
+
=> {:read_bytes=>0, :write_bytes=>0}
|
664
664
|
|
665
665
|
# File: process_info.rb | Line: 446
|
666
666
|
# Definition: def uid(pid = $$)
|
@@ -670,7 +670,7 @@ LinuxStat::ProcessInfo.uid(pid)
|
|
670
670
|
# File: process_info.rb | Line: 172
|
671
671
|
# Definition: def virtual_memory(pid = $$)
|
672
672
|
LinuxStat::ProcessInfo.virtual_memory(pid)
|
673
|
-
=>
|
673
|
+
=> 84221.952
|
674
674
|
|
675
675
|
```
|
676
676
|
|
@@ -684,27 +684,27 @@ LinuxStat::Swap.any?()
|
|
684
684
|
# File: swap.rb | Line: 68
|
685
685
|
# Definition: def available
|
686
686
|
LinuxStat::Swap.available()
|
687
|
-
=>
|
687
|
+
=> 4064380
|
688
688
|
|
689
689
|
# File: swap.rb | Line: 8
|
690
690
|
# Definition: def list
|
691
691
|
LinuxStat::Swap.list()
|
692
|
-
=> {"/dev/zram0"=>[:partition, 4194300,
|
692
|
+
=> {"/dev/zram0"=>[:partition, 4194300, 129920, -2]}
|
693
693
|
|
694
694
|
# File: swap.rb | Line: 103
|
695
695
|
# Definition: def percent_available
|
696
696
|
LinuxStat::Swap.percent_available()
|
697
|
-
=> 96.
|
697
|
+
=> 96.9
|
698
698
|
|
699
699
|
# File: swap.rb | Line: 89
|
700
700
|
# Definition: def percent_used
|
701
701
|
LinuxStat::Swap.percent_used()
|
702
|
-
=> 3.
|
702
|
+
=> 3.1
|
703
703
|
|
704
704
|
# File: swap.rb | Line: 32
|
705
705
|
# Definition: def stat
|
706
706
|
LinuxStat::Swap.stat()
|
707
|
-
=> {:total=>4194300, :used=>
|
707
|
+
=> {:total=>4194300, :used=>129920, :available=>4064380, :percent_used=>3.1, :percent_available=>96.9}
|
708
708
|
|
709
709
|
# File: swap.rb | Line: 57
|
710
710
|
# Definition: def total
|
@@ -714,7 +714,7 @@ LinuxStat::Swap.total()
|
|
714
714
|
# File: swap.rb | Line: 80
|
715
715
|
# Definition: def used
|
716
716
|
LinuxStat::Swap.used()
|
717
|
-
=>
|
717
|
+
=> 129920
|
718
718
|
|
719
719
|
```
|
720
720
|
|
@@ -776,6 +776,25 @@ LinuxStat::Sysconf.tty_name_max()
|
|
776
776
|
|
777
777
|
```
|
778
778
|
|
779
|
+
### LinuxStat::USB
|
780
|
+
```
|
781
|
+
# File: usb.rb | Line: 74
|
782
|
+
# Definition: def count
|
783
|
+
LinuxStat::USB.count()
|
784
|
+
=> 10
|
785
|
+
|
786
|
+
# File: usb.rb | Line: 74
|
787
|
+
# Definition: def count
|
788
|
+
LinuxStat::USB.count_devices()
|
789
|
+
=> 10
|
790
|
+
|
791
|
+
# File: usb.rb | Line: 4
|
792
|
+
# Definition: def devices_stat(hwdata: true)
|
793
|
+
LinuxStat::USB.devices_stat(hwdata:)
|
794
|
+
=> [{: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...
|
795
|
+
|
796
|
+
```
|
797
|
+
|
779
798
|
### LinuxStat::Uname
|
780
799
|
```
|
781
800
|
LinuxStat::Uname.machine()
|
data/lib/linux_stat.rb
CHANGED
data/lib/linux_stat/mounts.rb
CHANGED
@@ -62,7 +62,7 @@ module LinuxStat
|
|
62
62
|
end
|
63
63
|
|
64
64
|
##
|
65
|
-
# mount_point(dev = root)
|
65
|
+
# = mount_point(dev = root)
|
66
66
|
#
|
67
67
|
# Where device = block device.
|
68
68
|
#
|
@@ -94,7 +94,7 @@ module LinuxStat
|
|
94
94
|
end
|
95
95
|
|
96
96
|
##
|
97
|
-
# list_devices_mount_point()
|
97
|
+
# = list_devices_mount_point()
|
98
98
|
#
|
99
99
|
# It shows all the block devices corresponding to mount points.
|
100
100
|
#
|
@@ -120,7 +120,7 @@ module LinuxStat
|
|
120
120
|
end
|
121
121
|
|
122
122
|
##
|
123
|
-
# devices_stat
|
123
|
+
# = devices_stat
|
124
124
|
#
|
125
125
|
# [ Not to confuse this method with device_stat(dev) which shows only one device's info ]
|
126
126
|
#
|
@@ -162,7 +162,7 @@ module LinuxStat
|
|
162
162
|
end
|
163
163
|
|
164
164
|
##
|
165
|
-
# device_stat(dev = root)
|
165
|
+
# = device_stat(dev = root)
|
166
166
|
#
|
167
167
|
# [ Not to confuse this method with devices_stat() which shows all devices ]
|
168
168
|
#
|
@@ -0,0 +1,192 @@
|
|
1
|
+
module LinuxStat
|
2
|
+
module USB
|
3
|
+
class << self
|
4
|
+
##
|
5
|
+
# = devices_stat(hwdata: true)
|
6
|
+
#
|
7
|
+
# Returns details about the devices found in /sys/bus/usb/devices/
|
8
|
+
#
|
9
|
+
# The return value is an Array of multiple Hashes. If there's no info available,
|
10
|
+
# it will rather return an empty Array.
|
11
|
+
#
|
12
|
+
# On Android Termux for example, it can not list the directories because they are
|
13
|
+
# not readable the the regular user.
|
14
|
+
#
|
15
|
+
# It can have information like:
|
16
|
+
#
|
17
|
+
# id, vendor id, product id, manufacturer, serial, bus number, dev number,
|
18
|
+
# b_max_power, b_max_packet_size, etc.
|
19
|
+
#
|
20
|
+
# An example of the returned sample from a test machine is:
|
21
|
+
# LinuxStat::USB.devices_stat
|
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}
|
24
|
+
#
|
25
|
+
# Right, it's an array of Hashes.
|
26
|
+
#
|
27
|
+
# It also takes one option. The hwdata, which is true by default.
|
28
|
+
#
|
29
|
+
# Information about usb devices is found inside /usr/share/hwdata/usb.ids
|
30
|
+
#
|
31
|
+
# The data contains the vendor and the product.
|
32
|
+
#
|
33
|
+
# If the option is enabled, it will try look at /usr/share/hwdata/usb.ids
|
34
|
+
#
|
35
|
+
# But the file will be read only once. The consecutive calls to this method
|
36
|
+
# won't open the hwdata all the times.
|
37
|
+
#
|
38
|
+
# But if there's no hwdata, the Hash returned by this method will not contain
|
39
|
+
# hwdata key.
|
40
|
+
#
|
41
|
+
# The data is only populated if it's available. For example, if there's no
|
42
|
+
# manufacturer available for the product, the returned Hash will not contain the
|
43
|
+
# information about the manufacturer.
|
44
|
+
#
|
45
|
+
# Also note that if there's no info available or no USB devices, it will return an empty
|
46
|
+
# Hash.
|
47
|
+
def devices_stat(hwdata: true)
|
48
|
+
@@sys_usb_readable ||= File.readable?('/sys/bus/usb/devices/')
|
49
|
+
return [] unless @@sys_usb_readable
|
50
|
+
|
51
|
+
Dir['/sys/bus/usb/devices/*/'.freeze].sort!.map! { |x|
|
52
|
+
id_vendor_file = File.join(x, 'idVendor'.freeze)
|
53
|
+
next unless File.readable?(id_vendor_file)
|
54
|
+
id_vendor = IO.read(id_vendor_file).strip
|
55
|
+
|
56
|
+
id_product_file = File.join(x, 'idProduct'.freeze)
|
57
|
+
next unless File.readable?(id_vendor_file)
|
58
|
+
id_product = IO.read(id_product_file).strip
|
59
|
+
|
60
|
+
bus_num_file = File.join(x, 'busnum'.freeze)
|
61
|
+
bus_num = File.readable?(bus_num_file) ? IO.read(bus_num_file).strip : ''.freeze
|
62
|
+
|
63
|
+
dev_num_file = File.join(x, 'devnum'.freeze)
|
64
|
+
dev_num = File.readable?(dev_num_file) ? IO.read(dev_num_file).strip : ''.freeze
|
65
|
+
|
66
|
+
serial_file = File.join(x, 'serial'.freeze)
|
67
|
+
serial = File.readable?(serial_file) ? IO.read(serial_file).strip : ''.freeze
|
68
|
+
|
69
|
+
product_file = File.join(x, 'product'.freeze)
|
70
|
+
product = File.readable?(product_file) ? IO.read(product_file).strip : ''.freeze
|
71
|
+
|
72
|
+
manufacturer_file = File.join(x, 'manufacturer'.freeze)
|
73
|
+
manufacturer = File.readable?(manufacturer_file) ? IO.read(manufacturer_file).strip : ''.freeze
|
74
|
+
|
75
|
+
removable_file = File.join(x, 'removable'.freeze)
|
76
|
+
removable = File.readable?(removable_file) ? IO.read(removable_file).strip : ''.freeze
|
77
|
+
|
78
|
+
authorized_file = File.join(x, 'authorized'.freeze)
|
79
|
+
authorized = File.readable?(authorized_file) ? IO.read(authorized_file).to_i : ''.freeze
|
80
|
+
|
81
|
+
b_max_power_file = File.join(x, 'bMaxPower'.freeze)
|
82
|
+
b_max_power = File.readable?(b_max_power_file) ? IO.read(b_max_power_file).strip : ''.freeze
|
83
|
+
|
84
|
+
b_max_packet_size0_file = File.join(x, 'bMaxPacketSize0'.freeze)
|
85
|
+
b_max_packet_size0 = File.readable?(b_max_packet_size0_file) ? IO.read(b_max_packet_size0_file).to_i : ''.freeze
|
86
|
+
|
87
|
+
query = hwdata ? query_hwdata(id_vendor, id_product) : {}
|
88
|
+
|
89
|
+
removable.downcase!
|
90
|
+
is_removable = if removable == 'removable'.freeze
|
91
|
+
true
|
92
|
+
elsif removable == 'unknown'.freeze
|
93
|
+
nil
|
94
|
+
else
|
95
|
+
false
|
96
|
+
end
|
97
|
+
|
98
|
+
ret = {
|
99
|
+
path: x, id: "#{id_vendor}:#{id_product}",
|
100
|
+
vendor_id: id_vendor, product_id: id_product
|
101
|
+
}
|
102
|
+
|
103
|
+
ret.merge!(bus_num: bus_num.to_i) unless bus_num.empty?
|
104
|
+
ret.merge!(dev_num: dev_num.to_i) unless dev_num.empty?
|
105
|
+
|
106
|
+
ret.merge!(serial: serial) unless serial.empty?
|
107
|
+
|
108
|
+
ret.merge!(hwdata: query) unless query.empty?
|
109
|
+
ret.merge!(product: product) unless product.empty?
|
110
|
+
ret.merge!(manufacturer: manufacturer) unless manufacturer.empty?
|
111
|
+
|
112
|
+
ret.merge!(removable: is_removable) unless is_removable.nil?
|
113
|
+
ret.merge!(authorized: authorized == 1)
|
114
|
+
|
115
|
+
ret.merge!(b_max_power: b_max_power) unless b_max_power.empty?
|
116
|
+
ret.merge!(b_max_packet_size0: b_max_packet_size0) if b_max_packet_size0
|
117
|
+
}.tap(&:compact!)
|
118
|
+
end
|
119
|
+
|
120
|
+
##
|
121
|
+
# Opens /sys/bus/usb/devices, and counts the total number of
|
122
|
+
# devices connected to the USB interface.
|
123
|
+
# The return type is an integer.
|
124
|
+
#
|
125
|
+
# It checks for devices with vendor and product id file.
|
126
|
+
# If there's no such file, it will not count them as a USB device.
|
127
|
+
#
|
128
|
+
# It could be also an integrated hub or a webcam, as well as
|
129
|
+
# external hotpluggable devices like printer, USB storage devices,
|
130
|
+
# USB mouse, USB keyboard, USB joypad etc.
|
131
|
+
#
|
132
|
+
# But if the information isn't available, it will return nil.
|
133
|
+
def count
|
134
|
+
@@sys_usb_readable ||= File.readable?('/sys/bus/usb/devices/')
|
135
|
+
return [] unless @@sys_usb_readable
|
136
|
+
|
137
|
+
Dir['/sys/bus/usb/devices/*/'.freeze].count { |x|
|
138
|
+
id_vendor_file = File.join(x, 'idVendor'.freeze)
|
139
|
+
id_product_file = File.join(x, 'idProduct'.freeze)
|
140
|
+
File.readable?(id_vendor_file) && File.readable?(id_product_file)
|
141
|
+
}
|
142
|
+
end
|
143
|
+
|
144
|
+
alias count_devices count
|
145
|
+
|
146
|
+
private
|
147
|
+
def hwdata
|
148
|
+
@@hwdata_file ||= "/usr/share/hwdata/usb.ids"
|
149
|
+
|
150
|
+
@@hwdata ||= if File.readable?(@@hwdata_file)
|
151
|
+
file_data = IO.readlines(@@hwdata_file, encoding: 'ASCII-8BIT')
|
152
|
+
ret, vendor_id = {}, nil
|
153
|
+
|
154
|
+
i = -1
|
155
|
+
file_data_size = file_data.size
|
156
|
+
|
157
|
+
while (i += 1) < file_data_size
|
158
|
+
x = file_data[i]
|
159
|
+
|
160
|
+
_lstripped = x.lstrip
|
161
|
+
next if _lstripped == ?#.freeze || _lstripped.empty?
|
162
|
+
|
163
|
+
if x.start_with?(?\t.freeze)
|
164
|
+
data = x.tap(&:strip!)
|
165
|
+
device_id = data[/\A.*?\s/].to_s.strip
|
166
|
+
device = data[device_id.length..-1].to_s.strip
|
167
|
+
ret[vendor_id][1][device_id] = device
|
168
|
+
else
|
169
|
+
data = x
|
170
|
+
vendor_id = data[/\A.*?\s/].to_s.strip
|
171
|
+
vendor = data[vendor_id.length..-1].to_s.strip
|
172
|
+
ret[vendor_id] = [vendor, {}]
|
173
|
+
end
|
174
|
+
end
|
175
|
+
|
176
|
+
ret.freeze
|
177
|
+
else
|
178
|
+
{}
|
179
|
+
end
|
180
|
+
end
|
181
|
+
|
182
|
+
def query_hwdata(vendor_id, product_id)
|
183
|
+
vendor = hwdata[vendor_id]
|
184
|
+
if vendor
|
185
|
+
{vendor: vendor[0], product: vendor[1][product_id]}
|
186
|
+
else
|
187
|
+
{}
|
188
|
+
end
|
189
|
+
end
|
190
|
+
end
|
191
|
+
end
|
192
|
+
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: 0.
|
4
|
+
version: 1.0.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-24 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: Linux only, efficient linux system utilization reporting and system monitoring
|
14
14
|
gem
|
@@ -51,6 +51,7 @@ files:
|
|
51
51
|
- lib/linux_stat/process.rb
|
52
52
|
- lib/linux_stat/process_info.rb
|
53
53
|
- lib/linux_stat/swap.rb
|
54
|
+
- lib/linux_stat/usb.rb
|
54
55
|
- lib/linux_stat/user.rb
|
55
56
|
- lib/linux_stat/version.rb
|
56
57
|
homepage: https://github.com/Souravgoswami/linux_stat/
|