linux_stat 1.1.0 → 1.1.1
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 +184 -70
- data/lib/linux_stat.rb +1 -1
- data/lib/linux_stat/pci.rb +55 -3
- data/lib/linux_stat/usb.rb +53 -1
- data/lib/linux_stat/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 15d0c0fba26992b304c1f9983d172e283fe918dedc76eb7f3cfd86a274b974b4
|
4
|
+
data.tar.gz: bf5d4b822e2c0ab4f45d677a84172d33aea0d17df509e6000737cac9625c429f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 725d00aa53ffeb4054389ae9ddf4af843cc57dfda0bcb3128500795c735b6b6e28bba7bd42b1873babc508bbdc5036ae294c105422000305c4e1a8a70247efaa
|
7
|
+
data.tar.gz: 88d1f1939e2f7982d3cf6501f62e8974cb09e889dcf5e2c5132ae996a78d096b2ef1138e8be1ebd2cd93b1d6d3f53ade3696ac95a0eecbef6ea306ed1488588d
|
data/README.md
CHANGED
@@ -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:
|
@@ -88,7 +114,7 @@ LinuxStat::BIOS.version()
|
|
88
114
|
# File: battery.rb | Line: 105
|
89
115
|
# Definition: def charge
|
90
116
|
LinuxStat::Battery.charge()
|
91
|
-
=>
|
117
|
+
=> 95.73550551030186
|
92
118
|
|
93
119
|
# File: battery.rb | Line: 122
|
94
120
|
# Definition: def charge_full_design_wh
|
@@ -108,7 +134,7 @@ LinuxStat::Battery.charging?()
|
|
108
134
|
# File: battery.rb | Line: 184
|
109
135
|
# Definition: def devices_stat
|
110
136
|
LinuxStat::Battery.devices_stat()
|
111
|
-
=> {:AC=>{:type=>"Mains", :online=>1}, :BAT0=>{:model=>"DELL CYMGM77", :manufacturer=>"Samsung SDI", :type=>"Battery", :status=>"
|
137
|
+
=> {:AC=>{:type=>"Mains", :online=>1}, :BAT0=>{:model=>"DELL CYMGM77", :manufacturer=>"Samsung SDI", :type=>"Battery", :status=>"Charging", :capacity=>95, :voltage_min_design=>11.4, :charge_full_design=>3.684, :charge_full_design_wh=>42.0, :voltage_now=>...
|
112
138
|
|
113
139
|
# File: battery.rb | Line: 87
|
114
140
|
# Definition: def discharging?
|
@@ -118,7 +144,7 @@ LinuxStat::Battery.discharging?()
|
|
118
144
|
# File: battery.rb | Line: 96
|
119
145
|
# Definition: def full?
|
120
146
|
LinuxStat::Battery.full?()
|
121
|
-
=>
|
147
|
+
=> false
|
122
148
|
|
123
149
|
# File: battery.rb | Line: 47
|
124
150
|
# Definition: def manufacturer
|
@@ -138,12 +164,12 @@ LinuxStat::Battery.present?()
|
|
138
164
|
# File: battery.rb | Line: 16
|
139
165
|
# Definition: def stat
|
140
166
|
LinuxStat::Battery.stat()
|
141
|
-
=> {:model=>"DELL CYMGM77", :manufacturer=>"Samsung SDI", :technology=>"Li-ion", :status=>"
|
167
|
+
=> {:model=>"DELL CYMGM77", :manufacturer=>"Samsung SDI", :technology=>"Li-ion", :status=>"Charging", :charge=>95.73550551030186, :charging=>true, :discharging=>false, :full=>false}
|
142
168
|
|
143
169
|
# File: battery.rb | Line: 68
|
144
170
|
# Definition: def status
|
145
171
|
LinuxStat::Battery.status()
|
146
|
-
=> "
|
172
|
+
=> "Charging"
|
147
173
|
|
148
174
|
# File: battery.rb | Line: 57
|
149
175
|
# Definition: def technology
|
@@ -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.887
|
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"=>2000115, "cpu1"=>2000016, "cpu2"=>2000066, "cpu3"=>2000240}
|
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=>19.05, 1=>20.0, 2=>16.67, 3=>16.67, 4=>16.67}
|
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
|
+
=> 5.0
|
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
|
+
=> 0.0
|
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=>
|
256
|
+
=> {0=>13.64, 1=>0.0, 2=>16.67, 3=>0.0, 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=>10866159, :block_avail_unpriv=>10866159, :inodes=>58612160, :free_inodes=>56826110, :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
|
+
=> 44507787264
|
247
273
|
|
248
274
|
# File: filesystem.rb | Line: 58
|
249
275
|
# Definition: def free(fs = ?..freeze)
|
250
276
|
LinuxStat::Filesystem.free(fs)
|
251
|
-
=>
|
277
|
+
=> 44507787264
|
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=>44507787264, :used=>75473403904}
|
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=>10866159, :block_avail_unpriv=>10866159, :inodes=>58612160, :free_inodes=>56826110, :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
|
+
=> 75473403904
|
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
|
-
=>
|
360
|
+
=> 477784
|
335
361
|
|
336
362
|
# File: memory.rb | Line: 81
|
337
363
|
# Definition: def percent_available
|
338
364
|
LinuxStat::Memory.percent_available()
|
339
|
-
=>
|
365
|
+
=> 12.46
|
340
366
|
|
341
367
|
# File: memory.rb | Line: 70
|
342
368
|
# Definition: def percent_used
|
343
369
|
LinuxStat::Memory.percent_used()
|
344
|
-
=>
|
370
|
+
=> 87.54
|
345
371
|
|
346
372
|
# File: memory.rb | Line: 11
|
347
373
|
# Definition: def stat
|
348
374
|
LinuxStat::Memory.stat()
|
349
|
-
=> {:total=>3836036, :used=>
|
375
|
+
=> {:total=>3836036, :used=>3358252, :available=>477784, :percent_used=>87.54, :percent_available=>12.46}
|
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
|
-
=>
|
385
|
+
=> 3358252
|
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=>44507787264, :available=>44507787264, :used=>75473403904, :percent_used=>62.9, :percent_free=>37.1, :percent_available=>37.1}
|
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/1000", "devpts"=>"/dev/pts", "cgroup2"=>"/sys/fs/cgroup/unified", "cgroup"=>"/sys/fs/cgroup/
|
414
|
+
=> {"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/cpuset", "pstore"=>"...
|
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", "/
|
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
|
|
@@ -429,17 +455,17 @@ 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=>
|
458
|
+
=> {:received=>473253199, :transmitted=>35211379}
|
433
459
|
|
434
460
|
# File: net.rb | Line: 43
|
435
461
|
# Definition: def total_bytes_received
|
436
462
|
LinuxStat::Net.total_bytes_received()
|
437
|
-
=>
|
463
|
+
=> 473253199
|
438
464
|
|
439
465
|
# File: net.rb | Line: 56
|
440
466
|
# Definition: def total_bytes_transmitted
|
441
467
|
LinuxStat::Net.total_bytes_transmitted()
|
442
|
-
=>
|
468
|
+
=> 35211379
|
443
469
|
|
444
470
|
# File: net.rb | Line: 84
|
445
471
|
# Definition: def usage(interval = 0.1)
|
@@ -488,7 +514,7 @@ LinuxStat::OS.os_release()
|
|
488
514
|
# File: os.rb | Line: 114
|
489
515
|
# Definition: def uptime
|
490
516
|
LinuxStat::OS.uptime()
|
491
|
-
=> {:hour=>
|
517
|
+
=> {:hour=>9, :minute=>25, :second=>50.38}
|
492
518
|
|
493
519
|
```
|
494
520
|
|
@@ -514,29 +540,44 @@ LinuxStat::PCI.devices_info(hwdata:)
|
|
514
540
|
LinuxStat::PCI.devices_stat(hwdata:)
|
515
541
|
=> [{: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
542
|
|
543
|
+
# File: pci.rb | Line: 259
|
544
|
+
# Definition: def hwdata_file
|
545
|
+
LinuxStat::PCI.hwdata_file()
|
546
|
+
=> "/usr/share/hwdata/pci.ids"
|
547
|
+
|
548
|
+
# File: pci.rb | Line: 248
|
549
|
+
# Definition: def hwdata_file_set?
|
550
|
+
LinuxStat::PCI.hwdata_file_set?()
|
551
|
+
=> true
|
552
|
+
|
553
|
+
# File: pci.rb | Line: 275
|
554
|
+
# Definition: def initialize_hwdata
|
555
|
+
LinuxStat::PCI.initialize_hwdata()
|
556
|
+
=> false
|
557
|
+
|
517
558
|
```
|
518
559
|
|
519
560
|
### LinuxStat::PrettifyBytes
|
520
561
|
```
|
521
562
|
# File: prettify_bytes.rb | Line: 42
|
522
563
|
# Definition: def convert_binary(n)
|
523
|
-
LinuxStat::PrettifyBytes.convert_binary(n =
|
524
|
-
=> "
|
564
|
+
LinuxStat::PrettifyBytes.convert_binary(n = 419383956999155)
|
565
|
+
=> "381.43 tebibytes"
|
525
566
|
|
526
567
|
# File: prettify_bytes.rb | Line: 19
|
527
568
|
# Definition: def convert_decimal(n)
|
528
|
-
LinuxStat::PrettifyBytes.convert_decimal(n =
|
529
|
-
=> "
|
569
|
+
LinuxStat::PrettifyBytes.convert_decimal(n = 74171973456499)
|
570
|
+
=> "74.17 terabytes"
|
530
571
|
|
531
572
|
# File: prettify_bytes.rb | Line: 90
|
532
573
|
# Definition: def convert_short_binary(n)
|
533
|
-
LinuxStat::PrettifyBytes.convert_short_binary(n =
|
534
|
-
=> "
|
574
|
+
LinuxStat::PrettifyBytes.convert_short_binary(n = 992896974803970)
|
575
|
+
=> "903.03 TiB"
|
535
576
|
|
536
577
|
# File: prettify_bytes.rb | Line: 65
|
537
578
|
# Definition: def convert_short_decimal(n)
|
538
|
-
LinuxStat::PrettifyBytes.convert_short_decimal(n =
|
539
|
-
=> "
|
579
|
+
LinuxStat::PrettifyBytes.convert_short_decimal(n = 448181119260617)
|
580
|
+
=> "448.18 TB"
|
540
581
|
|
541
582
|
```
|
542
583
|
|
@@ -545,17 +586,17 @@ LinuxStat::PrettifyBytes.convert_short_decimal(n = 464855754781732)
|
|
545
586
|
# File: process.rb | Line: 19
|
546
587
|
# Definition: def count
|
547
588
|
LinuxStat::Process.count()
|
548
|
-
=>
|
589
|
+
=> 199
|
549
590
|
|
550
591
|
# File: process.rb | Line: 71
|
551
592
|
# Definition: def idle
|
552
593
|
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,
|
594
|
+
=> [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, 10193, 11...
|
554
595
|
|
555
596
|
# File: process.rb | Line: 8
|
556
597
|
# Definition: def list
|
557
598
|
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,
|
599
|
+
=> [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
600
|
|
560
601
|
# File: process.rb | Line: 25
|
561
602
|
# Definition: def names
|
@@ -565,12 +606,12 @@ LinuxStat::Process.names()
|
|
565
606
|
# File: process.rb | Line: 97
|
566
607
|
# Definition: def running
|
567
608
|
LinuxStat::Process.running()
|
568
|
-
=> [
|
609
|
+
=> [4259, 12094, 13037]
|
569
610
|
|
570
611
|
# File: process.rb | Line: 58
|
571
612
|
# Definition: def sleeping
|
572
613
|
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,
|
614
|
+
=> [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, 109, 113, 114, 163, 165, 189, 218, 232, 271, 302, 314, 316, 319, 321, 322, 324, 325, 326, 327, 345, 348, 376, 403, 405, 406,...
|
574
615
|
|
575
616
|
# File: process.rb | Line: 37
|
576
617
|
# Definition: def types
|
@@ -604,7 +645,7 @@ LinuxStat::ProcessInfo.count_cpu(pid)
|
|
604
645
|
# File: process_info.rb | Line: 247
|
605
646
|
# Definition: def cpu_stat(pid: $$, sleep: ticks_to_ms_t5)
|
606
647
|
LinuxStat::ProcessInfo.cpu_stat(pid:, sleep:)
|
607
|
-
=> {:cpu_usage=>0.0, :threads=>1, :last_executed_cpu=>
|
648
|
+
=> {:cpu_usage=>0.0, :threads=>1, :last_executed_cpu=>3}
|
608
649
|
|
609
650
|
# File: process_info.rb | Line: 307
|
610
651
|
# Definition: def cpu_usage(pid: $$, sleep: ticks_to_ms_t5)
|
@@ -619,17 +660,17 @@ LinuxStat::ProcessInfo.gid(pid)
|
|
619
660
|
# File: process_info.rb | Line: 433
|
620
661
|
# Definition: def last_executed_cpu(pid = $$)
|
621
662
|
LinuxStat::ProcessInfo.last_executed_cpu(pid)
|
622
|
-
=>
|
663
|
+
=> 3
|
623
664
|
|
624
665
|
# File: process_info.rb | Line: 114
|
625
666
|
# Definition: def mem_stat(pid = $$)
|
626
667
|
LinuxStat::ProcessInfo.mem_stat(pid)
|
627
|
-
=> {:memory=>
|
668
|
+
=> {:memory=>26685.44, :virtual_memory=>97878.016, :resident_memory=>32849.92}
|
628
669
|
|
629
670
|
# File: process_info.rb | Line: 147
|
630
671
|
# Definition: def memory(pid = $$)
|
631
672
|
LinuxStat::ProcessInfo.memory(pid)
|
632
|
-
=>
|
673
|
+
=> 26685.44
|
633
674
|
|
634
675
|
# File: process_info.rb | Line: 607
|
635
676
|
# Definition: def nice(pid = $$)
|
@@ -649,22 +690,22 @@ LinuxStat::ProcessInfo.owner(pid)
|
|
649
690
|
# File: process_info.rb | Line: 197
|
650
691
|
# Definition: def resident_memory(pid = $$)
|
651
692
|
LinuxStat::ProcessInfo.resident_memory(pid)
|
652
|
-
=>
|
693
|
+
=> 32849.92
|
653
694
|
|
654
695
|
# File: process_info.rb | Line: 563
|
655
696
|
# Definition: def running_time(pid = $$)
|
656
697
|
LinuxStat::ProcessInfo.running_time(pid)
|
657
|
-
=> 1.
|
698
|
+
=> 1.04
|
658
699
|
|
659
700
|
# File: process_info.rb | Line: 544
|
660
701
|
# Definition: def start_time(pid = $$)
|
661
702
|
LinuxStat::ProcessInfo.start_time(pid)
|
662
|
-
=> 2020-12-
|
703
|
+
=> 2020-12-28 21:00:34 +0530
|
663
704
|
|
664
705
|
# File: process_info.rb | Line: 513
|
665
706
|
# Definition: def start_time_epoch(pid = $$)
|
666
707
|
LinuxStat::ProcessInfo.start_time_epoch(pid)
|
667
|
-
=>
|
708
|
+
=> 1609169434
|
668
709
|
|
669
710
|
# File: process_info.rb | Line: 592
|
670
711
|
# Definition: def state(pid = $$)
|
@@ -684,7 +725,7 @@ LinuxStat::ProcessInfo.threads(pid)
|
|
684
725
|
# File: process_info.rb | Line: 23
|
685
726
|
# Definition: def total_io(pid = $$)
|
686
727
|
LinuxStat::ProcessInfo.total_io(pid)
|
687
|
-
=> {:read_bytes=>
|
728
|
+
=> {:read_bytes=>86016, :write_bytes=>0}
|
688
729
|
|
689
730
|
# File: process_info.rb | Line: 446
|
690
731
|
# Definition: def uid(pid = $$)
|
@@ -694,7 +735,7 @@ LinuxStat::ProcessInfo.uid(pid)
|
|
694
735
|
# File: process_info.rb | Line: 172
|
695
736
|
# Definition: def virtual_memory(pid = $$)
|
696
737
|
LinuxStat::ProcessInfo.virtual_memory(pid)
|
697
|
-
=>
|
738
|
+
=> 98148.352
|
698
739
|
|
699
740
|
```
|
700
741
|
|
@@ -708,27 +749,27 @@ LinuxStat::Swap.any?()
|
|
708
749
|
# File: swap.rb | Line: 68
|
709
750
|
# Definition: def available
|
710
751
|
LinuxStat::Swap.available()
|
711
|
-
=>
|
752
|
+
=> 2912056
|
712
753
|
|
713
754
|
# File: swap.rb | Line: 8
|
714
755
|
# Definition: def list
|
715
756
|
LinuxStat::Swap.list()
|
716
|
-
=> {"/dev/zram0"=>[:partition, 4194300,
|
757
|
+
=> {"/dev/zram0"=>[:partition, 4194300, 1282244, -2]}
|
717
758
|
|
718
759
|
# File: swap.rb | Line: 103
|
719
760
|
# Definition: def percent_available
|
720
761
|
LinuxStat::Swap.percent_available()
|
721
|
-
=>
|
762
|
+
=> 69.43
|
722
763
|
|
723
764
|
# File: swap.rb | Line: 89
|
724
765
|
# Definition: def percent_used
|
725
766
|
LinuxStat::Swap.percent_used()
|
726
|
-
=>
|
767
|
+
=> 30.57
|
727
768
|
|
728
769
|
# File: swap.rb | Line: 32
|
729
770
|
# Definition: def stat
|
730
771
|
LinuxStat::Swap.stat()
|
731
|
-
=> {:total=>4194300, :used=>
|
772
|
+
=> {:total=>4194300, :used=>1282244, :available=>2912056, :percent_used=>30.57, :percent_available=>69.43}
|
732
773
|
|
733
774
|
# File: swap.rb | Line: 57
|
734
775
|
# Definition: def total
|
@@ -738,14 +779,14 @@ LinuxStat::Swap.total()
|
|
738
779
|
# File: swap.rb | Line: 80
|
739
780
|
# Definition: def used
|
740
781
|
LinuxStat::Swap.used()
|
741
|
-
=>
|
782
|
+
=> 1282244
|
742
783
|
|
743
784
|
```
|
744
785
|
|
745
786
|
### LinuxStat::Sysconf
|
746
787
|
```
|
747
788
|
LinuxStat::Sysconf.child_max()
|
748
|
-
=>
|
789
|
+
=> 14915
|
749
790
|
|
750
791
|
LinuxStat::Sysconf.expr_nest_max()
|
751
792
|
=> 32
|
@@ -805,17 +846,32 @@ LinuxStat::Sysconf.tty_name_max()
|
|
805
846
|
# File: usb.rb | Line: 135
|
806
847
|
# Definition: def count
|
807
848
|
LinuxStat::USB.count()
|
808
|
-
=>
|
849
|
+
=> 10
|
809
850
|
|
810
851
|
# File: usb.rb | Line: 135
|
811
852
|
# Definition: def count
|
812
853
|
LinuxStat::USB.count_devices()
|
813
|
-
=>
|
854
|
+
=> 10
|
814
855
|
|
815
856
|
# File: usb.rb | Line: 47
|
816
857
|
# Definition: def devices_stat(hwdata: true)
|
817
858
|
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=>
|
859
|
+
=> [{: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...
|
860
|
+
|
861
|
+
# File: usb.rb | Line: 175
|
862
|
+
# Definition: def hwdata_file
|
863
|
+
LinuxStat::USB.hwdata_file()
|
864
|
+
=> "/usr/share/hwdata/usb.ids"
|
865
|
+
|
866
|
+
# File: usb.rb | Line: 164
|
867
|
+
# Definition: def hwdata_file_set?
|
868
|
+
LinuxStat::USB.hwdata_file_set?()
|
869
|
+
=> true
|
870
|
+
|
871
|
+
# File: usb.rb | Line: 191
|
872
|
+
# Definition: def initialize_hwdata
|
873
|
+
LinuxStat::USB.initialize_hwdata()
|
874
|
+
=> false
|
819
875
|
|
820
876
|
```
|
821
877
|
|
@@ -1007,11 +1063,11 @@ Well this section actually demystifies the methods.
|
|
1007
1063
|
1. The good old `LinuxStat::CPU.count()`:
|
1008
1064
|
|
1009
1065
|
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
|
1066
|
+
If 3 out of 4 CPU are hotplugged out, it will still show 4. It calls `sysconf(_SC_NPROCESSORS_CONF)`
|
1011
1067
|
|
1012
1068
|
2. The mysterious `LinuxStat::ProcessInfo.nproc(pid = $$)`:
|
1013
1069
|
|
1014
|
-
[ Also aliased to `LinuxStat::ProcessInfo.count_cpu()`
|
1070
|
+
[ Also aliased to `LinuxStat::ProcessInfo.count_cpu()` ]
|
1015
1071
|
|
1016
1072
|
It returns the number of processors, like the other 3 methods.
|
1017
1073
|
Without any arguments, it's like running `require 'etc' ; puts Etc.nprocessors`
|
@@ -1075,7 +1131,7 @@ and parse the output to get an array.
|
|
1075
1131
|
It's a more robust method that counts the online CPU. It shouldn't fail in most if not all cases!
|
1076
1132
|
But if it fails for some really spooky reasons, it will return nil.
|
1077
1133
|
|
1078
|
-
|
1134
|
+
5. The `LinuxStat::CPU.offline()`:
|
1079
1135
|
|
1080
1136
|
This returns the number of offline CPU as an Array. It doesn't get affected by taskset or anything.
|
1081
1137
|
|
@@ -1093,13 +1149,13 @@ Any n number of CPU can get hotplugged in and out, and this will report that cor
|
|
1093
1149
|
|
1094
1150
|
It just gets the info from /sys/devices/system/cpu/offline, and parses the output.
|
1095
1151
|
|
1096
|
-
|
1152
|
+
6. The `LinuxStat::Sysconf.processor_configured()`:
|
1097
1153
|
|
1098
1154
|
Sounds repetitive! Actually yes, this is written in C, and it is called by `LinuxStat::CPU.count`.
|
1099
1155
|
|
1100
1156
|
The difference is that `LinuxStat::CPU.count` caches the return value, and this method doesn't.
|
1101
1157
|
|
1102
|
-
|
1158
|
+
7. The `LinuxStat::Sysconf.processor_online()`:
|
1103
1159
|
|
1104
1160
|
This may again sound repititive to LinuxStat::CPU.online, but it's actually not!
|
1105
1161
|
|
@@ -1305,7 +1361,65 @@ irb(main):004:0> LinuxStat::User.get_login
|
|
1305
1361
|
|
1306
1362
|
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
1363
|
|
1308
|
-
## Note 7:
|
1364
|
+
## Note 7: Hwdata
|
1365
|
+
The PCI and USB modules actually rely on hwdata found in /usr/share/hwdata/.
|
1366
|
+
But if the directory is not available, it won't show hwdata related information.
|
1367
|
+
|
1368
|
+
So it's suggested to install hwdata. But you might face issues with heroku and
|
1369
|
+
other online PaaS where you can't install it. So Version 1.1.1+ comes with a module function called `hwdata_file = file`.
|
1370
|
+
|
1371
|
+
+ You can use any usb.ids or pci.ids files:
|
1372
|
+
|
1373
|
+
```
|
1374
|
+
LS::PCI.hwdata_file = File.join(__dir__, 'hwdata', 'pci.ids')
|
1375
|
+
LS::USB.hwdata_file = File.join(__dir__, 'hwdata', 'usb.ids')
|
1376
|
+
```
|
1377
|
+
|
1378
|
+
Assuming that you have `pci.ids` and `usb.ids` under ./hwdata directory.
|
1379
|
+
|
1380
|
+
On rails, you can put this (replace `__dir__` with `Rails.root` inside environment.rb).
|
1381
|
+
|
1382
|
+
But do note that the file can be set only once. It's suggested to do that in the beginning of your app.
|
1383
|
+
|
1384
|
+
+ There's one method to check if the hwdata file was already set:
|
1385
|
+
|
1386
|
+
```
|
1387
|
+
irb(main):001:0' require 'linux_stat'
|
1388
|
+
=> true
|
1389
|
+
|
1390
|
+
irb(main):002:0> LS::USB.hwdata_file_set?
|
1391
|
+
=> false
|
1392
|
+
|
1393
|
+
irb(main):003:0> LS::USB.devices_stat ; ''
|
1394
|
+
=> ""
|
1395
|
+
|
1396
|
+
irb(main):004:0> LS::USB.hwdata_file_set?
|
1397
|
+
=> true
|
1398
|
+
```
|
1399
|
+
|
1400
|
+
It works on USB and PCI modules.
|
1401
|
+
|
1402
|
+
Once the file is set, calling `LS::PCI.hwdata_file = file` is futile.
|
1403
|
+
|
1404
|
+
+ Initializing hwdata can take 0.1 to 0.2 seconds at the first, so there's a method to initialize_hwdata at first:
|
1405
|
+
|
1406
|
+
```
|
1407
|
+
irb(main):001:0> require 'linux_stat'
|
1408
|
+
=> true
|
1409
|
+
|
1410
|
+
irb(main):002:0> LS::PCI.initialize_hwdata
|
1411
|
+
=> true
|
1412
|
+
|
1413
|
+
irb(main):003:0> LS::PCI.initialize_hwdata
|
1414
|
+
=> false
|
1415
|
+
```
|
1416
|
+
|
1417
|
+
It will return true if it worked, else it will return false. It's intended to be done once.
|
1418
|
+
|
1419
|
+
If you don't initialize and call methods that utilizes hwdata, they will call it and the first
|
1420
|
+
call may take 0.1 to 0.2 seconds, the consecutive calls will then take under a millisecond.
|
1421
|
+
|
1422
|
+
## Note 8: PrettifyBytes
|
1309
1423
|
Often times we need to work with KB, MB GB, TB, or KiB, MiB, GiB, TiB, etc.
|
1310
1424
|
And we need some work to convert bytes to those units.
|
1311
1425
|
Because LinuxStat provides a lot of data in bytes, and kilobytes, it's quite tedious to convert them all the time.
|
data/lib/linux_stat.rb
CHANGED
@@ -15,8 +15,8 @@
|
|
15
15
|
|
16
16
|
# Miscellaneous Modules
|
17
17
|
# Independed and LinuxStat's miscellaneous modules
|
18
|
-
require "linux_stat/version"
|
19
18
|
require 'linux_stat/prettify_bytes'
|
19
|
+
require "linux_stat/version"
|
20
20
|
|
21
21
|
# Independed Modules
|
22
22
|
# Modules that doesn't have any dependency on its own
|
data/lib/linux_stat/pci.rb
CHANGED
@@ -6,11 +6,11 @@ module LinuxStat
|
|
6
6
|
#
|
7
7
|
# [ Not to be confused with devices_stat ]
|
8
8
|
#
|
9
|
-
# Take a look at
|
9
|
+
# Take a look at LinuxStat::PCI.devices_stat for more info.
|
10
10
|
#
|
11
11
|
# Returns details about the devices found in /proc/bus/pci/devices file.
|
12
12
|
#
|
13
|
-
# The details doesn't contain a lot of details, it
|
13
|
+
# The details doesn't contain a lot of details, it opens just one file.
|
14
14
|
#
|
15
15
|
# The return value is an Array of multiple Hashes. If there's no info available,
|
16
16
|
# it will rather return an empty Array.
|
@@ -227,11 +227,63 @@ module LinuxStat
|
|
227
227
|
end
|
228
228
|
end
|
229
229
|
|
230
|
+
##
|
231
|
+
# hwdata_file = file
|
232
|
+
#
|
233
|
+
# Lets you set the hwdata_file about pci.ids.
|
234
|
+
#
|
235
|
+
# The hwdata file about pci.ids contains vendor name and product name information about
|
236
|
+
# devices. This is then mapped by the other methods that utilizes hwdata/pci.ids.
|
237
|
+
#
|
238
|
+
# Do note that this method is intended to run only once, at the beginning.
|
239
|
+
# If you use any other method that utilizes hwdata/pci.ids, before
|
240
|
+
# calling this method, this method will not work.
|
241
|
+
def hwdata_file=(file)
|
242
|
+
@@hwdata_file ||= file.freeze
|
243
|
+
end
|
244
|
+
|
245
|
+
##
|
246
|
+
# Checks if hwdata_file is already initialized or not.
|
247
|
+
# Once it's initialized, calling hwdata_file = 'something/pci.ids' is futile.
|
248
|
+
def hwdata_file_set?
|
249
|
+
@@hwdata_file ||= false
|
250
|
+
!!@@hwdata_file
|
251
|
+
end
|
252
|
+
|
253
|
+
##
|
254
|
+
# Returns the hwdata_file as string.
|
255
|
+
#
|
256
|
+
# If hwdata_file isn't set, it will return an empty frozen string.
|
257
|
+
#
|
258
|
+
# Once it's set, it can't be changed.
|
259
|
+
def hwdata_file
|
260
|
+
@@hwdata_file ||= nil
|
261
|
+
@@hwdata_file ? @@hwdata_file : ''.freeze
|
262
|
+
end
|
263
|
+
|
264
|
+
##
|
265
|
+
# Initializes hwdata
|
266
|
+
#
|
267
|
+
# hwdata can take upto 0.1 to 0.2 seconds to get initialized.
|
268
|
+
#
|
269
|
+
# Calling this method will load hwdata for future use.
|
270
|
+
#
|
271
|
+
# Once it's initialized, hwdata_file can't be changed.
|
272
|
+
#
|
273
|
+
# If this method initializes hwdata, it will return true
|
274
|
+
# Othewise this method will return false.
|
275
|
+
def initialize_hwdata
|
276
|
+
@@hwdata ||= nil
|
277
|
+
init = !@@hwdata
|
278
|
+
hwdata
|
279
|
+
init
|
280
|
+
end
|
281
|
+
|
230
282
|
alias count_devices count
|
231
283
|
|
232
284
|
private
|
233
285
|
def hwdata
|
234
|
-
@@hwdata_file ||= "/usr/share/hwdata/pci.ids"
|
286
|
+
@@hwdata_file ||= "/usr/share/hwdata/pci.ids".freeze
|
235
287
|
|
236
288
|
@@hwdata ||= if File.readable?(@@hwdata_file)
|
237
289
|
ret, vendor_id, device_id, device = {}, nil, nil, nil
|
data/lib/linux_stat/usb.rb
CHANGED
@@ -143,11 +143,63 @@ module LinuxStat
|
|
143
143
|
}
|
144
144
|
end
|
145
145
|
|
146
|
+
##
|
147
|
+
# hwdata_file = file
|
148
|
+
#
|
149
|
+
# Lets you set the hwdata_file about usb.ids.
|
150
|
+
#
|
151
|
+
# The hwdata file about usb.ids contains vendor name and product name information about
|
152
|
+
# devices. This is then mapped by the other methods that utilizes hwdata/usb.ids.
|
153
|
+
#
|
154
|
+
# Do note that this method is intended to run only once, at the beginning.
|
155
|
+
# If you use any other method that utilizes hwdata/usb.ids, before
|
156
|
+
# calling this method, this method will not work.
|
157
|
+
def hwdata_file=(file)
|
158
|
+
@@hwdata_file ||= file.freeze
|
159
|
+
end
|
160
|
+
|
161
|
+
##
|
162
|
+
# Checks if hwdata_file is already initialized or not.
|
163
|
+
# Once it's initialized, calling hwdata_file = 'something/usb.ids' is futile.
|
164
|
+
def hwdata_file_set?
|
165
|
+
@@hwdata_file ||= nil
|
166
|
+
!!@@hwdata_file
|
167
|
+
end
|
168
|
+
|
169
|
+
##
|
170
|
+
# Returns the hwdata_file as string.
|
171
|
+
#
|
172
|
+
# If hwdata_file isn't set, it will return an empty frozen string.
|
173
|
+
#
|
174
|
+
# Once it's set, it can't be changed.
|
175
|
+
def hwdata_file
|
176
|
+
@@hwdata_file ||= nil
|
177
|
+
@@hwdata_file ? @@hwdata_file : ''.freeze
|
178
|
+
end
|
179
|
+
|
180
|
+
##
|
181
|
+
# Initializes hwdata
|
182
|
+
#
|
183
|
+
# hwdata can take upto 0.1 to 0.2 seconds to get initialized.
|
184
|
+
#
|
185
|
+
# Calling this method will load hwdata for future use.
|
186
|
+
#
|
187
|
+
# Once it's initialized, hwdata_file can't be changed.
|
188
|
+
#
|
189
|
+
# If this method initializes hwdata, it will return true
|
190
|
+
# Othewise this method will return false.
|
191
|
+
def initialize_hwdata
|
192
|
+
@@hwdata ||= nil
|
193
|
+
init = !@@hwdata
|
194
|
+
hwdata
|
195
|
+
init
|
196
|
+
end
|
197
|
+
|
146
198
|
alias count_devices count
|
147
199
|
|
148
200
|
private
|
149
201
|
def hwdata
|
150
|
-
@@hwdata_file ||= "/usr/share/hwdata/usb.ids"
|
202
|
+
@@hwdata_file ||= "/usr/share/hwdata/usb.ids".freeze
|
151
203
|
|
152
204
|
@@hwdata ||= if File.readable?(@@hwdata_file)
|
153
205
|
file_data = IO.readlines(@@hwdata_file, encoding: 'ASCII-8BIT')
|
data/lib/linux_stat/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: linux_stat
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.1.
|
4
|
+
version: 1.1.1
|
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-28 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: Linux only, efficient linux system utilization reporting and system monitoring
|
14
14
|
gem
|