linux_stat 1.4.0 → 1.5.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 219b1bdf4ab0f8c62143e6b8c28059966baa28c33323bf65c718614446377513
4
- data.tar.gz: 3f38dede32f96b80b74311468524e20e07a87184cbaf55ccbc8c899a86a20eb4
3
+ metadata.gz: 5da13d97b132a58afb5d56337e40f5a234cf129612a14886e931b5d01d2232d3
4
+ data.tar.gz: dee75b59d2a8e2ab3f55e19c7e117869149d2c318fbc12e6e8a39c3d9433d418
5
5
  SHA512:
6
- metadata.gz: c0a08fd12c22370baf0080845e64ec8d0ea027d575b238ee02bb1b9dc5e193d12f5c9f3d705490a2ef9824e839dffa549d6840c21b434d08bcae58f1e135768d
7
- data.tar.gz: f47e5f32f8cac9d4aa5dbb5510f85d8acde8d81c849da28a097ab07cd551cefc2e8c567047a16a4741ab49301d9adf8e33557423b60675b6434514bde831e407
6
+ metadata.gz: 1885696170e580ac960730d82dce2e73ca8b924211b3ee1d74c3cdde362fdaebf6fcc08a7fd49b444729186e65c68b0c15767c9baca050d0853b0460ae1ca989
7
+ data.tar.gz: 8ec56355b4774c830282ca5ecb23dc3318ccc8fabd748a20af4bb0535bec6e3f0da9a3d0232ce09f58e1bf43cb9cc5917e970633dc19cc7c4b0cc9ed786df492
data/README.md CHANGED
@@ -16,6 +16,10 @@ Languages Used:
16
16
 
17
17
  ---
18
18
 
19
+ ## Requirements:
20
+
21
+ Any Linux distribution with Kernel 3.14+.
22
+
19
23
  ## Dependencies:
20
24
  + You need to have the C compiler installed to be able to compile the C extensions.
21
25
  On Arch Linux:
@@ -89,7 +93,6 @@ It's generated by linuxstat.rb command, which is available after the installatio
89
93
 
90
94
  For ease of use, LinuxStat is also assigned to the LS constant.
91
95
 
92
- ### LinuxStat::BIOS
93
96
  ### LinuxStat::BIOS
94
97
  ```
95
98
  # File: bios.rb | Line: 58
@@ -184,7 +187,7 @@ LinuxStat::Battery.technology()
184
187
  # File: battery.rb | Line: 162
185
188
  # Definition: def voltage_now
186
189
  LinuxStat::Battery.voltage_now()
187
- => 12.537
190
+ => 12.583
188
191
 
189
192
  ```
190
193
 
@@ -208,7 +211,7 @@ LinuxStat::CPU.count_online()
208
211
  # File: cpu.rb | Line: 199
209
212
  # Definition: def cur_freq
210
213
  LinuxStat::CPU.cur_freq()
211
- => {"cpu0"=>1999901, "cpu1"=>1999408, "cpu2"=>2000039, "cpu3"=>2000019}
214
+ => {"cpu0"=>2000010, "cpu1"=>1999584, "cpu2"=>2000137, "cpu3"=>2000033}
212
215
 
213
216
  # File: cpu.rb | Line: 267
214
217
  # Definition: def governor
@@ -243,29 +246,29 @@ LinuxStat::CPU.online()
243
246
  # File: cpu.rb | Line: 25
244
247
  # Definition: def stat(sleep = ticks_to_ms_t5)
245
248
  LinuxStat::CPU.stat(sleep)
246
- => {0=>27.78, 1=>20.0, 2=>25.0, 3=>25.0, 4=>40.0}
249
+ => {0=>5.26, 1=>16.67, 2=>16.67, 3=>0.0, 4=>20.0}
247
250
 
248
251
  # File: cpu.rb | Line: 65
249
252
  # Definition: def total_usage(sleep = ticks_to_ms_t5)
250
253
  LinuxStat::CPU.total_usage(sleep)
251
- => 25.0
254
+ => 14.29
252
255
 
253
256
  # File: cpu.rb | Line: 65
254
257
  # Definition: def total_usage(sleep = ticks_to_ms_t5)
255
258
  LinuxStat::CPU.usage(sleep)
256
- => 25.0
259
+ => 10.0
257
260
 
258
261
  # File: cpu.rb | Line: 25
259
262
  # Definition: def stat(sleep = ticks_to_ms_t5)
260
263
  LinuxStat::CPU.usages(sleep)
261
- => {0=>25.0, 1=>20.0, 2=>33.33, 3=>20.0, 4=>0.0}
264
+ => {0=>5.26, 1=>0.0, 2=>0.0, 3=>20.0, 4=>0.0}
262
265
 
263
266
  ```
264
267
 
265
268
  ### LinuxStat::FS
266
269
  ```
267
270
  LinuxStat::FS.stat(arg = "/")
268
- => {:block_size=>4096, :fragment_size=>4096, :blocks=>29292283, :block_free=>7268389, :block_avail_unpriv=>7268389, :inodes=>58612160, :free_inodes=>56907397, :filesystem_id=>2050, :mount_flags=>1024, :max_filename_length=>255}
271
+ => {:block_size=>4096, :fragment_size=>4096, :blocks=>29292283, :block_free=>6091459, :block_avail_unpriv=>6091459, :inodes=>50505784, :free_inodes=>48759601, :filesystem_id=>2050, :mount_flags=>1024, :max_filename_length=>255}
269
272
 
270
273
  ```
271
274
 
@@ -274,22 +277,22 @@ LinuxStat::FS.stat(arg = "/")
274
277
  # File: filesystem.rb | Line: 94
275
278
  # Definition: def available(fs = ?..freeze)
276
279
  LinuxStat::Filesystem.available(fs)
277
- => 29771321344
280
+ => 24950616064
278
281
 
279
282
  # File: filesystem.rb | Line: 60
280
283
  # Definition: def free(fs = ?..freeze)
281
284
  LinuxStat::Filesystem.free(fs)
282
- => 29771321344
285
+ => 24950616064
283
286
 
284
287
  # File: filesystem.rb | Line: 21
285
288
  # Definition: def stat(fs = ?..freeze)
286
289
  LinuxStat::Filesystem.stat(fs)
287
- => {:total=>119981191168, :free=>29771321344, :used=>90209869824}
290
+ => {:total=>119981191168, :free=>24950616064, :used=>95030575104}
288
291
 
289
292
  # File: filesystem.rb | Line: 110
290
293
  # Definition: def stat_raw(fs = ?..freeze)
291
294
  LinuxStat::Filesystem.stat_raw(fs)
292
- => {:block_size=>4096, :fragment_size=>4096, :blocks=>29292283, :block_free=>7268389, :block_avail_unpriv=>7268389, :inodes=>58612160, :free_inodes=>56907397, :filesystem_id=>2050, :mount_flags=>1024, :max_filename_length=>255}
295
+ => {:block_size=>4096, :fragment_size=>4096, :blocks=>29292283, :block_free=>6091459, :block_avail_unpriv=>6091459, :inodes=>50505784, :free_inodes=>48759601, :filesystem_id=>2050, :mount_flags=>1024, :max_filename_length=>255}
293
296
 
294
297
  # File: filesystem.rb | Line: 41
295
298
  # Definition: def total(fs = ?..freeze)
@@ -299,7 +302,7 @@ LinuxStat::Filesystem.total(fs)
299
302
  # File: filesystem.rb | Line: 75
300
303
  # Definition: def used(fs = ?..freeze)
301
304
  LinuxStat::Filesystem.used(fs)
302
- => 90209869824
305
+ => 95030575104
303
306
 
304
307
  ```
305
308
 
@@ -359,35 +362,40 @@ LinuxStat::Kernel.version()
359
362
 
360
363
  ### LinuxStat::Memory
361
364
  ```
362
- # File: memory.rb | Line: 52
365
+ # File: memory.rb | Line: 62
363
366
  # Definition: def available
364
367
  LinuxStat::Memory.available()
365
- => 337416
368
+ => 422660
366
369
 
367
- # File: memory.rb | Line: 83
370
+ # File: memory.rb | Line: 52
371
+ # Definition: def free
372
+ LinuxStat::Memory.free()
373
+ => 237884
374
+
375
+ # File: memory.rb | Line: 93
368
376
  # Definition: def percent_available
369
377
  LinuxStat::Memory.percent_available()
370
- => 8.8
378
+ => 11.02
371
379
 
372
- # File: memory.rb | Line: 72
380
+ # File: memory.rb | Line: 82
373
381
  # Definition: def percent_used
374
382
  LinuxStat::Memory.percent_used()
375
- => 91.2
383
+ => 88.98
376
384
 
377
385
  # File: memory.rb | Line: 13
378
386
  # Definition: def stat
379
387
  LinuxStat::Memory.stat()
380
- => {:total=>3836228, :used=>3498812, :available=>337416, :percent_used=>91.2, :percent_available=>8.8}
388
+ => {:total=>3836236, :used=>3413576, :available=>422660, :percent_used=>88.98, :percent_available=>11.02}
381
389
 
382
390
  # File: memory.rb | Line: 42
383
391
  # Definition: def total
384
392
  LinuxStat::Memory.total()
385
- => 3836228
393
+ => 3836236
386
394
 
387
- # File: memory.rb | Line: 62
395
+ # File: memory.rb | Line: 72
388
396
  # Definition: def used
389
397
  LinuxStat::Memory.used()
390
- => 3498812
398
+ => 3413576
391
399
 
392
400
  ```
393
401
 
@@ -396,7 +404,7 @@ LinuxStat::Memory.used()
396
404
  # File: mounts.rb | Line: 181
397
405
  # Definition: def device_stat(dev = root)
398
406
  LinuxStat::Mounts.device_stat(dev)
399
- => {:mountpoint=>"/", :total=>119981191168, :free=>29771321344, :available=>29771321344, :used=>90209869824, :percent_used=>75.19, :percent_free=>24.81, :percent_available=>24.81}
407
+ => {:mountpoint=>"/", :total=>119981191168, :free=>24950616064, :available=>24950616064, :used=>95030575104, :percent_used=>79.2, :percent_free=>20.8, :percent_available=>20.8}
400
408
 
401
409
  # File: mounts.rb | Line: 139
402
410
  # Definition: def devices_stat
@@ -406,17 +414,17 @@ LinuxStat::Mounts.devices_stat()
406
414
  # File: mounts.rb | Line: 13
407
415
  # Definition: def list
408
416
  LinuxStat::Mounts.list()
409
- => ["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=1892888k,nr_inodes=473222,mode=755 0 0", "run /run tmpfs rw,nosuid,nodev,relatime,mode=755 0 0", "...
417
+ => ["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=1892892k,nr_inodes=473223,mode=755 0 0", "run /run tmpfs rw,nosuid,nodev,relatime,mode=755 0 0", "...
410
418
 
411
419
  # File: mounts.rb | Line: 22
412
420
  # Definition: def list_devices
413
421
  LinuxStat::Mounts.list_devices()
414
- => ["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", "deb...
422
+ => ["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...
415
423
 
416
424
  # File: mounts.rb | Line: 111
417
425
  # Definition: def list_devices_mount_point
418
426
  LinuxStat::Mounts.list_devices_mount_point()
419
- => {"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"=>"...
427
+ => {"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...
420
428
 
421
429
  # File: mounts.rb | Line: 82
422
430
  # Definition: def mount_point(dev = root)
@@ -441,7 +449,7 @@ LinuxStat::Mounts.root_mount_options()
441
449
  # File: mounts.rb | Line: 58
442
450
  # Definition: def tmpfs
443
451
  LinuxStat::Mounts.tmpfs()
444
- => {"/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", "/ramdisk"=>"tmpfs /ramdisk tmpfs rw,nosuid,nodev,relatime,size=6291456k 0 0", "/tmp...
452
+ => {"/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", "/cache"=>"tmpfs /cache tmpfs rw,nosuid,nodev,relatime,size=2097152k 0 0", "/ramdisk...
445
453
 
446
454
  ```
447
455
 
@@ -455,22 +463,22 @@ LinuxStat::Net.current_usage(interval)
455
463
  # File: net.rb | Line: 12
456
464
  # Definition: def ipv4_private
457
465
  LinuxStat::Net.ipv4_private()
458
- => "192.168.43.107"
466
+ => "192.168.0.103"
459
467
 
460
468
  # File: net.rb | Line: 27
461
469
  # Definition: def total_bytes
462
470
  LinuxStat::Net.total_bytes()
463
- => {:received=>936112008, :transmitted=>141554101}
471
+ => {:received=>719043592, :transmitted=>70236574}
464
472
 
465
473
  # File: net.rb | Line: 45
466
474
  # Definition: def total_bytes_received
467
475
  LinuxStat::Net.total_bytes_received()
468
- => 936112008
476
+ => 719043592
469
477
 
470
478
  # File: net.rb | Line: 58
471
479
  # Definition: def total_bytes_transmitted
472
480
  LinuxStat::Net.total_bytes_transmitted()
473
- => 141554101
481
+ => 70236574
474
482
 
475
483
  # File: net.rb | Line: 86
476
484
  # Definition: def usage(interval = 0.1)
@@ -501,6 +509,11 @@ LinuxStat::OS.distribution()
501
509
  LinuxStat::OS.hostname()
502
510
  => "archlinux"
503
511
 
512
+ # File: os.rb | Line: 185
513
+ # Definition: def loadavg
514
+ LinuxStat::OS.loadavg()
515
+ => {1=>0.56884765625, 5=>0.69482421875, 15=>0.9892578125}
516
+
504
517
  # File: os.rb | Line: 35
505
518
  # Definition: def lsb_release
506
519
  LinuxStat::OS.lsb_release()
@@ -524,7 +537,12 @@ LinuxStat::OS.os_release()
524
537
  # File: os.rb | Line: 144
525
538
  # Definition: def uptime
526
539
  LinuxStat::OS.uptime()
527
- => {:hour=>14, :minute=>8, :second=>42.08}
540
+ => {:hour=>11, :minute=>17, :second=>5.68}
541
+
542
+ # File: os.rb | Line: 168
543
+ # Definition: def uptime_i
544
+ LinuxStat::OS.uptime_i()
545
+ => 40626
528
546
 
529
547
  # File: os.rb | Line: 84
530
548
  # Definition: def version
@@ -576,23 +594,23 @@ LinuxStat::PCI.initialize_hwdata()
576
594
  ```
577
595
  # File: prettify_bytes.rb | Line: 49
578
596
  # Definition: def convert_binary(n, precision: 2)
579
- LinuxStat::PrettifyBytes.convert_binary(n = 327222499582327, precision:)
580
- => "297.61 tebibytes"
597
+ LinuxStat::PrettifyBytes.convert_binary(n = 137669164863821, precision:)
598
+ => "125.21 tebibytes"
581
599
 
582
600
  # File: prettify_bytes.rb | Line: 26
583
601
  # Definition: def convert_decimal(n, precision: 2)
584
- LinuxStat::PrettifyBytes.convert_decimal(n = 812496332434396, precision:)
585
- => "812.50 terabytes"
602
+ LinuxStat::PrettifyBytes.convert_decimal(n = 854792232966738, precision:)
603
+ => "854.79 terabytes"
586
604
 
587
605
  # File: prettify_bytes.rb | Line: 97
588
606
  # Definition: def convert_short_binary(n, precision: 2)
589
- LinuxStat::PrettifyBytes.convert_short_binary(n = 447429857254915, precision:)
590
- => "406.94 TiB"
607
+ LinuxStat::PrettifyBytes.convert_short_binary(n = 502144293693829, precision:)
608
+ => "456.70 TiB"
591
609
 
592
610
  # File: prettify_bytes.rb | Line: 72
593
611
  # Definition: def convert_short_decimal(n, precision: 2)
594
- LinuxStat::PrettifyBytes.convert_short_decimal(n = 157028156498063, precision:)
595
- => "157.03 TB"
612
+ LinuxStat::PrettifyBytes.convert_short_decimal(n = 489879177525276, precision:)
613
+ => "489.88 TB"
596
614
 
597
615
  ```
598
616
 
@@ -611,12 +629,12 @@ LinuxStat::Process.count()
611
629
  # File: process.rb | Line: 124
612
630
  # Definition: def idle
613
631
  LinuxStat::Process.idle()
614
- => [3, 4, 6, 9, 12, 23, 30, 37, 39, 49, 102, 103, 104, 106, 107, 108, 109, 110, 117, 118, 119, 121, 131, 134, 140, 164, 166, 168, 169, 172, 174, 179, 180, 181, 182, 183, 184, 185, 186, 230, 234, 283, 418, 426, 428, 5731, 5732, 5733, 5734, 5735, 5736, 517...
632
+ => [3, 4, 6, 9, 12, 23, 30, 37, 39, 49, 102, 103, 104, 106, 107, 108, 109, 110, 117, 118, 120, 122, 131, 134, 140, 164, 166, 170, 171, 174, 176, 181, 182, 183, 184, 185, 186, 187, 189, 231, 234, 302, 417, 425, 13585, 20484, 20485, 20486, 20487, 20488, 20...
615
633
 
616
634
  # File: process.rb | Line: 11
617
635
  # Definition: def list
618
636
  LinuxStat::Process.list()
619
- => [1, 2, 3, 4, 6, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 23, 24, 25, 26, 27, 28, 30, 31, 32, 33, 34, 35, 37, 38, 39, 40, 41, 42, 46, 47, 48, 49, 50, 51, 52, 102, 103, 104, 106, 107, 108, 109, 110, 111, 114, 115, 117, 118, 119, 121, 131, 134,...
637
+ => [1, 2, 3, 4, 6, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 23, 24, 25, 26, 27, 28, 30, 31, 32, 33, 34, 35, 37, 38, 39, 40, 41, 42, 46, 47, 48, 49, 50, 51, 52, 102, 103, 104, 106, 107, 108, 109, 110, 112, 114, 115, 117, 118, 120, 122, 131, 134,...
620
638
 
621
639
  # File: process.rb | Line: 36
622
640
  # Definition: def names
@@ -626,12 +644,12 @@ LinuxStat::Process.names()
626
644
  # File: process.rb | Line: 150
627
645
  # Definition: def running
628
646
  LinuxStat::Process.running()
629
- => [474, 628, 643, 55770]
647
+ => [37551]
630
648
 
631
649
  # File: process.rb | Line: 111
632
650
  # Definition: def sleeping
633
651
  LinuxStat::Process.sleeping()
634
- => [1, 2, 10, 11, 13, 14, 15, 16, 17, 18, 19, 20, 21, 24, 25, 26, 27, 28, 31, 32, 33, 34, 35, 38, 40, 41, 42, 46, 47, 48, 50, 51, 52, 111, 114, 115, 163, 165, 187, 216, 233, 235, 349, 350, 352, 353, 363, 425, 427, 451, 452, 453, 454, 468, 470, 474, 485,...
652
+ => [1, 2, 10, 11, 13, 14, 15, 16, 17, 18, 19, 20, 21, 24, 25, 26, 27, 28, 31, 32, 33, 34, 35, 38, 40, 41, 42, 46, 47, 48, 50, 51, 52, 112, 114, 115, 163, 165, 190, 218, 233, 235, 342, 380, 382, 384, 385, 428, 429, 430, 432, 443, 447, 454, 483, 501, 504,...
635
653
 
636
654
  # File: process.rb | Line: 163
637
655
  # Definition: def stopped
@@ -670,12 +688,12 @@ LinuxStat::ProcessInfo.count_cpu(pid)
670
688
  # File: process_info.rb | Line: 284
671
689
  # Definition: def cpu_stat(pid: $$, sleep: ticks_to_ms_t5)
672
690
  LinuxStat::ProcessInfo.cpu_stat(pid:, sleep:)
673
- => {:cpu_usage=>0.0, :threads=>1, :last_executed_cpu=>2}
691
+ => {:cpu_usage=>0.0, :threads=>1, :last_executed_cpu=>1}
674
692
 
675
693
  # File: process_info.rb | Line: 350
676
694
  # Definition: def cpu_usage(pid: $$, sleep: ticks_to_ms_t5)
677
695
  LinuxStat::ProcessInfo.cpu_usage(pid:, sleep:)
678
- => 5.0
696
+ => 0.0
679
697
 
680
698
  # File: process_info.rb | Line: 525
681
699
  # Definition: def gid(pid = $$)
@@ -685,12 +703,12 @@ LinuxStat::ProcessInfo.gid(pid)
685
703
  # File: process_info.rb | Line: 487
686
704
  # Definition: def last_executed_cpu(pid = $$)
687
705
  LinuxStat::ProcessInfo.last_executed_cpu(pid)
688
- => 2
706
+ => 1
689
707
 
690
708
  # File: process_info.rb | Line: 151
691
709
  # Definition: def mem_stat(pid = $$)
692
710
  LinuxStat::ProcessInfo.mem_stat(pid)
693
- => {:memory=>24842.24, :virtual_memory=>96309.248, :resident_memory=>30720.0}
711
+ => {:memory=>24842.24, :virtual_memory=>96256.0, :resident_memory=>30859.264}
694
712
 
695
713
  # File: process_info.rb | Line: 184
696
714
  # Definition: def memory(pid = $$)
@@ -720,22 +738,22 @@ LinuxStat::ProcessInfo.process_name(pid)
720
738
  # File: process_info.rb | Line: 234
721
739
  # Definition: def resident_memory(pid = $$)
722
740
  LinuxStat::ProcessInfo.resident_memory(pid)
723
- => 30720.0
741
+ => 30859.264
724
742
 
725
743
  # File: process_info.rb | Line: 621
726
744
  # Definition: def running_time(pid = $$)
727
745
  LinuxStat::ProcessInfo.running_time(pid)
728
- => 1.19
746
+ => 1.08
729
747
 
730
748
  # File: process_info.rb | Line: 602
731
749
  # Definition: def start_time(pid = $$)
732
750
  LinuxStat::ProcessInfo.start_time(pid)
733
- => 2021-01-20 00:10:50 +0530
751
+ => 2021-01-22 21:42:20 +0530
734
752
 
735
753
  # File: process_info.rb | Line: 568
736
754
  # Definition: def start_time_epoch(pid = $$)
737
755
  LinuxStat::ProcessInfo.start_time_epoch(pid)
738
- => 1611081650
756
+ => 1611331940
739
757
 
740
758
  # File: process_info.rb | Line: 653
741
759
  # Definition: def state(pid = $$)
@@ -755,7 +773,7 @@ LinuxStat::ProcessInfo.threads(pid)
755
773
  # File: process_info.rb | Line: 30
756
774
  # Definition: def total_io(pid = $$)
757
775
  LinuxStat::ProcessInfo.total_io(pid)
758
- => {:read_bytes=>1286144, :write_bytes=>0}
776
+ => {:read_bytes=>1302528, :write_bytes=>0}
759
777
 
760
778
  # File: process_info.rb | Line: 501
761
779
  # Definition: def uid(pid = $$)
@@ -765,7 +783,7 @@ LinuxStat::ProcessInfo.uid(pid)
765
783
  # File: process_info.rb | Line: 209
766
784
  # Definition: def virtual_memory(pid = $$)
767
785
  LinuxStat::ProcessInfo.virtual_memory(pid)
768
- => 96309.248
786
+ => 96256.0
769
787
 
770
788
  ```
771
789
 
@@ -776,40 +794,45 @@ LinuxStat::ProcessInfo.virtual_memory(pid)
776
794
  LinuxStat::Swap.any?()
777
795
  => true
778
796
 
779
- # File: swap.rb | Line: 70
797
+ # File: swap.rb | Line: 81
780
798
  # Definition: def available
781
799
  LinuxStat::Swap.available()
782
- => 3546108
800
+ => 2437940
801
+
802
+ # File: swap.rb | Line: 70
803
+ # Definition: def free
804
+ LinuxStat::Swap.free()
805
+ => 2437940
783
806
 
784
807
  # File: swap.rb | Line: 10
785
808
  # Definition: def list
786
809
  LinuxStat::Swap.list()
787
- => {"/dev/zram0"=>[:partition, 4194300, 648192, -2]}
810
+ => {"/dev/zram0"=>[:partition, 4194300, 1756360, -2]}
788
811
 
789
- # File: swap.rb | Line: 105
812
+ # File: swap.rb | Line: 116
790
813
  # Definition: def percent_available
791
814
  LinuxStat::Swap.percent_available()
792
- => 84.55
815
+ => 58.13
793
816
 
794
- # File: swap.rb | Line: 91
817
+ # File: swap.rb | Line: 102
795
818
  # Definition: def percent_used
796
819
  LinuxStat::Swap.percent_used()
797
- => 15.45
820
+ => 41.87
798
821
 
799
822
  # File: swap.rb | Line: 34
800
823
  # Definition: def stat
801
824
  LinuxStat::Swap.stat()
802
- => {:total=>4194300, :used=>648192, :available=>3546108, :percent_used=>15.45, :percent_available=>84.55}
825
+ => {:total=>4194300, :used=>1756360, :available=>2437940, :percent_used=>41.87, :percent_available=>58.13}
803
826
 
804
827
  # File: swap.rb | Line: 59
805
828
  # Definition: def total
806
829
  LinuxStat::Swap.total()
807
830
  => 4194300
808
831
 
809
- # File: swap.rb | Line: 82
832
+ # File: swap.rb | Line: 93
810
833
  # Definition: def used
811
834
  LinuxStat::Swap.used()
812
- => 648192
835
+ => 1756360
813
836
 
814
837
  ```
815
838
 
@@ -874,6 +897,40 @@ LinuxStat::Sysconf.tty_name_max()
874
897
 
875
898
  ```
876
899
 
900
+ ### LinuxStat::Sysinfo
901
+ ```
902
+ LinuxStat::Sysinfo.bufferram()
903
+ => 4096
904
+
905
+ LinuxStat::Sysinfo.freehigh()
906
+ => 0
907
+
908
+ LinuxStat::Sysinfo.freeram()
909
+ => 223875072
910
+
911
+ LinuxStat::Sysinfo.freeswap()
912
+ => 2496450560
913
+
914
+ LinuxStat::Sysinfo.loads()
915
+ => [0.56884765625, 0.69482421875, 0.9892578125]
916
+
917
+ LinuxStat::Sysinfo.sharedram()
918
+ => 834801664
919
+
920
+ LinuxStat::Sysinfo.totalhigh()
921
+ => 0
922
+
923
+ LinuxStat::Sysinfo.totalram()
924
+ => 3928305664
925
+
926
+ LinuxStat::Sysinfo.totalswap()
927
+ => 4294963200
928
+
929
+ LinuxStat::Sysinfo.uptime()
930
+ => 40627
931
+
932
+ ```
933
+
877
934
  ### LinuxStat::Thermal
878
935
  ```
879
936
  # File: thermal.rb | Line: 59
@@ -889,12 +946,12 @@ LinuxStat::Thermal.count_sensors()
889
946
  # File: thermal.rb | Line: 41
890
947
  # Definition: def fans
891
948
  LinuxStat::Thermal.fans()
892
- => [{:path=>"/sys/class/hwmon/hwmon4", :name=>"dell_smm", :label=>"Processor Fan", :rpm=>2718}]
949
+ => [{:path=>"/sys/class/hwmon/hwmon4", :name=>"dell_smm", :label=>"Processor Fan", :rpm=>0}]
893
950
 
894
951
  # File: thermal.rb | Line: 23
895
952
  # Definition: def temperatures
896
953
  LinuxStat::Thermal.temperatures()
897
- => [{:path=>"/sys/class/hwmon/hwmon4", :name=>"dell_smm", :label=>"SODIMM", :temperature=>33.0}, {:path=>"/sys/class/hwmon/hwmon4", :name=>"dell_smm", :label=>"CPU", :temperature=>42.0}, {:path=>"/sys/class/hwmon/hwmon4", :name=>"dell_smm", :label=>"Ambi...
954
+ => [{:path=>"/sys/class/hwmon/hwmon4", :name=>"dell_smm", :label=>"SODIMM", :temperature=>36.0}, {:path=>"/sys/class/hwmon/hwmon4", :name=>"dell_smm", :label=>"CPU", :temperature=>46.0}, {:path=>"/sys/class/hwmon/hwmon4", :name=>"dell_smm", :label=>"Ambi...
898
955
 
899
956
  ```
900
957
 
@@ -913,7 +970,7 @@ LinuxStat::USB.count_devices()
913
970
  # File: usb.rb | Line: 49
914
971
  # Definition: def devices_stat(hwdata: true)
915
972
  LinuxStat::USB.devices_stat(hwdata:)
916
- => [{: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...
973
+ => [{:path=>"/sys/bus/usb/devices/1-1.2/", :id=>"04d9:1203", :vendor_id=>"04d9", :product_id=>"1203", :bus_num=>1, :dev_num=>11, :hwdata=>{:vendor=>"Holtek Semiconductor, Inc.", :product=>"Keyboard"}, :authorized=>true, :b_max_power=>"100mA", :b_max_pack...
917
974
 
918
975
  # File: usb.rb | Line: 179
919
976
  # Definition: def hwdata_file
@@ -18,16 +18,16 @@ static VALUE statfs(VALUE obj, VALUE dir) {
18
18
 
19
19
  if(statvfs(d, &buf) < 0) return hash ;
20
20
 
21
- rb_hash_aset(hash, ID2SYM(rb_intern("block_size")), INT2FIX(buf.f_bsize)) ;
22
- rb_hash_aset(hash, ID2SYM(rb_intern("fragment_size")), INT2FIX(buf.f_frsize)) ;
23
- rb_hash_aset(hash, ID2SYM(rb_intern("blocks")), INT2FIX(buf.f_blocks)) ;
24
- rb_hash_aset(hash, ID2SYM(rb_intern("block_free")), INT2FIX(buf.f_bfree)) ;
25
- rb_hash_aset(hash, ID2SYM(rb_intern("block_avail_unpriv")), INT2FIX(buf.f_bavail)) ;
26
- rb_hash_aset(hash, ID2SYM(rb_intern("inodes")), INT2FIX(buf.f_files)) ;
27
- rb_hash_aset(hash, ID2SYM(rb_intern("free_inodes")), INT2FIX(buf.f_ffree)) ;
28
- rb_hash_aset(hash, ID2SYM(rb_intern("filesystem_id")), INT2FIX(buf.f_fsid)) ;
29
- rb_hash_aset(hash, ID2SYM(rb_intern("mount_flags")), INT2FIX(buf.f_flag)) ;
30
- rb_hash_aset(hash, ID2SYM(rb_intern("max_filename_length")), INT2FIX(buf.f_namemax)) ;
21
+ rb_hash_aset(hash, ID2SYM(rb_intern("block_size")), INT2FIX((unsigned int)buf.f_bsize)) ;
22
+ rb_hash_aset(hash, ID2SYM(rb_intern("fragment_size")), ULL2NUM((unsigned long long)buf.f_frsize)) ;
23
+ rb_hash_aset(hash, ID2SYM(rb_intern("blocks")), ULL2NUM((unsigned long long)buf.f_blocks)) ;
24
+ rb_hash_aset(hash, ID2SYM(rb_intern("block_free")), ULL2NUM((unsigned long long)buf.f_bfree)) ;
25
+ rb_hash_aset(hash, ID2SYM(rb_intern("block_avail_unpriv")), ULL2NUM((unsigned long long)buf.f_bavail)) ;
26
+ rb_hash_aset(hash, ID2SYM(rb_intern("inodes")), ULL2NUM((unsigned long long)buf.f_files)) ;
27
+ rb_hash_aset(hash, ID2SYM(rb_intern("free_inodes")), ULL2NUM((unsigned long long)buf.f_ffree)) ;
28
+ rb_hash_aset(hash, ID2SYM(rb_intern("filesystem_id")), ULL2NUM((unsigned long long)buf.f_fsid)) ;
29
+ rb_hash_aset(hash, ID2SYM(rb_intern("mount_flags")), ULL2NUM((unsigned long long)buf.f_flag)) ;
30
+ rb_hash_aset(hash, ID2SYM(rb_intern("max_filename_length")), ULL2NUM((unsigned long long)buf.f_namemax)) ;
31
31
 
32
32
  return hash ;
33
33
  }
@@ -4,7 +4,7 @@ unless have_const('linux') || RbConfig::CONFIG['arch'].to_s[/linux/]
4
4
  abort('Platform is not linux')
5
5
  end
6
6
 
7
- unless have_header('sys/unistd.h') && have_header('ruby.h')
7
+ unless have_header('unistd.h') && have_header('ruby.h')
8
8
  abort('Missing header')
9
9
  end
10
10
 
@@ -1,4 +1,5 @@
1
1
  #include <unistd.h>
2
+ #include <inttypes.h>
2
3
  #include "ruby.h"
3
4
 
4
5
  #if defined(__GNUC__) && !defined(__clang__) && !defined(__INTEL_COMPILER)
@@ -12,94 +13,94 @@
12
13
  #endif
13
14
 
14
15
  static VALUE getTick(VALUE obj) {
15
- short int val = sysconf(_SC_CLK_TCK) ;
16
+ int16_t val = sysconf(_SC_CLK_TCK) ;
16
17
  if (val < 0) return Qnil ;
17
18
 
18
19
  return INT2FIX(val) ;
19
20
  }
20
21
 
21
22
  static VALUE getChildMax(VALUE obj) {
22
- long long int val = sysconf(_SC_CHILD_MAX) ;
23
+ int64_t val = sysconf(_SC_CHILD_MAX) ;
23
24
  if (val < 0) return Qnil ;
24
25
 
25
- return INT2FIX(val) ;
26
+ return INT2NUM(val) ;
26
27
  }
27
28
 
28
29
  static VALUE getHostnameMax(VALUE obj) {
29
- int val = sysconf(_SC_HOST_NAME_MAX) ;
30
+ int32_t val = sysconf(_SC_HOST_NAME_MAX) ;
30
31
  if (val < 0) return Qnil ;
31
32
 
32
- return INT2FIX(val) ;
33
+ return INT2NUM(val) ;
33
34
  }
34
35
 
35
36
  static VALUE getLoginNameMax(VALUE obj) {
36
- int val = sysconf(_SC_LOGIN_NAME_MAX) ;
37
+ int32_t val = sysconf(_SC_LOGIN_NAME_MAX) ;
37
38
  if (val < 0) return Qnil ;
38
39
 
39
- return INT2FIX(val) ;
40
+ return INT2NUM(val) ;
40
41
  }
41
42
 
42
43
  static VALUE getOpenMax(VALUE obj) {
43
- int val = sysconf(_SC_OPEN_MAX) ;
44
+ int64_t val = sysconf(_SC_OPEN_MAX) ;
44
45
  if (val < 0) return Qnil ;
45
46
 
46
- return INT2FIX(val) ;
47
+ return INT2NUM(val) ;
47
48
  }
48
49
 
49
50
  static VALUE getPageSize(VALUE obj) {
50
- short int val = sysconf(_SC_PAGESIZE) ;
51
+ int32_t val = sysconf(_SC_PAGESIZE) ;
51
52
  if (val < 0) return Qnil ;
52
53
 
53
- return INT2FIX(val) ;
54
+ return INT2NUM(val) ;
54
55
  }
55
56
 
56
57
  static VALUE getStreamMax(VALUE obj) {
57
- int val = sysconf(_SC_STREAM_MAX) ;
58
+ int64_t val = sysconf(_SC_STREAM_MAX) ;
58
59
  if (val < 0) return Qnil ;
59
60
 
60
- return INT2FIX(val) ;
61
+ return INT2NUM(val) ;
61
62
  }
62
63
 
63
64
  static VALUE getTTYNameMax(VALUE obj) {
64
- int val = sysconf(_SC_TTY_NAME_MAX) ;
65
+ int32_t val = sysconf(_SC_TTY_NAME_MAX) ;
65
66
  if (val < 0) return Qnil ;
66
67
 
67
- return INT2FIX(val) ;
68
+ return INT2NUM(val) ;
68
69
  }
69
70
 
70
71
  static VALUE getPosixVersion(VALUE obj) {
71
- int val = sysconf(_SC_VERSION) ;
72
+ int32_t val = sysconf(_SC_VERSION) ;
72
73
  if (val < 0) return Qnil ;
73
74
 
74
- return INT2FIX(val) ;
75
+ return INT2NUM(val) ;
75
76
  }
76
77
 
77
78
  static VALUE getLineMax(VALUE obj) {
78
- int val = sysconf(_SC_LINE_MAX) ;
79
+ int32_t val = sysconf(_SC_LINE_MAX) ;
79
80
  if (val < 0) return Qnil ;
80
81
 
81
- return INT2FIX(val) ;
82
+ return INT2NUM(val) ;
82
83
  }
83
84
 
84
85
  static VALUE getExprNestMax(VALUE obj) {
85
- int val = sysconf(_SC_EXPR_NEST_MAX) ;
86
+ int32_t val = sysconf(_SC_EXPR_NEST_MAX) ;
86
87
  if (val < 0) return Qnil ;
87
88
 
88
- return INT2FIX(val) ;
89
+ return INT2NUM(val) ;
89
90
  }
90
91
 
91
92
  static VALUE getProcessorConfigured(VALUE obj) {
92
- short int val = sysconf(_SC_NPROCESSORS_CONF) ;
93
+ int32_t val = sysconf(_SC_NPROCESSORS_CONF) ;
93
94
  if (val < 0) return Qnil ;
94
95
 
95
- return INT2FIX(val) ;
96
+ return INT2NUM(val) ;
96
97
  }
97
98
 
98
99
  static VALUE getProcessorOnline(VALUE obj) {
99
- short int val = sysconf(_SC_NPROCESSORS_ONLN) ;
100
+ int32_t val = sysconf(_SC_NPROCESSORS_ONLN) ;
100
101
  if (val < 0) return Qnil ;
101
102
 
102
- return INT2FIX(val) ;
103
+ return INT2NUM(val) ;
103
104
  }
104
105
 
105
106
  static VALUE getUser(VALUE obj) {
@@ -108,15 +109,15 @@ static VALUE getUser(VALUE obj) {
108
109
  }
109
110
 
110
111
  static VALUE getUID(VALUE obj) {
111
- return INT2FIX(getuid()) ;
112
+ return INT2NUM(getuid()) ;
112
113
  }
113
114
 
114
115
  static VALUE getGID(VALUE obj) {
115
- return INT2FIX(getgid()) ;
116
+ return INT2NUM(getgid()) ;
116
117
  }
117
118
 
118
119
  static VALUE getEUID(VALUE obj) {
119
- return INT2FIX(geteuid()) ;
120
+ return INT2NUM(geteuid()) ;
120
121
  }
121
122
 
122
123
  static VALUE getHostname(VALUE obj) {
@@ -0,0 +1,11 @@
1
+ require 'mkmf'
2
+
3
+ unless have_const('linux') || RbConfig::CONFIG['arch'].to_s[/linux/]
4
+ abort('Platform is not linux')
5
+ end
6
+
7
+ unless have_header('sys/sysinfo.h') && have_header('ruby.h')
8
+ abort('Missing header')
9
+ end
10
+
11
+ create_makefile 'linux_stat/sysinfo'
@@ -0,0 +1,130 @@
1
+ #include <sys/sysinfo.h>
2
+ #include <inttypes.h>
3
+ #include "ruby.h"
4
+
5
+ #if defined(__GNUC__) && !defined(__clang__) && !defined(__INTEL_COMPILER)
6
+ #pragma GCC optimize ("O3")
7
+ #pragma GCC diagnostic warning "-Wall"
8
+ #elif defined(__clang__)
9
+ #pragma clang optimize on
10
+ #pragma clang diagnostic warning "-Wall"
11
+ #elif defined(__INTEL_COMPILER)
12
+ #pragma intel optimization_level 3
13
+ #endif
14
+
15
+ static struct sysinfo info ;
16
+
17
+ VALUE totalram(VALUE obj) {
18
+ static struct sysinfo info ;
19
+ short status = sysinfo(&info) ;
20
+ if (status < 0) return Qnil ;
21
+
22
+ VALUE _rb_v = ULL2NUM((unsigned long long) info.totalram) ;
23
+ VALUE _rb_mem_unit = ULL2NUM((unsigned long long) info.mem_unit) ;
24
+ return rb_funcallv_public(_rb_v, rb_intern("*"), 1, &_rb_mem_unit) ;
25
+ }
26
+
27
+ VALUE freeram(VALUE obj) {
28
+ short status = sysinfo(&info) ;
29
+ if (status < 0) return Qnil ;
30
+
31
+ VALUE _rb_v = ULL2NUM((unsigned long long) info.freeram) ;
32
+ VALUE _rb_mem_unit = ULL2NUM((unsigned long long) info.mem_unit) ;
33
+ return rb_funcallv_public(_rb_v, rb_intern("*"), 1, &_rb_mem_unit) ;
34
+ }
35
+
36
+ VALUE sharedram(VALUE obj) {
37
+ short status = sysinfo(&info) ;
38
+ if (status < 0) return Qnil ;
39
+
40
+ VALUE _rb_v = ULL2NUM((unsigned long long) info.sharedram) ;
41
+ VALUE _rb_mem_unit = ULL2NUM((unsigned long long) info.mem_unit) ;
42
+ return rb_funcallv_public(_rb_v, rb_intern("*"), 1, &_rb_mem_unit) ;
43
+ }
44
+
45
+ VALUE bufferram(VALUE obj) {
46
+ short status = sysinfo(&info) ;
47
+ if (status < 0) return Qnil ;
48
+
49
+ VALUE _rb_v = ULL2NUM((unsigned long long) info.bufferram) ;
50
+ VALUE _rb_mem_unit = ULL2NUM((unsigned long long) info.mem_unit) ;
51
+ return rb_funcallv_public(_rb_v, rb_intern("*"), 1, &_rb_mem_unit) ;
52
+ }
53
+
54
+ VALUE totalswap(VALUE obj) {
55
+ static struct sysinfo info ;
56
+ short status = sysinfo(&info) ;
57
+ if (status < 0) return Qnil ;
58
+
59
+ VALUE _rb_v = ULL2NUM((unsigned long long) info.totalswap) ;
60
+ VALUE _rb_mem_unit = ULL2NUM((unsigned long long) info.mem_unit) ;
61
+ return rb_funcallv_public(_rb_v, rb_intern("*"), 1, &_rb_mem_unit) ;
62
+ }
63
+
64
+ VALUE freeswap(VALUE obj) {
65
+ short status = sysinfo(&info) ;
66
+ if (status < 0) return Qnil ;
67
+
68
+ VALUE _rb_v = ULL2NUM((unsigned long long) info.freeswap) ;
69
+ VALUE _rb_mem_unit = ULL2NUM((unsigned long long) info.mem_unit) ;
70
+ return rb_funcallv_public(_rb_v, rb_intern("*"), 1, &_rb_mem_unit) ;
71
+ }
72
+
73
+ VALUE totalhigh(VALUE obj) {
74
+ short status = sysinfo(&info) ;
75
+ if (status < 0) return Qnil ;
76
+
77
+ VALUE _rb_v = ULL2NUM((unsigned long long) info.totalhigh) ;
78
+ VALUE _rb_mem_unit = ULL2NUM((unsigned long long) info.mem_unit) ;
79
+ return rb_funcallv_public(_rb_v, rb_intern("*"), 1, &_rb_mem_unit) ;
80
+ }
81
+
82
+ VALUE freehigh(VALUE obj) {
83
+ short status = sysinfo(&info) ;
84
+ if (status < 0) return Qnil ;
85
+
86
+ VALUE _rb_v = ULL2NUM((unsigned long long) info.freehigh) ;
87
+ VALUE _rb_mem_unit = ULL2NUM((unsigned long long) info.mem_unit) ;
88
+ return rb_funcallv_public(_rb_v, rb_intern("*"), 1, &_rb_mem_unit) ;
89
+ }
90
+
91
+ VALUE uptime(VALUE obj) {
92
+ short status = sysinfo(&info) ;
93
+ if (status < 0) return Qnil ;
94
+
95
+ uint64_t v = info.uptime ;
96
+ return ULL2NUM((unsigned long long) v) ;
97
+ }
98
+
99
+ VALUE loads(VALUE obj) {
100
+ short status = sysinfo(&info) ;
101
+ if(status < 0) return rb_ary_new() ;
102
+
103
+ long double load = 1.f / (1 << SI_LOAD_SHIFT) ;
104
+
105
+ float l_1 = info.loads[0] * load ;
106
+ float l_5 = info.loads[1] * load ;
107
+ float l_15 = info.loads[2] * load ;
108
+
109
+ return rb_ary_new_from_args(3,
110
+ rb_float_new(l_1),
111
+ rb_float_new(l_5),
112
+ rb_float_new(l_15)
113
+ ) ;
114
+ }
115
+
116
+ void Init_sysinfo() {
117
+ VALUE _linux_stat = rb_define_module("LinuxStat") ;
118
+ VALUE _sysinfo = rb_define_module_under(_linux_stat, "Sysinfo") ;
119
+
120
+ rb_define_module_function(_sysinfo, "totalram", totalram, 0) ;
121
+ rb_define_module_function(_sysinfo, "freeram", freeram, 0) ;
122
+ rb_define_module_function(_sysinfo, "sharedram", sharedram, 0) ;
123
+ rb_define_module_function(_sysinfo, "bufferram", bufferram, 0) ;
124
+ rb_define_module_function(_sysinfo, "totalswap", totalswap, 0) ;
125
+ rb_define_module_function(_sysinfo, "freeswap", freeswap, 0) ;
126
+ rb_define_module_function(_sysinfo, "totalhigh", totalhigh, 0) ;
127
+ rb_define_module_function(_sysinfo, "freehigh", freehigh, 0) ;
128
+ rb_define_module_function(_sysinfo, "uptime", uptime, 0) ;
129
+ rb_define_module_function(_sysinfo, "loads", loads, 0) ;
130
+ }
@@ -23,20 +23,23 @@ require "linux_stat/version"
23
23
  # But might be required by other module functions in "Dependent Modules" section
24
24
  require "linux_stat/battery"
25
25
  require "linux_stat/bios"
26
- require "linux_stat/memory"
27
26
  require "linux_stat/net"
28
27
  require "linux_stat/pci"
29
28
  require "linux_stat/process"
30
- require "linux_stat/swap"
31
29
  require "linux_stat/thermal"
32
30
  require "linux_stat/usb"
33
31
 
34
32
  # Dependent Modules
35
33
  # Modules that can have reverse dependency
36
34
 
35
+ # LinuxStat::CPU.sysinfo dependent modules
36
+ require "linux_stat/sysinfo"
37
+ require "linux_stat/swap"
38
+ require "linux_stat/memory"
39
+
37
40
  # LinuxStat::CPU.nproc dependent modules
38
- require "linux_stat/cpu"
39
41
  require "linux_stat/nproc"
42
+ require "linux_stat/cpu"
40
43
 
41
44
  # LinuxStat::Uname dependent modules
42
45
  require 'linux_stat/utsname'
@@ -35,13 +35,23 @@ module LinuxStat
35
35
  end
36
36
 
37
37
  ##
38
- # Returns the total memory details reported by /proc/meminfo.
38
+ # Returns the total memory reported by LS::Sysinfo.totalram()
39
39
  # The value is in Kilobyte.
40
40
  #
41
41
  # It retuns an Integer but if the info is not available, it will return nil.
42
42
  def total
43
- return nil unless meminfo?
44
- IO.foreach('/proc/meminfo'.freeze).first.split[1].to_i
43
+ v = LinuxStat::Sysinfo.totalram
44
+ v ? v.fdiv(1024).to_i : nil
45
+ end
46
+
47
+ ##
48
+ # Returns the free memory reported by LS::Sysinfo.freeram()
49
+ # The value is in Kilobyte.
50
+ #
51
+ # It retuns an Integer but if the info is not available, it will return nil.
52
+ def free
53
+ v = LinuxStat::Sysinfo.freeram
54
+ v ? v.fdiv(1024).to_i : nil
45
55
  end
46
56
 
47
57
  ##
@@ -158,6 +158,40 @@ module LinuxStat
158
158
  }.freeze
159
159
  end
160
160
 
161
+ ##
162
+ # Returns uptime of the system reported by LinuxStat::Sysinfo.uptime()
163
+ # LinuxStat::OS.uptime_i
164
+ #
165
+ # 28956
166
+ #
167
+ # If the stat isn't available, nil is returned.
168
+ def uptime_i
169
+ LinuxStat::Sysinfo.uptime
170
+ end
171
+
172
+ ##
173
+ # The first three fields in this file are load average
174
+ # figures giving the number of jobs in the run queue (state R)
175
+ # or waiting for disk I/O (state D) averaged over 1, 5,
176
+ # and 15 minutes. They are the same as the load average
177
+ # numbers given by uptime(1) and other programs.
178
+ # https://man7.org/linux/man-pages/man5/procfs.5.html
179
+ #
180
+ # The return type is an Hash containing the values
181
+ # that maps to 1, 5, and 15.
182
+ # This method calls LinuxStat::Sysinfo.loads() directly.
183
+ #
184
+ # However, if the info isn't available, it will return nil as values.
185
+ def loadavg
186
+ loads = LinuxStat::Sysinfo.loads
187
+
188
+ {
189
+ 1 => loads[0],
190
+ 5 => loads[1],
191
+ 15 => loads[2]
192
+ }
193
+ end
194
+
161
195
  alias distrib_version version
162
196
 
163
197
  private
@@ -57,8 +57,19 @@ module LinuxStat
57
57
  #
58
58
  # The return type is a Integer but if the info isn't available, it will return nil.
59
59
  def total
60
- return nil unless swaps_readable?
61
- read_usage[0].sum
60
+ v = LinuxStat::Sysinfo.totalswap
61
+ v ? v.fdiv(1024).to_i : nil
62
+ end
63
+
64
+ ##
65
+ # Shows free swap.
66
+ #
67
+ # The value is in kilobytes.
68
+ #
69
+ # The return type is a Integer but if the info isn't available, it will return nil.
70
+ def free
71
+ v = LinuxStat::Sysinfo.freeswap
72
+ v ? v.fdiv(1024).to_i : nil
62
73
  end
63
74
 
64
75
  ##
@@ -1,3 +1,3 @@
1
1
  module LinuxStat
2
- VERSION ||= "1.4.0"
2
+ VERSION ||= "1.5.1"
3
3
  end
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.4.0
4
+ version: 1.5.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: 2021-01-19 00:00:00.000000000 Z
11
+ date: 2021-01-22 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: Linux only, efficient linux system utilization reporting and system monitoring
14
14
  gem
@@ -20,6 +20,7 @@ extensions:
20
20
  - ext/fs_stat/extconf.rb
21
21
  - ext/nproc/extconf.rb
22
22
  - ext/sysconf/extconf.rb
23
+ - ext/sysinfo/extconf.rb
23
24
  - ext/utsname/extconf.rb
24
25
  extra_rdoc_files:
25
26
  - README.md
@@ -35,6 +36,8 @@ files:
35
36
  - ext/nproc/nproc.c
36
37
  - ext/sysconf/extconf.rb
37
38
  - ext/sysconf/sysconf.c
39
+ - ext/sysinfo/extconf.rb
40
+ - ext/sysinfo/sysinfo.c
38
41
  - ext/utsname/extconf.rb
39
42
  - ext/utsname/utsname.c
40
43
  - lib/linux_stat.rb