linux_stat 1.1.0 → 1.2.3

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 86307b8ccfb101dbd829b5fdf36d6c9bf4eaffb555e1387311f34f10d5cb748e
4
- data.tar.gz: 5576fa510cffef8567df558cd096afe91ccb5afa536532f5625f04be19279ae6
3
+ metadata.gz: 4b3270fb4ddf3dd436a63233d134f5fecd2ff13d7aa0d4f91b444ac65ed29b84
4
+ data.tar.gz: 8f4987b804b866eb6b0bea4a9de1a507e6529ca6188d54b0def59a7dbf74c73f
5
5
  SHA512:
6
- metadata.gz: c6960ddec53d610b61e44de4c7432f4e05fb00c7588629924fd34d17d711357c00867bd80c48497082332507879c6b7ad5472f0b66f188fab14d34d0d491d579
7
- data.tar.gz: 1f31b0c48520ec826bc9b74fb48e5d752fb61aedab841911c2de92e9027861226ebafb03e210fea67667b5d1ab8b68a271f7859fe2ae2acd25b5f50efc9e2c7d
6
+ metadata.gz: fd9393533d03fbfe16599d972762aaa6d84aa737de9ceccd7a4b333a3e049742e2a088f29364203dfd5e65199c95ccc790a68d31e8c8cf6c5f6fd718dc655818
7
+ data.tar.gz: b4fbe848f72fe1d51ed8c3d8bba37aba8a1da937c4f1639503dedbb894fc8eebe6516c7c8957e88569b73362d03dfd4a60787af1c4c585fe40b73725e2f5dabe
data/README.md CHANGED
@@ -10,7 +10,7 @@ LinuxStat lets you read status of a Linux system. It can show you cpu stats and
10
10
 
11
11
  It only works for Linux, and detecting the OS is upto the user of this gem.
12
12
 
13
- Programming Languages Used:
13
+ Languages Used:
14
14
 
15
15
  <img src="https://linuxstatloc.herokuapp.com/badge.svg" width="260px">
16
16
 
@@ -37,6 +37,32 @@ On Debian based systems:
37
37
 
38
38
  ---
39
39
 
40
+ ## Optional Dependencies
41
+
42
+ You need hwdata to decode vendor and product ids if you use LinuxStat::USB and/or LinuxStat::PCI
43
+
44
+ You can install hwdata simply.
45
+
46
+ + Arch:
47
+
48
+ ```
49
+ sudo pacman -S hwids
50
+ ```
51
+
52
+ + Debian based systems:
53
+
54
+ ```
55
+ sudo apt install hwdata
56
+ ```
57
+
58
+ But without hwdata, it won't show such information.
59
+
60
+ You can also point to a downloaded copy of hwdata (pci.ids / usb.ids) file.
61
+
62
+ Follow [Note 7](https://github.com/Souravgoswami/linux_stat#note-7-hwdata) below for more information on that.
63
+
64
+ ---
65
+
40
66
  ## Installation
41
67
 
42
68
  Add this line to your application's Gemfile:
@@ -153,7 +179,7 @@ LinuxStat::Battery.technology()
153
179
  # File: battery.rb | Line: 160
154
180
  # Definition: def voltage_now
155
181
  LinuxStat::Battery.voltage_now()
156
- => 12.541
182
+ => 12.625
157
183
 
158
184
  ```
159
185
 
@@ -177,7 +203,7 @@ LinuxStat::CPU.count_online()
177
203
  # File: cpu.rb | Line: 197
178
204
  # Definition: def cur_freq
179
205
  LinuxStat::CPU.cur_freq()
180
- => {"cpu0"=>2000006, "cpu1"=>2000050, "cpu2"=>2000024, "cpu3"=>2000195}
206
+ => {"cpu0"=>1999999, "cpu1"=>2000045, "cpu2"=>2000144, "cpu3"=>2000034}
181
207
 
182
208
  # File: cpu.rb | Line: 265
183
209
  # Definition: def governor
@@ -212,29 +238,29 @@ LinuxStat::CPU.online()
212
238
  # File: cpu.rb | Line: 23
213
239
  # Definition: def stat(sleep = ticks_to_ms_t5)
214
240
  LinuxStat::CPU.stat(sleep)
215
- => {0=>9.52, 1=>0.0, 2=>0.0, 3=>0.0, 4=>0.0}
241
+ => {0=>10.0, 1=>0.0, 2=>0.0, 3=>16.67, 4=>0.0}
216
242
 
217
243
  # File: cpu.rb | Line: 63
218
244
  # Definition: def total_usage(sleep = ticks_to_ms_t5)
219
245
  LinuxStat::CPU.total_usage(sleep)
220
- => 0.0
246
+ => 19.05
221
247
 
222
248
  # File: cpu.rb | Line: 63
223
249
  # Definition: def total_usage(sleep = ticks_to_ms_t5)
224
250
  LinuxStat::CPU.usage(sleep)
225
- => 14.29
251
+ => 5.26
226
252
 
227
253
  # File: cpu.rb | Line: 23
228
254
  # Definition: def stat(sleep = ticks_to_ms_t5)
229
255
  LinuxStat::CPU.usages(sleep)
230
- => {0=>5.0, 1=>0.0, 2=>20.0, 3=>20.0, 4=>16.67}
256
+ => {0=>5.26, 1=>0.0, 2=>0.0, 3=>33.33, 4=>20.0}
231
257
 
232
258
  ```
233
259
 
234
260
  ### LinuxStat::FS
235
261
  ```
236
262
  LinuxStat::FS.stat(arg = "/")
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}
263
+ => {:block_size=>4096, :fragment_size=>4096, :blocks=>29292283, :block_free=>10846968, :block_avail_unpriv=>10846968, :inodes=>58612160, :free_inodes=>56825184, :filesystem_id=>2050, :mount_flags=>1024, :max_filename_length=>255}
238
264
 
239
265
  ```
240
266
 
@@ -243,22 +269,22 @@ LinuxStat::FS.stat(arg = "/")
243
269
  # File: filesystem.rb | Line: 92
244
270
  # Definition: def available(fs = ?..freeze)
245
271
  LinuxStat::Filesystem.available(fs)
246
- => 43449671680
272
+ => 44429180928
247
273
 
248
274
  # File: filesystem.rb | Line: 58
249
275
  # Definition: def free(fs = ?..freeze)
250
276
  LinuxStat::Filesystem.free(fs)
251
- => 43449671680
277
+ => 44429180928
252
278
 
253
279
  # File: filesystem.rb | Line: 19
254
280
  # Definition: def stat(fs = ?..freeze)
255
281
  LinuxStat::Filesystem.stat(fs)
256
- => {:total=>119981191168, :free=>43449671680, :used=>76531519488}
282
+ => {:total=>119981191168, :free=>44429180928, :used=>75552010240}
257
283
 
258
284
  # File: filesystem.rb | Line: 108
259
285
  # Definition: def stat_raw(fs = ?..freeze)
260
286
  LinuxStat::Filesystem.stat_raw(fs)
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}
287
+ => {:block_size=>4096, :fragment_size=>4096, :blocks=>29292283, :block_free=>10846968, :block_avail_unpriv=>10846968, :inodes=>58612160, :free_inodes=>56825184, :filesystem_id=>2050, :mount_flags=>1024, :max_filename_length=>255}
262
288
 
263
289
  # File: filesystem.rb | Line: 39
264
290
  # Definition: def total(fs = ?..freeze)
@@ -268,7 +294,7 @@ LinuxStat::Filesystem.total(fs)
268
294
  # File: filesystem.rb | Line: 73
269
295
  # Definition: def used(fs = ?..freeze)
270
296
  LinuxStat::Filesystem.used(fs)
271
- => 76531519488
297
+ => 75552010240
272
298
 
273
299
  ```
274
300
 
@@ -331,22 +357,22 @@ LinuxStat::Kernel.version()
331
357
  # File: memory.rb | Line: 50
332
358
  # Definition: def available
333
359
  LinuxStat::Memory.available()
334
- => 1000240
360
+ => 375384
335
361
 
336
362
  # File: memory.rb | Line: 81
337
363
  # Definition: def percent_available
338
364
  LinuxStat::Memory.percent_available()
339
- => 26.07
365
+ => 9.79
340
366
 
341
367
  # File: memory.rb | Line: 70
342
368
  # Definition: def percent_used
343
369
  LinuxStat::Memory.percent_used()
344
- => 73.93
370
+ => 90.21
345
371
 
346
372
  # File: memory.rb | Line: 11
347
373
  # Definition: def stat
348
374
  LinuxStat::Memory.stat()
349
- => {:total=>3836036, :used=>2835796, :available=>1000240, :percent_used=>73.93, :percent_available=>26.07}
375
+ => {:total=>3836036, :used=>3460652, :available=>375384, :percent_used=>90.21, :percent_available=>9.79}
350
376
 
351
377
  # File: memory.rb | Line: 40
352
378
  # Definition: def total
@@ -356,7 +382,7 @@ LinuxStat::Memory.total()
356
382
  # File: memory.rb | Line: 60
357
383
  # Definition: def used
358
384
  LinuxStat::Memory.used()
359
- => 2835796
385
+ => 3460652
360
386
 
361
387
  ```
362
388
 
@@ -365,7 +391,7 @@ LinuxStat::Memory.used()
365
391
  # File: mounts.rb | Line: 179
366
392
  # Definition: def device_stat(dev = root)
367
393
  LinuxStat::Mounts.device_stat(dev)
368
- => {:mountpoint=>"/", :total=>119981191168, :free=>43449671680, :available=>43449671680, :used=>76531519488, :percent_used=>63.79, :percent_free=>36.21, :percent_available=>36.21}
394
+ => {:mountpoint=>"/", :total=>119981191168, :free=>44429180928, :available=>44429180928, :used=>75552010240, :percent_used=>62.97, :percent_free=>37.03, :percent_available=>37.03}
369
395
 
370
396
  # File: mounts.rb | Line: 137
371
397
  # Definition: def devices_stat
@@ -375,17 +401,17 @@ LinuxStat::Mounts.devices_stat()
375
401
  # File: mounts.rb | Line: 11
376
402
  # Definition: def list
377
403
  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=1909256k,nr_inodes=477314,mode=755,inode64 0 0", "run /run tmpfs rw,nosuid,nodev,relatime,mode=755...
404
+ => ["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=1909248k,nr_inodes=477312,mode=755,inode64 0 0", "run /run tmpfs rw,nosuid,nodev,relatime,mode=755...
379
405
 
380
406
  # File: mounts.rb | Line: 20
381
407
  # Definition: def list_devices
382
408
  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", "mqu...
409
+ => ["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...
384
410
 
385
411
  # File: mounts.rb | Line: 109
386
412
  # Definition: def list_devices_mount_point
387
413
  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/pids", "pstore"=>"/s...
414
+ => {"proc"=>"/proc", "sys"=>"/sys", "dev"=>"/dev", "run"=>"/run", "/dev/sda2"=>"/", "securityfs"=>"/sys/kernel/security", "tmpfs"=>"/run/user/0", "devpts"=>"/dev/pts", "cgroup2"=>"/sys/fs/cgroup/unified", "cgroup"=>"/sys/fs/cgroup/cpuset", "pstore"=>"/sy...
389
415
 
390
416
  # File: mounts.rb | Line: 80
391
417
  # Definition: def mount_point(dev = root)
@@ -410,7 +436,7 @@ LinuxStat::Mounts.root_mount_options()
410
436
  # File: mounts.rb | Line: 56
411
437
  # Definition: def tmpfs
412
438
  LinuxStat::Mounts.tmpfs()
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...
439
+ => {"/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", "/ramdisk"=>"tmpfs /ramdisk tmpfs rw,nosuid,nodev,relatime,size=6291...
414
440
 
415
441
  ```
416
442
 
@@ -419,7 +445,7 @@ LinuxStat::Mounts.tmpfs()
419
445
  # File: net.rb | Line: 84
420
446
  # Definition: def usage(interval = 0.1)
421
447
  LinuxStat::Net.current_usage(interval)
422
- => {:received=>0.0, :transmitted=>0.0}
448
+ => {:received=>279000.0, :transmitted=>5640.0}
423
449
 
424
450
  # File: net.rb | Line: 10
425
451
  # Definition: def ipv4_private
@@ -429,38 +455,43 @@ LinuxStat::Net.ipv4_private()
429
455
  # File: net.rb | Line: 25
430
456
  # Definition: def total_bytes
431
457
  LinuxStat::Net.total_bytes()
432
- => {:received=>4509667469, :transmitted=>172614974}
458
+ => {:received=>2093813713, :transmitted=>138899807}
433
459
 
434
460
  # File: net.rb | Line: 43
435
461
  # Definition: def total_bytes_received
436
462
  LinuxStat::Net.total_bytes_received()
437
- => 4509667469
463
+ => 2093813713
438
464
 
439
465
  # File: net.rb | Line: 56
440
466
  # Definition: def total_bytes_transmitted
441
467
  LinuxStat::Net.total_bytes_transmitted()
442
- => 172614974
468
+ => 138899807
443
469
 
444
470
  # File: net.rb | Line: 84
445
471
  # Definition: def usage(interval = 0.1)
446
472
  LinuxStat::Net.usage(interval)
447
- => {:received=>0.0, :transmitted=>0.0}
473
+ => {:received=>419320.0, :transmitted=>10340.0}
448
474
 
449
475
  ```
450
476
 
451
477
  ### LinuxStat::OS
452
478
  ```
453
- # File: os.rb | Line: 99
479
+ # File: os.rb | Line: 127
454
480
  # Definition: def bits
455
481
  LinuxStat::OS.bits()
456
482
  => 64
457
483
 
484
+ # File: os.rb | Line: 82
485
+ # Definition: def version
486
+ LinuxStat::OS.distrib_version()
487
+ => "rolling"
488
+
458
489
  # File: os.rb | Line: 44
459
490
  # Definition: def distribution
460
491
  LinuxStat::OS.distribution()
461
492
  => "Arch Linux"
462
493
 
463
- # File: os.rb | Line: 83
494
+ # File: os.rb | Line: 115
464
495
  # Definition: def hostname
465
496
  LinuxStat::OS.hostname()
466
497
  => "archlinux"
@@ -470,12 +501,12 @@ LinuxStat::OS.hostname()
470
501
  LinuxStat::OS.lsb_release()
471
502
  => {:LSB_VERSION=>"1.4", :DISTRIB_ID=>"Arch", :DISTRIB_RELEASE=>"rolling", :DISTRIB_DESCRIPTION=>"Arch Linux"}
472
503
 
473
- # File: os.rb | Line: 66
504
+ # File: os.rb | Line: 98
474
505
  # Definition: def machine
475
506
  LinuxStat::OS.machine()
476
507
  => "x86_64"
477
508
 
478
- # File: os.rb | Line: 74
509
+ # File: os.rb | Line: 106
479
510
  # Definition: def nodename
480
511
  LinuxStat::OS.nodename()
481
512
  => "archlinux"
@@ -485,10 +516,15 @@ LinuxStat::OS.nodename()
485
516
  LinuxStat::OS.os_release()
486
517
  => {: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
518
 
488
- # File: os.rb | Line: 114
519
+ # File: os.rb | Line: 142
489
520
  # Definition: def uptime
490
521
  LinuxStat::OS.uptime()
491
- => {:hour=>8, :minute=>50, :second=>58.38}
522
+ => {:hour=>14, :minute=>24, :second=>12.06}
523
+
524
+ # File: os.rb | Line: 82
525
+ # Definition: def version
526
+ LinuxStat::OS.version()
527
+ => "rolling"
492
528
 
493
529
  ```
494
530
 
@@ -514,29 +550,44 @@ LinuxStat::PCI.devices_info(hwdata:)
514
550
  LinuxStat::PCI.devices_stat(hwdata:)
515
551
  => [{: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...
516
552
 
553
+ # File: pci.rb | Line: 259
554
+ # Definition: def hwdata_file
555
+ LinuxStat::PCI.hwdata_file()
556
+ => "/usr/share/hwdata/pci.ids"
557
+
558
+ # File: pci.rb | Line: 248
559
+ # Definition: def hwdata_file_set?
560
+ LinuxStat::PCI.hwdata_file_set?()
561
+ => true
562
+
563
+ # File: pci.rb | Line: 275
564
+ # Definition: def initialize_hwdata
565
+ LinuxStat::PCI.initialize_hwdata()
566
+ => false
567
+
517
568
  ```
518
569
 
519
570
  ### LinuxStat::PrettifyBytes
520
571
  ```
521
572
  # File: prettify_bytes.rb | Line: 42
522
573
  # Definition: def convert_binary(n)
523
- LinuxStat::PrettifyBytes.convert_binary(n = 339049244499630)
524
- => "308.36 tebibytes"
574
+ LinuxStat::PrettifyBytes.convert_binary(n = 320846048510750)
575
+ => "291.81 tebibytes"
525
576
 
526
577
  # File: prettify_bytes.rb | Line: 19
527
578
  # Definition: def convert_decimal(n)
528
- LinuxStat::PrettifyBytes.convert_decimal(n = 963970414034560)
529
- => "963.97 terabytes"
579
+ LinuxStat::PrettifyBytes.convert_decimal(n = 996984130887475)
580
+ => "996.98 terabytes"
530
581
 
531
582
  # File: prettify_bytes.rb | Line: 90
532
583
  # Definition: def convert_short_binary(n)
533
- LinuxStat::PrettifyBytes.convert_short_binary(n = 954637976904599)
534
- => "868.24 TiB"
584
+ LinuxStat::PrettifyBytes.convert_short_binary(n = 396350966829319)
585
+ => "360.48 TiB"
535
586
 
536
587
  # File: prettify_bytes.rb | Line: 65
537
588
  # Definition: def convert_short_decimal(n)
538
- LinuxStat::PrettifyBytes.convert_short_decimal(n = 464855754781732)
539
- => "464.86 TB"
589
+ LinuxStat::PrettifyBytes.convert_short_decimal(n = 558910893490277)
590
+ => "558.91 TB"
540
591
 
541
592
  ```
542
593
 
@@ -545,17 +596,17 @@ LinuxStat::PrettifyBytes.convert_short_decimal(n = 464855754781732)
545
596
  # File: process.rb | Line: 19
546
597
  # Definition: def count
547
598
  LinuxStat::Process.count()
548
- => 203
599
+ => 210
549
600
 
550
601
  # File: process.rb | Line: 71
551
602
  # Definition: def idle
552
603
  LinuxStat::Process.idle()
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...
604
+ => [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, 164, 166, 169, 170, 173, 175, 180, 181, 182, 183, 184, 185, 186, 188, 231, 275, 315, 323, 333, 3142, 3143, 3144, 3145, 3146, 3147, 20004, 29...
554
605
 
555
606
  # File: process.rb | Line: 8
556
607
  # Definition: def list
557
608
  LinuxStat::Process.list()
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,...
609
+ => [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, 109, 113, 114, 116, 117, 119, 122, 131, 134, 140,...
559
610
 
560
611
  # File: process.rb | Line: 25
561
612
  # Definition: def names
@@ -565,12 +616,12 @@ LinuxStat::Process.names()
565
616
  # File: process.rb | Line: 97
566
617
  # Definition: def running
567
618
  LinuxStat::Process.running()
568
- => [28, 23778, 24066]
619
+ => [34967]
569
620
 
570
621
  # File: process.rb | Line: 58
571
622
  # Definition: def sleeping
572
623
  LinuxStat::Process.sleeping()
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,...
624
+ => [1, 2, 10, 11, 13, 14, 15, 16, 17, 18, 19, 20, 24, 25, 26, 27, 28, 31, 32, 33, 34, 35, 38, 40, 41, 42, 43, 44, 46, 47, 48, 109, 113, 114, 163, 165, 189, 218, 232, 271, 302, 314, 316, 319, 321, 322, 324, 325, 326, 327, 345, 348, 351, 376, 403, 405, 406...
574
625
 
575
626
  # File: process.rb | Line: 37
576
627
  # Definition: def types
@@ -589,7 +640,7 @@ LinuxStat::Process.zombie()
589
640
  # File: process_info.rb | Line: 54
590
641
  # Definition: def cmdline(pid = $$)
591
642
  LinuxStat::ProcessInfo.cmdline(pid)
592
- => "/usr/bin/ruby /home/sourav/.gem/ruby/2.7.0/bin/linuxstat.rb -md"
643
+ => "/usr/bin/ruby /home/sourav/.gem/ruby/2.7.0/bin/linuxstat.rb --markdown"
593
644
 
594
645
  # File: process_info.rb | Line: 78
595
646
  # Definition: def command_name(pid = $$)
@@ -604,7 +655,7 @@ LinuxStat::ProcessInfo.count_cpu(pid)
604
655
  # File: process_info.rb | Line: 247
605
656
  # Definition: def cpu_stat(pid: $$, sleep: ticks_to_ms_t5)
606
657
  LinuxStat::ProcessInfo.cpu_stat(pid:, sleep:)
607
- => {:cpu_usage=>0.0, :threads=>1, :last_executed_cpu=>2}
658
+ => {:cpu_usage=>0.0, :threads=>1, :last_executed_cpu=>3}
608
659
 
609
660
  # File: process_info.rb | Line: 307
610
661
  # Definition: def cpu_usage(pid: $$, sleep: ticks_to_ms_t5)
@@ -619,17 +670,17 @@ LinuxStat::ProcessInfo.gid(pid)
619
670
  # File: process_info.rb | Line: 433
620
671
  # Definition: def last_executed_cpu(pid = $$)
621
672
  LinuxStat::ProcessInfo.last_executed_cpu(pid)
622
- => 2
673
+ => 3
623
674
 
624
675
  # File: process_info.rb | Line: 114
625
676
  # Definition: def mem_stat(pid = $$)
626
677
  LinuxStat::ProcessInfo.mem_stat(pid)
627
- => {:memory=>27025.408, :virtual_memory=>98074.624, :resident_memory=>33210.368}
678
+ => {:memory=>26836.992, :virtual_memory=>97992.704, :resident_memory=>32841.728}
628
679
 
629
680
  # File: process_info.rb | Line: 147
630
681
  # Definition: def memory(pid = $$)
631
682
  LinuxStat::ProcessInfo.memory(pid)
632
- => 27025.408
683
+ => 26836.992
633
684
 
634
685
  # File: process_info.rb | Line: 607
635
686
  # Definition: def nice(pid = $$)
@@ -649,22 +700,22 @@ LinuxStat::ProcessInfo.owner(pid)
649
700
  # File: process_info.rb | Line: 197
650
701
  # Definition: def resident_memory(pid = $$)
651
702
  LinuxStat::ProcessInfo.resident_memory(pid)
652
- => 33210.368
703
+ => 32841.728
653
704
 
654
705
  # File: process_info.rb | Line: 563
655
706
  # Definition: def running_time(pid = $$)
656
707
  LinuxStat::ProcessInfo.running_time(pid)
657
- => 1.05
708
+ => 1.04
658
709
 
659
710
  # File: process_info.rb | Line: 544
660
711
  # Definition: def start_time(pid = $$)
661
712
  LinuxStat::ProcessInfo.start_time(pid)
662
- => 2020-12-27 04:20:42 +0530
713
+ => 2020-12-29 01:58:56 +0530
663
714
 
664
715
  # File: process_info.rb | Line: 513
665
716
  # Definition: def start_time_epoch(pid = $$)
666
717
  LinuxStat::ProcessInfo.start_time_epoch(pid)
667
- => 1609023042
718
+ => 1609187336
668
719
 
669
720
  # File: process_info.rb | Line: 592
670
721
  # Definition: def state(pid = $$)
@@ -684,7 +735,7 @@ LinuxStat::ProcessInfo.threads(pid)
684
735
  # File: process_info.rb | Line: 23
685
736
  # Definition: def total_io(pid = $$)
686
737
  LinuxStat::ProcessInfo.total_io(pid)
687
- => {:read_bytes=>0, :write_bytes=>0}
738
+ => {:read_bytes=>1249280, :write_bytes=>0}
688
739
 
689
740
  # File: process_info.rb | Line: 446
690
741
  # Definition: def uid(pid = $$)
@@ -694,7 +745,7 @@ LinuxStat::ProcessInfo.uid(pid)
694
745
  # File: process_info.rb | Line: 172
695
746
  # Definition: def virtual_memory(pid = $$)
696
747
  LinuxStat::ProcessInfo.virtual_memory(pid)
697
- => 98213.888
748
+ => 97992.704
698
749
 
699
750
  ```
700
751
 
@@ -708,27 +759,27 @@ LinuxStat::Swap.any?()
708
759
  # File: swap.rb | Line: 68
709
760
  # Definition: def available
710
761
  LinuxStat::Swap.available()
711
- => 3759868
762
+ => 2293908
712
763
 
713
764
  # File: swap.rb | Line: 8
714
765
  # Definition: def list
715
766
  LinuxStat::Swap.list()
716
- => {"/dev/zram0"=>[:partition, 4194300, 434432, -2]}
767
+ => {"/dev/zram0"=>[:partition, 4194300, 1900392, -2]}
717
768
 
718
769
  # File: swap.rb | Line: 103
719
770
  # Definition: def percent_available
720
771
  LinuxStat::Swap.percent_available()
721
- => 89.64
772
+ => 54.69
722
773
 
723
774
  # File: swap.rb | Line: 89
724
775
  # Definition: def percent_used
725
776
  LinuxStat::Swap.percent_used()
726
- => 10.36
777
+ => 45.31
727
778
 
728
779
  # File: swap.rb | Line: 32
729
780
  # Definition: def stat
730
781
  LinuxStat::Swap.stat()
731
- => {:total=>4194300, :used=>434432, :available=>3759868, :percent_used=>10.36, :percent_available=>89.64}
782
+ => {:total=>4194300, :used=>1900392, :available=>2293908, :percent_used=>45.31, :percent_available=>54.69}
732
783
 
733
784
  # File: swap.rb | Line: 57
734
785
  # Definition: def total
@@ -738,14 +789,14 @@ LinuxStat::Swap.total()
738
789
  # File: swap.rb | Line: 80
739
790
  # Definition: def used
740
791
  LinuxStat::Swap.used()
741
- => 434432
792
+ => 1900392
742
793
 
743
794
  ```
744
795
 
745
796
  ### LinuxStat::Sysconf
746
797
  ```
747
798
  LinuxStat::Sysconf.child_max()
748
- => 2000000
799
+ => 14915
749
800
 
750
801
  LinuxStat::Sysconf.expr_nest_max()
751
802
  => 32
@@ -765,6 +816,9 @@ LinuxStat::Sysconf.get_uid()
765
816
  LinuxStat::Sysconf.get_user()
766
817
  => "sourav"
767
818
 
819
+ LinuxStat::Sysconf.hostname()
820
+ => "archlinux"
821
+
768
822
  LinuxStat::Sysconf.hostname_max()
769
823
  => 64
770
824
 
@@ -805,17 +859,32 @@ LinuxStat::Sysconf.tty_name_max()
805
859
  # File: usb.rb | Line: 135
806
860
  # Definition: def count
807
861
  LinuxStat::USB.count()
808
- => 11
862
+ => 10
809
863
 
810
864
  # File: usb.rb | Line: 135
811
865
  # Definition: def count
812
866
  LinuxStat::USB.count_devices()
813
- => 11
867
+ => 10
814
868
 
815
869
  # File: usb.rb | Line: 47
816
870
  # Definition: def devices_stat(hwdata: true)
817
871
  LinuxStat::USB.devices_stat(hwdata:)
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...
872
+ => [{:path=>"/sys/bus/usb/devices/1-1.2/", :id=>"04d9:1203", :vendor_id=>"04d9", :product_id=>"1203", :bus_num=>1, :dev_num=>7, :hwdata=>{:vendor=>"Holtek Semiconductor, Inc.", :product=>"Keyboard"}, :authorized=>true, :b_max_power=>"100mA", :b_max_packe...
873
+
874
+ # File: usb.rb | Line: 175
875
+ # Definition: def hwdata_file
876
+ LinuxStat::USB.hwdata_file()
877
+ => "/usr/share/hwdata/usb.ids"
878
+
879
+ # File: usb.rb | Line: 164
880
+ # Definition: def hwdata_file_set?
881
+ LinuxStat::USB.hwdata_file_set?()
882
+ => true
883
+
884
+ # File: usb.rb | Line: 191
885
+ # Definition: def initialize_hwdata
886
+ LinuxStat::USB.initialize_hwdata()
887
+ => false
819
888
 
820
889
  ```
821
890
 
@@ -1007,11 +1076,11 @@ Well this section actually demystifies the methods.
1007
1076
  1. The good old `LinuxStat::CPU.count()`:
1008
1077
 
1009
1078
  It gets the configured CPU for the system. It doesn't count for hotplugged CPU.
1010
- If 3 out of 4 CPU are hotplugged out, it will still show 4. It calles `sysconf(_SC_NPROCESSORS_CONF)`
1079
+ If 3 out of 4 CPU are hotplugged out, it will still show 4. It calls `sysconf(_SC_NPROCESSORS_CONF)`
1011
1080
 
1012
1081
  2. The mysterious `LinuxStat::ProcessInfo.nproc(pid = $$)`:
1013
1082
 
1014
- [ Also aliased to `LinuxStat::ProcessInfo.count_cpu()` ]
1083
+ [ Also aliased to `LinuxStat::ProcessInfo.count_cpu()` ]
1015
1084
 
1016
1085
  It returns the number of processors, like the other 3 methods.
1017
1086
  Without any arguments, it's like running `require 'etc' ; puts Etc.nprocessors`
@@ -1075,7 +1144,7 @@ and parse the output to get an array.
1075
1144
  It's a more robust method that counts the online CPU. It shouldn't fail in most if not all cases!
1076
1145
  But if it fails for some really spooky reasons, it will return nil.
1077
1146
 
1078
- 4. The `LinuxStat::CPU.offline()`:
1147
+ 5. The `LinuxStat::CPU.offline()`:
1079
1148
 
1080
1149
  This returns the number of offline CPU as an Array. It doesn't get affected by taskset or anything.
1081
1150
 
@@ -1093,13 +1162,13 @@ Any n number of CPU can get hotplugged in and out, and this will report that cor
1093
1162
 
1094
1163
  It just gets the info from /sys/devices/system/cpu/offline, and parses the output.
1095
1164
 
1096
- 5. The `LinuxStat::Sysconf.processor_configured()`:
1165
+ 6. The `LinuxStat::Sysconf.processor_configured()`:
1097
1166
 
1098
1167
  Sounds repetitive! Actually yes, this is written in C, and it is called by `LinuxStat::CPU.count`.
1099
1168
 
1100
1169
  The difference is that `LinuxStat::CPU.count` caches the return value, and this method doesn't.
1101
1170
 
1102
- 6. The `LinuxStat::Sysconf.processor_online()`:
1171
+ 7. The `LinuxStat::Sysconf.processor_online()`:
1103
1172
 
1104
1173
  This may again sound repititive to LinuxStat::CPU.online, but it's actually not!
1105
1174
 
@@ -1305,7 +1374,72 @@ irb(main):004:0> LinuxStat::User.get_login
1305
1374
 
1306
1375
  Right, the get_login() can return an empty string. But LinuxStat::User.get_user also aliased as LinuxStat::User.get_current_user shouldn't return an empty string under most circumstances.
1307
1376
 
1308
- ## Note 7: PrettifyBytes
1377
+ ## Note 7: Hwdata
1378
+ The PCI and USB modules actually rely on hwdata found in /usr/share/hwdata/.
1379
+ The LS::USB.devices_stat and LS::PCI.devices_stat returns the information in a Hash:
1380
+
1381
+ ```
1382
+ $ ruby -r linux_stat -e "puts LS::USB.devices_stat.to_s[0..200]"
1383
+ [{:path=>"/sys/bus/usb/devices/1-1.2/", :id=>"04d9:1203", :vendor_id=>"04d9", :product_id=>"1203", :bus_num=>1, :dev_num=>7, :hwdata=>{:vendor=>"Holtek Semiconductor, Inc.", :product=>"Keyboard"}, :aut
1384
+ ```
1385
+
1386
+ But if the files are not available, it won't return hwdata related information.
1387
+
1388
+ So it's suggested to install hwdata. But you might face issues with heroku and
1389
+ other online PaaS where you can't install it. So Version 1.1.1+ comes with a module function called `hwdata_file = file`.
1390
+
1391
+ + You can use any usb.ids or pci.ids files:
1392
+
1393
+ ```
1394
+ LS::PCI.hwdata_file = File.join(__dir__, 'hwdata', 'pci.ids')
1395
+ LS::USB.hwdata_file = File.join(__dir__, 'hwdata', 'usb.ids')
1396
+ ```
1397
+
1398
+ Assuming that you have `pci.ids` and `usb.ids` under ./hwdata directory.
1399
+
1400
+ On rails, you can put this (replace `__dir__` with `Rails.root`) inside environment.rb.
1401
+
1402
+ But do note that the file can be set only once. It's suggested to do that in the beginning of your app.
1403
+
1404
+ + There's one method to check if the hwdata file was already set:
1405
+
1406
+ ```
1407
+ irb(main):001:0' require 'linux_stat'
1408
+ => true
1409
+
1410
+ irb(main):002:0> LS::USB.hwdata_file_set?
1411
+ => false
1412
+
1413
+ irb(main):003:0> LS::USB.devices_stat ; ''
1414
+ => ""
1415
+
1416
+ irb(main):004:0> LS::USB.hwdata_file_set?
1417
+ => true
1418
+ ```
1419
+
1420
+ It works on USB and PCI modules.
1421
+
1422
+ Once the file is set, calling `LS::PCI.hwdata_file = file` is futile.
1423
+
1424
+ + Initializing hwdata can take 0.1 to 0.2 seconds at the first, so there's a method to initialize_hwdata at first:
1425
+
1426
+ ```
1427
+ irb(main):001:0> require 'linux_stat'
1428
+ => true
1429
+
1430
+ irb(main):002:0> LS::PCI.initialize_hwdata
1431
+ => true
1432
+
1433
+ irb(main):003:0> LS::PCI.initialize_hwdata
1434
+ => false
1435
+ ```
1436
+
1437
+ It will return true if it worked, else it will return false. It's intended to be done once.
1438
+
1439
+ If you don't initialize and call methods that utilizes hwdata, they will call it and the first
1440
+ call may take 0.1 to 0.2 seconds, the consecutive calls will then take under a millisecond.
1441
+
1442
+ ## Note 8: PrettifyBytes
1309
1443
  Often times we need to work with KB, MB GB, TB, or KiB, MiB, GiB, TiB, etc.
1310
1444
  And we need some work to convert bytes to those units.
1311
1445
  Because LinuxStat provides a lot of data in bytes, and kilobytes, it's quite tedious to convert them all the time.