linux_stat 1.0.1 → 1.2.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 +250 -92
- data/ext/sysconf/sysconf.c +20 -9
- data/lib/linux_stat.rb +2 -1
- data/lib/linux_stat/net.rb +6 -2
- data/lib/linux_stat/os.rb +57 -20
- data/lib/linux_stat/pci.rb +363 -0
- data/lib/linux_stat/usb.rb +67 -11
- data/lib/linux_stat/version.rb +1 -1
- metadata +4 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c84445d23c56692a85aa620d8529099e4466721d004218ae33c8ae28abdb0980
|
4
|
+
data.tar.gz: e69b74b0b906a8ed3c479c73056ffbf1a2c904deab896ea0fa99fccdc992af9d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1b54691d6ed08d6de27e8040149c61174755dc28be706289228800f399d3b71b73ddbdc13e68bd87be1f78370964e7fecb6c0ad2d764f7d9660fbcebc0318b0b
|
7
|
+
data.tar.gz: 91a45ff49fd6f633acc768fc23d03b6f10b0b47bb56db40a05568ad3ca43b29204fed27a233fc6da45bd3017ad4dc316a66488c71a3aaad78c7fc1a620f6c257
|
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
|
-
|
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.
|
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"=>
|
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=>
|
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
|
-
=>
|
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
|
-
=>
|
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.26, 1=>
|
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=>
|
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
|
-
=>
|
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
|
-
=>
|
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=>
|
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=>
|
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
|
-
=>
|
297
|
+
=> 75552010240
|
272
298
|
|
273
299
|
```
|
274
300
|
|
@@ -277,12 +303,12 @@ LinuxStat::Filesystem.used(fs)
|
|
277
303
|
# File: kernel.rb | Line: 86
|
278
304
|
# Definition: def build_date
|
279
305
|
LinuxStat::Kernel.build_date()
|
280
|
-
=> 2020-
|
306
|
+
=> 2020-12-24 18:28:16 +0000
|
281
307
|
|
282
308
|
# File: kernel.rb | Line: 140
|
283
309
|
# Definition: def build_date_string
|
284
310
|
LinuxStat::Kernel.build_date_string()
|
285
|
-
=> "
|
311
|
+
=> "24 Dec 2020 18:28:16 +0000"
|
286
312
|
|
287
313
|
# File: kernel.rb | Line: 21
|
288
314
|
# Definition: def build_user
|
@@ -307,12 +333,12 @@ LinuxStat::Kernel.compiler_version()
|
|
307
333
|
# File: kernel.rb | Line: 10
|
308
334
|
# Definition: def version
|
309
335
|
LinuxStat::Kernel.release()
|
310
|
-
=> "5.
|
336
|
+
=> "5.10.2-xanmod1-cacule-1-cacule"
|
311
337
|
|
312
338
|
# File: kernel.rb | Line: 169
|
313
339
|
# Definition: def string
|
314
340
|
LinuxStat::Kernel.string()
|
315
|
-
=> "Linux version 5.
|
341
|
+
=> "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
342
|
|
317
343
|
# File: kernel.rb | Line: 179
|
318
344
|
# Definition: def ticks
|
@@ -322,7 +348,7 @@ LinuxStat::Kernel.ticks()
|
|
322
348
|
# File: kernel.rb | Line: 10
|
323
349
|
# Definition: def version
|
324
350
|
LinuxStat::Kernel.version()
|
325
|
-
=> "5.
|
351
|
+
=> "5.10.2-xanmod1-cacule-1-cacule"
|
326
352
|
|
327
353
|
```
|
328
354
|
|
@@ -331,32 +357,32 @@ LinuxStat::Kernel.version()
|
|
331
357
|
# File: memory.rb | Line: 50
|
332
358
|
# Definition: def available
|
333
359
|
LinuxStat::Memory.available()
|
334
|
-
=>
|
360
|
+
=> 375384
|
335
361
|
|
336
362
|
# File: memory.rb | Line: 81
|
337
363
|
# Definition: def percent_available
|
338
364
|
LinuxStat::Memory.percent_available()
|
339
|
-
=>
|
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
|
-
=>
|
370
|
+
=> 90.21
|
345
371
|
|
346
372
|
# File: memory.rb | Line: 11
|
347
373
|
# Definition: def stat
|
348
374
|
LinuxStat::Memory.stat()
|
349
|
-
=> {:total=>
|
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
|
353
379
|
LinuxStat::Memory.total()
|
354
|
-
=>
|
380
|
+
=> 3836036
|
355
381
|
|
356
382
|
# File: memory.rb | Line: 60
|
357
383
|
# Definition: def used
|
358
384
|
LinuxStat::Memory.used()
|
359
|
-
=>
|
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=>
|
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=
|
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", "
|
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/
|
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,85 +436,134 @@ 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 0 0", "/sys/fs/cgroup"=>"tmpfs /sys/fs/cgroup tmpfs ro,nosuid,nodev,noexec,size=4096k,nr_inodes=1024,mode=755 0 0", "/
|
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
|
|
417
443
|
### LinuxStat::Net
|
418
444
|
```
|
419
|
-
# File: net.rb | Line:
|
445
|
+
# File: net.rb | Line: 84
|
420
446
|
# Definition: def usage(interval = 0.1)
|
421
447
|
LinuxStat::Net.current_usage(interval)
|
422
|
-
=> {:received=>
|
448
|
+
=> {:received=>279000.0, :transmitted=>5640.0}
|
423
449
|
|
424
450
|
# File: net.rb | Line: 10
|
425
451
|
# Definition: def ipv4_private
|
426
452
|
LinuxStat::Net.ipv4_private()
|
427
453
|
=> "192.168.0.102"
|
428
454
|
|
429
|
-
# File: net.rb | Line:
|
455
|
+
# File: net.rb | Line: 25
|
430
456
|
# Definition: def total_bytes
|
431
457
|
LinuxStat::Net.total_bytes()
|
432
|
-
=> {:received=>
|
458
|
+
=> {:received=>2093813713, :transmitted=>138899807}
|
433
459
|
|
434
|
-
# File: net.rb | Line:
|
460
|
+
# File: net.rb | Line: 43
|
435
461
|
# Definition: def total_bytes_received
|
436
462
|
LinuxStat::Net.total_bytes_received()
|
437
|
-
=>
|
463
|
+
=> 2093813713
|
438
464
|
|
439
|
-
# File: net.rb | Line:
|
465
|
+
# File: net.rb | Line: 56
|
440
466
|
# Definition: def total_bytes_transmitted
|
441
467
|
LinuxStat::Net.total_bytes_transmitted()
|
442
|
-
=>
|
468
|
+
=> 138899807
|
443
469
|
|
444
|
-
# File: net.rb | Line:
|
470
|
+
# File: net.rb | Line: 84
|
445
471
|
# Definition: def usage(interval = 0.1)
|
446
472
|
LinuxStat::Net.usage(interval)
|
447
|
-
=> {:received=>
|
473
|
+
=> {:received=>419320.0, :transmitted=>10340.0}
|
448
474
|
|
449
475
|
```
|
450
476
|
|
451
477
|
### LinuxStat::OS
|
452
478
|
```
|
453
|
-
# File: os.rb | Line:
|
479
|
+
# File: os.rb | Line: 127
|
454
480
|
# Definition: def bits
|
455
481
|
LinuxStat::OS.bits()
|
456
482
|
=> 64
|
457
483
|
|
458
|
-
# File: os.rb | Line:
|
484
|
+
# File: os.rb | Line: 82
|
485
|
+
# Definition: def version
|
486
|
+
LinuxStat::OS.distrib_version()
|
487
|
+
=> "rolling"
|
488
|
+
|
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:
|
494
|
+
# File: os.rb | Line: 115
|
464
495
|
# Definition: def hostname
|
465
496
|
LinuxStat::OS.hostname()
|
466
497
|
=> "archlinux"
|
467
498
|
|
468
|
-
# File: os.rb | Line:
|
499
|
+
# File: os.rb | Line: 33
|
469
500
|
# Definition: def lsb_release
|
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:
|
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:
|
509
|
+
# File: os.rb | Line: 106
|
479
510
|
# Definition: def nodename
|
480
511
|
LinuxStat::OS.nodename()
|
481
512
|
=> "archlinux"
|
482
513
|
|
483
|
-
# File: os.rb | Line:
|
514
|
+
# File: os.rb | Line: 17
|
484
515
|
# Definition: def os_release
|
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:
|
519
|
+
# File: os.rb | Line: 142
|
489
520
|
# Definition: def uptime
|
490
521
|
LinuxStat::OS.uptime()
|
491
|
-
=> {:hour=>
|
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"
|
528
|
+
|
529
|
+
```
|
530
|
+
|
531
|
+
### LinuxStat::PCI
|
532
|
+
```
|
533
|
+
# File: pci.rb | Line: 211
|
534
|
+
# Definition: def count
|
535
|
+
LinuxStat::PCI.count()
|
536
|
+
=> 13
|
537
|
+
|
538
|
+
# File: pci.rb | Line: 211
|
539
|
+
# Definition: def count
|
540
|
+
LinuxStat::PCI.count_devices()
|
541
|
+
=> 13
|
542
|
+
|
543
|
+
# File: pci.rb | Line: 52
|
544
|
+
# Definition: def devices_info(hwdata: true)
|
545
|
+
LinuxStat::PCI.devices_info(hwdata:)
|
546
|
+
=> [{: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...
|
547
|
+
|
548
|
+
# File: pci.rb | Line: 128
|
549
|
+
# Definition: def devices_stat(hwdata: true)
|
550
|
+
LinuxStat::PCI.devices_stat(hwdata:)
|
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...
|
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
|
492
567
|
|
493
568
|
```
|
494
569
|
|
@@ -496,23 +571,23 @@ LinuxStat::OS.uptime()
|
|
496
571
|
```
|
497
572
|
# File: prettify_bytes.rb | Line: 42
|
498
573
|
# Definition: def convert_binary(n)
|
499
|
-
LinuxStat::PrettifyBytes.convert_binary(n =
|
500
|
-
=> "
|
574
|
+
LinuxStat::PrettifyBytes.convert_binary(n = 320846048510750)
|
575
|
+
=> "291.81 tebibytes"
|
501
576
|
|
502
577
|
# File: prettify_bytes.rb | Line: 19
|
503
578
|
# Definition: def convert_decimal(n)
|
504
|
-
LinuxStat::PrettifyBytes.convert_decimal(n =
|
505
|
-
=> "
|
579
|
+
LinuxStat::PrettifyBytes.convert_decimal(n = 996984130887475)
|
580
|
+
=> "996.98 terabytes"
|
506
581
|
|
507
582
|
# File: prettify_bytes.rb | Line: 90
|
508
583
|
# Definition: def convert_short_binary(n)
|
509
|
-
LinuxStat::PrettifyBytes.convert_short_binary(n =
|
510
|
-
=> "
|
584
|
+
LinuxStat::PrettifyBytes.convert_short_binary(n = 396350966829319)
|
585
|
+
=> "360.48 TiB"
|
511
586
|
|
512
587
|
# File: prettify_bytes.rb | Line: 65
|
513
588
|
# Definition: def convert_short_decimal(n)
|
514
|
-
LinuxStat::PrettifyBytes.convert_short_decimal(n =
|
515
|
-
=> "
|
589
|
+
LinuxStat::PrettifyBytes.convert_short_decimal(n = 558910893490277)
|
590
|
+
=> "558.91 TB"
|
516
591
|
|
517
592
|
```
|
518
593
|
|
@@ -521,37 +596,37 @@ LinuxStat::PrettifyBytes.convert_short_decimal(n = 238518247519978)
|
|
521
596
|
# File: process.rb | Line: 19
|
522
597
|
# Definition: def count
|
523
598
|
LinuxStat::Process.count()
|
524
|
-
=>
|
599
|
+
=> 210
|
525
600
|
|
526
601
|
# File: process.rb | Line: 71
|
527
602
|
# Definition: def idle
|
528
603
|
LinuxStat::Process.idle()
|
529
|
-
=> [3, 4,
|
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...
|
530
605
|
|
531
606
|
# File: process.rb | Line: 8
|
532
607
|
# Definition: def list
|
533
608
|
LinuxStat::Process.list()
|
534
|
-
=> [1, 2, 3, 4,
|
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,...
|
535
610
|
|
536
611
|
# File: process.rb | Line: 25
|
537
612
|
# Definition: def names
|
538
613
|
LinuxStat::Process.names()
|
539
|
-
=> {1=>"systemd", 2=>"kthreadd", 3=>"rcu_gp", 4=>"rcu_par_gp",
|
614
|
+
=> {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
615
|
|
541
616
|
# File: process.rb | Line: 97
|
542
617
|
# Definition: def running
|
543
618
|
LinuxStat::Process.running()
|
544
|
-
=> [
|
619
|
+
=> [34967]
|
545
620
|
|
546
621
|
# File: process.rb | Line: 58
|
547
622
|
# Definition: def sleeping
|
548
623
|
LinuxStat::Process.sleeping()
|
549
|
-
=> [1, 2, 10, 11, 13, 14, 15, 16, 17, 18, 19, 20,
|
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...
|
550
625
|
|
551
626
|
# File: process.rb | Line: 37
|
552
627
|
# Definition: def types
|
553
628
|
LinuxStat::Process.types()
|
554
|
-
=> {1=>:sleeping, 2=>:sleeping, 3=>:idle, 4=>:idle,
|
629
|
+
=> {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
630
|
|
556
631
|
# File: process.rb | Line: 84
|
557
632
|
# Definition: def zombie
|
@@ -565,7 +640,7 @@ LinuxStat::Process.zombie()
|
|
565
640
|
# File: process_info.rb | Line: 54
|
566
641
|
# Definition: def cmdline(pid = $$)
|
567
642
|
LinuxStat::ProcessInfo.cmdline(pid)
|
568
|
-
=> "/usr/bin/ruby /home/sourav/.gem/ruby/2.7.0/bin/linuxstat.rb
|
643
|
+
=> "/usr/bin/ruby /home/sourav/.gem/ruby/2.7.0/bin/linuxstat.rb --markdown"
|
569
644
|
|
570
645
|
# File: process_info.rb | Line: 78
|
571
646
|
# Definition: def command_name(pid = $$)
|
@@ -600,12 +675,12 @@ LinuxStat::ProcessInfo.last_executed_cpu(pid)
|
|
600
675
|
# File: process_info.rb | Line: 114
|
601
676
|
# Definition: def mem_stat(pid = $$)
|
602
677
|
LinuxStat::ProcessInfo.mem_stat(pid)
|
603
|
-
=> {:memory=>
|
678
|
+
=> {:memory=>26836.992, :virtual_memory=>97992.704, :resident_memory=>32841.728}
|
604
679
|
|
605
680
|
# File: process_info.rb | Line: 147
|
606
681
|
# Definition: def memory(pid = $$)
|
607
682
|
LinuxStat::ProcessInfo.memory(pid)
|
608
|
-
=>
|
683
|
+
=> 26836.992
|
609
684
|
|
610
685
|
# File: process_info.rb | Line: 607
|
611
686
|
# Definition: def nice(pid = $$)
|
@@ -625,22 +700,22 @@ LinuxStat::ProcessInfo.owner(pid)
|
|
625
700
|
# File: process_info.rb | Line: 197
|
626
701
|
# Definition: def resident_memory(pid = $$)
|
627
702
|
LinuxStat::ProcessInfo.resident_memory(pid)
|
628
|
-
=>
|
703
|
+
=> 32841.728
|
629
704
|
|
630
705
|
# File: process_info.rb | Line: 563
|
631
706
|
# Definition: def running_time(pid = $$)
|
632
707
|
LinuxStat::ProcessInfo.running_time(pid)
|
633
|
-
=>
|
708
|
+
=> 1.04
|
634
709
|
|
635
710
|
# File: process_info.rb | Line: 544
|
636
711
|
# Definition: def start_time(pid = $$)
|
637
712
|
LinuxStat::ProcessInfo.start_time(pid)
|
638
|
-
=> 2020-12-
|
713
|
+
=> 2020-12-29 01:58:56 +0530
|
639
714
|
|
640
715
|
# File: process_info.rb | Line: 513
|
641
716
|
# Definition: def start_time_epoch(pid = $$)
|
642
717
|
LinuxStat::ProcessInfo.start_time_epoch(pid)
|
643
|
-
=>
|
718
|
+
=> 1609187336
|
644
719
|
|
645
720
|
# File: process_info.rb | Line: 592
|
646
721
|
# Definition: def state(pid = $$)
|
@@ -660,7 +735,7 @@ LinuxStat::ProcessInfo.threads(pid)
|
|
660
735
|
# File: process_info.rb | Line: 23
|
661
736
|
# Definition: def total_io(pid = $$)
|
662
737
|
LinuxStat::ProcessInfo.total_io(pid)
|
663
|
-
=> {:read_bytes=>
|
738
|
+
=> {:read_bytes=>1249280, :write_bytes=>0}
|
664
739
|
|
665
740
|
# File: process_info.rb | Line: 446
|
666
741
|
# Definition: def uid(pid = $$)
|
@@ -670,7 +745,7 @@ LinuxStat::ProcessInfo.uid(pid)
|
|
670
745
|
# File: process_info.rb | Line: 172
|
671
746
|
# Definition: def virtual_memory(pid = $$)
|
672
747
|
LinuxStat::ProcessInfo.virtual_memory(pid)
|
673
|
-
=>
|
748
|
+
=> 97992.704
|
674
749
|
|
675
750
|
```
|
676
751
|
|
@@ -684,27 +759,27 @@ LinuxStat::Swap.any?()
|
|
684
759
|
# File: swap.rb | Line: 68
|
685
760
|
# Definition: def available
|
686
761
|
LinuxStat::Swap.available()
|
687
|
-
=>
|
762
|
+
=> 2293908
|
688
763
|
|
689
764
|
# File: swap.rb | Line: 8
|
690
765
|
# Definition: def list
|
691
766
|
LinuxStat::Swap.list()
|
692
|
-
=> {"/dev/zram0"=>[:partition, 4194300,
|
767
|
+
=> {"/dev/zram0"=>[:partition, 4194300, 1900392, -2]}
|
693
768
|
|
694
769
|
# File: swap.rb | Line: 103
|
695
770
|
# Definition: def percent_available
|
696
771
|
LinuxStat::Swap.percent_available()
|
697
|
-
=>
|
772
|
+
=> 54.69
|
698
773
|
|
699
774
|
# File: swap.rb | Line: 89
|
700
775
|
# Definition: def percent_used
|
701
776
|
LinuxStat::Swap.percent_used()
|
702
|
-
=>
|
777
|
+
=> 45.31
|
703
778
|
|
704
779
|
# File: swap.rb | Line: 32
|
705
780
|
# Definition: def stat
|
706
781
|
LinuxStat::Swap.stat()
|
707
|
-
=> {:total=>4194300, :used=>
|
782
|
+
=> {:total=>4194300, :used=>1900392, :available=>2293908, :percent_used=>45.31, :percent_available=>54.69}
|
708
783
|
|
709
784
|
# File: swap.rb | Line: 57
|
710
785
|
# Definition: def total
|
@@ -714,14 +789,14 @@ LinuxStat::Swap.total()
|
|
714
789
|
# File: swap.rb | Line: 80
|
715
790
|
# Definition: def used
|
716
791
|
LinuxStat::Swap.used()
|
717
|
-
=>
|
792
|
+
=> 1900392
|
718
793
|
|
719
794
|
```
|
720
795
|
|
721
796
|
### LinuxStat::Sysconf
|
722
797
|
```
|
723
798
|
LinuxStat::Sysconf.child_max()
|
724
|
-
=>
|
799
|
+
=> 14915
|
725
800
|
|
726
801
|
LinuxStat::Sysconf.expr_nest_max()
|
727
802
|
=> 32
|
@@ -741,6 +816,9 @@ LinuxStat::Sysconf.get_uid()
|
|
741
816
|
LinuxStat::Sysconf.get_user()
|
742
817
|
=> "sourav"
|
743
818
|
|
819
|
+
LinuxStat::Sysconf.hostname()
|
820
|
+
=> "archlinux"
|
821
|
+
|
744
822
|
LinuxStat::Sysconf.hostname_max()
|
745
823
|
=> 64
|
746
824
|
|
@@ -757,7 +835,7 @@ LinuxStat::Sysconf.pagesize()
|
|
757
835
|
=> 4096
|
758
836
|
|
759
837
|
LinuxStat::Sysconf.posix_version()
|
760
|
-
=>
|
838
|
+
=> 200809
|
761
839
|
|
762
840
|
LinuxStat::Sysconf.processor_configured()
|
763
841
|
=> 4
|
@@ -778,20 +856,35 @@ LinuxStat::Sysconf.tty_name_max()
|
|
778
856
|
|
779
857
|
### LinuxStat::USB
|
780
858
|
```
|
781
|
-
# File: usb.rb | Line:
|
859
|
+
# File: usb.rb | Line: 135
|
782
860
|
# Definition: def count
|
783
861
|
LinuxStat::USB.count()
|
784
862
|
=> 10
|
785
863
|
|
786
|
-
# File: usb.rb | Line:
|
864
|
+
# File: usb.rb | Line: 135
|
787
865
|
# Definition: def count
|
788
866
|
LinuxStat::USB.count_devices()
|
789
867
|
=> 10
|
790
868
|
|
791
|
-
# File: usb.rb | Line:
|
869
|
+
# File: usb.rb | Line: 47
|
792
870
|
# Definition: def devices_stat(hwdata: true)
|
793
871
|
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=>
|
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
|
795
888
|
|
796
889
|
```
|
797
890
|
|
@@ -804,13 +897,13 @@ LinuxStat::Uname.nodename()
|
|
804
897
|
=> "archlinux"
|
805
898
|
|
806
899
|
LinuxStat::Uname.release()
|
807
|
-
=> "5.
|
900
|
+
=> "5.10.2-xanmod1-cacule-1-cacule"
|
808
901
|
|
809
902
|
LinuxStat::Uname.sysname()
|
810
903
|
=> "Linux"
|
811
904
|
|
812
905
|
LinuxStat::Uname.version()
|
813
|
-
=> "#1 SMP PREEMPT
|
906
|
+
=> "#1 SMP PREEMPT Thu, 24 Dec 2020 18:28:16 +0000"
|
814
907
|
|
815
908
|
```
|
816
909
|
|
@@ -983,11 +1076,11 @@ Well this section actually demystifies the methods.
|
|
983
1076
|
1. The good old `LinuxStat::CPU.count()`:
|
984
1077
|
|
985
1078
|
It gets the configured CPU for the system. It doesn't count for hotplugged CPU.
|
986
|
-
If 3 out of 4 CPU are hotplugged out, it will still show 4. It
|
1079
|
+
If 3 out of 4 CPU are hotplugged out, it will still show 4. It calls `sysconf(_SC_NPROCESSORS_CONF)`
|
987
1080
|
|
988
1081
|
2. The mysterious `LinuxStat::ProcessInfo.nproc(pid = $$)`:
|
989
1082
|
|
990
|
-
[ Also aliased to `LinuxStat::ProcessInfo.count_cpu()`
|
1083
|
+
[ Also aliased to `LinuxStat::ProcessInfo.count_cpu()` ]
|
991
1084
|
|
992
1085
|
It returns the number of processors, like the other 3 methods.
|
993
1086
|
Without any arguments, it's like running `require 'etc' ; puts Etc.nprocessors`
|
@@ -1051,7 +1144,7 @@ and parse the output to get an array.
|
|
1051
1144
|
It's a more robust method that counts the online CPU. It shouldn't fail in most if not all cases!
|
1052
1145
|
But if it fails for some really spooky reasons, it will return nil.
|
1053
1146
|
|
1054
|
-
|
1147
|
+
5. The `LinuxStat::CPU.offline()`:
|
1055
1148
|
|
1056
1149
|
This returns the number of offline CPU as an Array. It doesn't get affected by taskset or anything.
|
1057
1150
|
|
@@ -1069,13 +1162,13 @@ Any n number of CPU can get hotplugged in and out, and this will report that cor
|
|
1069
1162
|
|
1070
1163
|
It just gets the info from /sys/devices/system/cpu/offline, and parses the output.
|
1071
1164
|
|
1072
|
-
|
1165
|
+
6. The `LinuxStat::Sysconf.processor_configured()`:
|
1073
1166
|
|
1074
1167
|
Sounds repetitive! Actually yes, this is written in C, and it is called by `LinuxStat::CPU.count`.
|
1075
1168
|
|
1076
1169
|
The difference is that `LinuxStat::CPU.count` caches the return value, and this method doesn't.
|
1077
1170
|
|
1078
|
-
|
1171
|
+
7. The `LinuxStat::Sysconf.processor_online()`:
|
1079
1172
|
|
1080
1173
|
This may again sound repititive to LinuxStat::CPU.online, but it's actually not!
|
1081
1174
|
|
@@ -1281,7 +1374,72 @@ irb(main):004:0> LinuxStat::User.get_login
|
|
1281
1374
|
|
1282
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.
|
1283
1376
|
|
1284
|
-
## Note 7:
|
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
|
1285
1443
|
Often times we need to work with KB, MB GB, TB, or KiB, MiB, GiB, TiB, etc.
|
1286
1444
|
And we need some work to convert bytes to those units.
|
1287
1445
|
Because LinuxStat provides a lot of data in bytes, and kilobytes, it's quite tedious to convert them all the time.
|