linux_stat 1.1.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 +84 -64
- data/ext/sysconf/sysconf.c +11 -0
- data/lib/linux_stat/os.rb +48 -15
- data/lib/linux_stat/version.rb +1 -1
- metadata +1 -1
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
|
|
@@ -114,7 +114,7 @@ LinuxStat::BIOS.version()
|
|
114
114
|
# File: battery.rb | Line: 105
|
115
115
|
# Definition: def charge
|
116
116
|
LinuxStat::Battery.charge()
|
117
|
-
=>
|
117
|
+
=> 100.0
|
118
118
|
|
119
119
|
# File: battery.rb | Line: 122
|
120
120
|
# Definition: def charge_full_design_wh
|
@@ -134,7 +134,7 @@ LinuxStat::Battery.charging?()
|
|
134
134
|
# File: battery.rb | Line: 184
|
135
135
|
# Definition: def devices_stat
|
136
136
|
LinuxStat::Battery.devices_stat()
|
137
|
-
=> {: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=>"Full", :capacity=>100, :voltage_min_design=>11.4, :charge_full_design=>3.684, :charge_full_design_wh=>42.0, :voltage_now=>12....
|
138
138
|
|
139
139
|
# File: battery.rb | Line: 87
|
140
140
|
# Definition: def discharging?
|
@@ -144,7 +144,7 @@ LinuxStat::Battery.discharging?()
|
|
144
144
|
# File: battery.rb | Line: 96
|
145
145
|
# Definition: def full?
|
146
146
|
LinuxStat::Battery.full?()
|
147
|
-
=>
|
147
|
+
=> true
|
148
148
|
|
149
149
|
# File: battery.rb | Line: 47
|
150
150
|
# Definition: def manufacturer
|
@@ -164,12 +164,12 @@ LinuxStat::Battery.present?()
|
|
164
164
|
# File: battery.rb | Line: 16
|
165
165
|
# Definition: def stat
|
166
166
|
LinuxStat::Battery.stat()
|
167
|
-
=> {:model=>"DELL CYMGM77", :manufacturer=>"Samsung SDI", :technology=>"Li-ion", :status=>"
|
167
|
+
=> {:model=>"DELL CYMGM77", :manufacturer=>"Samsung SDI", :technology=>"Li-ion", :status=>"Full", :charge=>100.0, :charging=>true, :discharging=>false, :full=>true}
|
168
168
|
|
169
169
|
# File: battery.rb | Line: 68
|
170
170
|
# Definition: def status
|
171
171
|
LinuxStat::Battery.status()
|
172
|
-
=> "
|
172
|
+
=> "Full"
|
173
173
|
|
174
174
|
# File: battery.rb | Line: 57
|
175
175
|
# Definition: def technology
|
@@ -179,7 +179,7 @@ LinuxStat::Battery.technology()
|
|
179
179
|
# File: battery.rb | Line: 160
|
180
180
|
# Definition: def voltage_now
|
181
181
|
LinuxStat::Battery.voltage_now()
|
182
|
-
=> 12.
|
182
|
+
=> 12.625
|
183
183
|
|
184
184
|
```
|
185
185
|
|
@@ -203,7 +203,7 @@ LinuxStat::CPU.count_online()
|
|
203
203
|
# File: cpu.rb | Line: 197
|
204
204
|
# Definition: def cur_freq
|
205
205
|
LinuxStat::CPU.cur_freq()
|
206
|
-
=> {"cpu0"=>
|
206
|
+
=> {"cpu0"=>1999999, "cpu1"=>2000045, "cpu2"=>2000144, "cpu3"=>2000034}
|
207
207
|
|
208
208
|
# File: cpu.rb | Line: 265
|
209
209
|
# Definition: def governor
|
@@ -238,29 +238,29 @@ LinuxStat::CPU.online()
|
|
238
238
|
# File: cpu.rb | Line: 23
|
239
239
|
# Definition: def stat(sleep = ticks_to_ms_t5)
|
240
240
|
LinuxStat::CPU.stat(sleep)
|
241
|
-
=> {0=>
|
241
|
+
=> {0=>10.0, 1=>0.0, 2=>0.0, 3=>16.67, 4=>0.0}
|
242
242
|
|
243
243
|
# File: cpu.rb | Line: 63
|
244
244
|
# Definition: def total_usage(sleep = ticks_to_ms_t5)
|
245
245
|
LinuxStat::CPU.total_usage(sleep)
|
246
|
-
=>
|
246
|
+
=> 19.05
|
247
247
|
|
248
248
|
# File: cpu.rb | Line: 63
|
249
249
|
# Definition: def total_usage(sleep = ticks_to_ms_t5)
|
250
250
|
LinuxStat::CPU.usage(sleep)
|
251
|
-
=>
|
251
|
+
=> 5.26
|
252
252
|
|
253
253
|
# File: cpu.rb | Line: 23
|
254
254
|
# Definition: def stat(sleep = ticks_to_ms_t5)
|
255
255
|
LinuxStat::CPU.usages(sleep)
|
256
|
-
=> {0=>
|
256
|
+
=> {0=>5.26, 1=>0.0, 2=>0.0, 3=>33.33, 4=>20.0}
|
257
257
|
|
258
258
|
```
|
259
259
|
|
260
260
|
### LinuxStat::FS
|
261
261
|
```
|
262
262
|
LinuxStat::FS.stat(arg = "/")
|
263
|
-
=> {: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}
|
264
264
|
|
265
265
|
```
|
266
266
|
|
@@ -269,22 +269,22 @@ LinuxStat::FS.stat(arg = "/")
|
|
269
269
|
# File: filesystem.rb | Line: 92
|
270
270
|
# Definition: def available(fs = ?..freeze)
|
271
271
|
LinuxStat::Filesystem.available(fs)
|
272
|
-
=>
|
272
|
+
=> 44429180928
|
273
273
|
|
274
274
|
# File: filesystem.rb | Line: 58
|
275
275
|
# Definition: def free(fs = ?..freeze)
|
276
276
|
LinuxStat::Filesystem.free(fs)
|
277
|
-
=>
|
277
|
+
=> 44429180928
|
278
278
|
|
279
279
|
# File: filesystem.rb | Line: 19
|
280
280
|
# Definition: def stat(fs = ?..freeze)
|
281
281
|
LinuxStat::Filesystem.stat(fs)
|
282
|
-
=> {:total=>119981191168, :free=>
|
282
|
+
=> {:total=>119981191168, :free=>44429180928, :used=>75552010240}
|
283
283
|
|
284
284
|
# File: filesystem.rb | Line: 108
|
285
285
|
# Definition: def stat_raw(fs = ?..freeze)
|
286
286
|
LinuxStat::Filesystem.stat_raw(fs)
|
287
|
-
=> {: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}
|
288
288
|
|
289
289
|
# File: filesystem.rb | Line: 39
|
290
290
|
# Definition: def total(fs = ?..freeze)
|
@@ -294,7 +294,7 @@ LinuxStat::Filesystem.total(fs)
|
|
294
294
|
# File: filesystem.rb | Line: 73
|
295
295
|
# Definition: def used(fs = ?..freeze)
|
296
296
|
LinuxStat::Filesystem.used(fs)
|
297
|
-
=>
|
297
|
+
=> 75552010240
|
298
298
|
|
299
299
|
```
|
300
300
|
|
@@ -357,22 +357,22 @@ LinuxStat::Kernel.version()
|
|
357
357
|
# File: memory.rb | Line: 50
|
358
358
|
# Definition: def available
|
359
359
|
LinuxStat::Memory.available()
|
360
|
-
=>
|
360
|
+
=> 375384
|
361
361
|
|
362
362
|
# File: memory.rb | Line: 81
|
363
363
|
# Definition: def percent_available
|
364
364
|
LinuxStat::Memory.percent_available()
|
365
|
-
=>
|
365
|
+
=> 9.79
|
366
366
|
|
367
367
|
# File: memory.rb | Line: 70
|
368
368
|
# Definition: def percent_used
|
369
369
|
LinuxStat::Memory.percent_used()
|
370
|
-
=>
|
370
|
+
=> 90.21
|
371
371
|
|
372
372
|
# File: memory.rb | Line: 11
|
373
373
|
# Definition: def stat
|
374
374
|
LinuxStat::Memory.stat()
|
375
|
-
=> {:total=>3836036, :used=>
|
375
|
+
=> {:total=>3836036, :used=>3460652, :available=>375384, :percent_used=>90.21, :percent_available=>9.79}
|
376
376
|
|
377
377
|
# File: memory.rb | Line: 40
|
378
378
|
# Definition: def total
|
@@ -382,7 +382,7 @@ LinuxStat::Memory.total()
|
|
382
382
|
# File: memory.rb | Line: 60
|
383
383
|
# Definition: def used
|
384
384
|
LinuxStat::Memory.used()
|
385
|
-
=>
|
385
|
+
=> 3460652
|
386
386
|
|
387
387
|
```
|
388
388
|
|
@@ -391,7 +391,7 @@ LinuxStat::Memory.used()
|
|
391
391
|
# File: mounts.rb | Line: 179
|
392
392
|
# Definition: def device_stat(dev = root)
|
393
393
|
LinuxStat::Mounts.device_stat(dev)
|
394
|
-
=> {: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}
|
395
395
|
|
396
396
|
# File: mounts.rb | Line: 137
|
397
397
|
# Definition: def devices_stat
|
@@ -411,7 +411,7 @@ LinuxStat::Mounts.list_devices()
|
|
411
411
|
# File: mounts.rb | Line: 109
|
412
412
|
# Definition: def list_devices_mount_point
|
413
413
|
LinuxStat::Mounts.list_devices_mount_point()
|
414
|
-
=> {"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...
|
415
415
|
|
416
416
|
# File: mounts.rb | Line: 80
|
417
417
|
# Definition: def mount_point(dev = root)
|
@@ -445,7 +445,7 @@ LinuxStat::Mounts.tmpfs()
|
|
445
445
|
# File: net.rb | Line: 84
|
446
446
|
# Definition: def usage(interval = 0.1)
|
447
447
|
LinuxStat::Net.current_usage(interval)
|
448
|
-
=> {:received=>
|
448
|
+
=> {:received=>279000.0, :transmitted=>5640.0}
|
449
449
|
|
450
450
|
# File: net.rb | Line: 10
|
451
451
|
# Definition: def ipv4_private
|
@@ -455,38 +455,43 @@ LinuxStat::Net.ipv4_private()
|
|
455
455
|
# File: net.rb | Line: 25
|
456
456
|
# Definition: def total_bytes
|
457
457
|
LinuxStat::Net.total_bytes()
|
458
|
-
=> {:received=>
|
458
|
+
=> {:received=>2093813713, :transmitted=>138899807}
|
459
459
|
|
460
460
|
# File: net.rb | Line: 43
|
461
461
|
# Definition: def total_bytes_received
|
462
462
|
LinuxStat::Net.total_bytes_received()
|
463
|
-
=>
|
463
|
+
=> 2093813713
|
464
464
|
|
465
465
|
# File: net.rb | Line: 56
|
466
466
|
# Definition: def total_bytes_transmitted
|
467
467
|
LinuxStat::Net.total_bytes_transmitted()
|
468
|
-
=>
|
468
|
+
=> 138899807
|
469
469
|
|
470
470
|
# File: net.rb | Line: 84
|
471
471
|
# Definition: def usage(interval = 0.1)
|
472
472
|
LinuxStat::Net.usage(interval)
|
473
|
-
=> {:received=>
|
473
|
+
=> {:received=>419320.0, :transmitted=>10340.0}
|
474
474
|
|
475
475
|
```
|
476
476
|
|
477
477
|
### LinuxStat::OS
|
478
478
|
```
|
479
|
-
# File: os.rb | Line:
|
479
|
+
# File: os.rb | Line: 127
|
480
480
|
# Definition: def bits
|
481
481
|
LinuxStat::OS.bits()
|
482
482
|
=> 64
|
483
483
|
|
484
|
+
# File: os.rb | Line: 82
|
485
|
+
# Definition: def version
|
486
|
+
LinuxStat::OS.distrib_version()
|
487
|
+
=> "rolling"
|
488
|
+
|
484
489
|
# File: os.rb | Line: 44
|
485
490
|
# Definition: def distribution
|
486
491
|
LinuxStat::OS.distribution()
|
487
492
|
=> "Arch Linux"
|
488
493
|
|
489
|
-
# File: os.rb | Line:
|
494
|
+
# File: os.rb | Line: 115
|
490
495
|
# Definition: def hostname
|
491
496
|
LinuxStat::OS.hostname()
|
492
497
|
=> "archlinux"
|
@@ -496,12 +501,12 @@ LinuxStat::OS.hostname()
|
|
496
501
|
LinuxStat::OS.lsb_release()
|
497
502
|
=> {:LSB_VERSION=>"1.4", :DISTRIB_ID=>"Arch", :DISTRIB_RELEASE=>"rolling", :DISTRIB_DESCRIPTION=>"Arch Linux"}
|
498
503
|
|
499
|
-
# File: os.rb | Line:
|
504
|
+
# File: os.rb | Line: 98
|
500
505
|
# Definition: def machine
|
501
506
|
LinuxStat::OS.machine()
|
502
507
|
=> "x86_64"
|
503
508
|
|
504
|
-
# File: os.rb | Line:
|
509
|
+
# File: os.rb | Line: 106
|
505
510
|
# Definition: def nodename
|
506
511
|
LinuxStat::OS.nodename()
|
507
512
|
=> "archlinux"
|
@@ -511,10 +516,15 @@ LinuxStat::OS.nodename()
|
|
511
516
|
LinuxStat::OS.os_release()
|
512
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/"...
|
513
518
|
|
514
|
-
# File: os.rb | Line:
|
519
|
+
# File: os.rb | Line: 142
|
515
520
|
# Definition: def uptime
|
516
521
|
LinuxStat::OS.uptime()
|
517
|
-
=> {: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"
|
518
528
|
|
519
529
|
```
|
520
530
|
|
@@ -561,23 +571,23 @@ LinuxStat::PCI.initialize_hwdata()
|
|
561
571
|
```
|
562
572
|
# File: prettify_bytes.rb | Line: 42
|
563
573
|
# Definition: def convert_binary(n)
|
564
|
-
LinuxStat::PrettifyBytes.convert_binary(n =
|
565
|
-
=> "
|
574
|
+
LinuxStat::PrettifyBytes.convert_binary(n = 320846048510750)
|
575
|
+
=> "291.81 tebibytes"
|
566
576
|
|
567
577
|
# File: prettify_bytes.rb | Line: 19
|
568
578
|
# Definition: def convert_decimal(n)
|
569
|
-
LinuxStat::PrettifyBytes.convert_decimal(n =
|
570
|
-
=> "
|
579
|
+
LinuxStat::PrettifyBytes.convert_decimal(n = 996984130887475)
|
580
|
+
=> "996.98 terabytes"
|
571
581
|
|
572
582
|
# File: prettify_bytes.rb | Line: 90
|
573
583
|
# Definition: def convert_short_binary(n)
|
574
|
-
LinuxStat::PrettifyBytes.convert_short_binary(n =
|
575
|
-
=> "
|
584
|
+
LinuxStat::PrettifyBytes.convert_short_binary(n = 396350966829319)
|
585
|
+
=> "360.48 TiB"
|
576
586
|
|
577
587
|
# File: prettify_bytes.rb | Line: 65
|
578
588
|
# Definition: def convert_short_decimal(n)
|
579
|
-
LinuxStat::PrettifyBytes.convert_short_decimal(n =
|
580
|
-
=> "
|
589
|
+
LinuxStat::PrettifyBytes.convert_short_decimal(n = 558910893490277)
|
590
|
+
=> "558.91 TB"
|
581
591
|
|
582
592
|
```
|
583
593
|
|
@@ -586,12 +596,12 @@ LinuxStat::PrettifyBytes.convert_short_decimal(n = 448181119260617)
|
|
586
596
|
# File: process.rb | Line: 19
|
587
597
|
# Definition: def count
|
588
598
|
LinuxStat::Process.count()
|
589
|
-
=>
|
599
|
+
=> 210
|
590
600
|
|
591
601
|
# File: process.rb | Line: 71
|
592
602
|
# Definition: def idle
|
593
603
|
LinuxStat::Process.idle()
|
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,
|
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...
|
595
605
|
|
596
606
|
# File: process.rb | Line: 8
|
597
607
|
# Definition: def list
|
@@ -606,12 +616,12 @@ LinuxStat::Process.names()
|
|
606
616
|
# File: process.rb | Line: 97
|
607
617
|
# Definition: def running
|
608
618
|
LinuxStat::Process.running()
|
609
|
-
=> [
|
619
|
+
=> [34967]
|
610
620
|
|
611
621
|
# File: process.rb | Line: 58
|
612
622
|
# Definition: def sleeping
|
613
623
|
LinuxStat::Process.sleeping()
|
614
|
-
=> [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...
|
615
625
|
|
616
626
|
# File: process.rb | Line: 37
|
617
627
|
# Definition: def types
|
@@ -630,7 +640,7 @@ LinuxStat::Process.zombie()
|
|
630
640
|
# File: process_info.rb | Line: 54
|
631
641
|
# Definition: def cmdline(pid = $$)
|
632
642
|
LinuxStat::ProcessInfo.cmdline(pid)
|
633
|
-
=> "/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"
|
634
644
|
|
635
645
|
# File: process_info.rb | Line: 78
|
636
646
|
# Definition: def command_name(pid = $$)
|
@@ -665,12 +675,12 @@ LinuxStat::ProcessInfo.last_executed_cpu(pid)
|
|
665
675
|
# File: process_info.rb | Line: 114
|
666
676
|
# Definition: def mem_stat(pid = $$)
|
667
677
|
LinuxStat::ProcessInfo.mem_stat(pid)
|
668
|
-
=> {:memory=>
|
678
|
+
=> {:memory=>26836.992, :virtual_memory=>97992.704, :resident_memory=>32841.728}
|
669
679
|
|
670
680
|
# File: process_info.rb | Line: 147
|
671
681
|
# Definition: def memory(pid = $$)
|
672
682
|
LinuxStat::ProcessInfo.memory(pid)
|
673
|
-
=>
|
683
|
+
=> 26836.992
|
674
684
|
|
675
685
|
# File: process_info.rb | Line: 607
|
676
686
|
# Definition: def nice(pid = $$)
|
@@ -690,7 +700,7 @@ LinuxStat::ProcessInfo.owner(pid)
|
|
690
700
|
# File: process_info.rb | Line: 197
|
691
701
|
# Definition: def resident_memory(pid = $$)
|
692
702
|
LinuxStat::ProcessInfo.resident_memory(pid)
|
693
|
-
=>
|
703
|
+
=> 32841.728
|
694
704
|
|
695
705
|
# File: process_info.rb | Line: 563
|
696
706
|
# Definition: def running_time(pid = $$)
|
@@ -700,12 +710,12 @@ LinuxStat::ProcessInfo.running_time(pid)
|
|
700
710
|
# File: process_info.rb | Line: 544
|
701
711
|
# Definition: def start_time(pid = $$)
|
702
712
|
LinuxStat::ProcessInfo.start_time(pid)
|
703
|
-
=> 2020-12-
|
713
|
+
=> 2020-12-29 01:58:56 +0530
|
704
714
|
|
705
715
|
# File: process_info.rb | Line: 513
|
706
716
|
# Definition: def start_time_epoch(pid = $$)
|
707
717
|
LinuxStat::ProcessInfo.start_time_epoch(pid)
|
708
|
-
=>
|
718
|
+
=> 1609187336
|
709
719
|
|
710
720
|
# File: process_info.rb | Line: 592
|
711
721
|
# Definition: def state(pid = $$)
|
@@ -725,7 +735,7 @@ LinuxStat::ProcessInfo.threads(pid)
|
|
725
735
|
# File: process_info.rb | Line: 23
|
726
736
|
# Definition: def total_io(pid = $$)
|
727
737
|
LinuxStat::ProcessInfo.total_io(pid)
|
728
|
-
=> {:read_bytes=>
|
738
|
+
=> {:read_bytes=>1249280, :write_bytes=>0}
|
729
739
|
|
730
740
|
# File: process_info.rb | Line: 446
|
731
741
|
# Definition: def uid(pid = $$)
|
@@ -735,7 +745,7 @@ LinuxStat::ProcessInfo.uid(pid)
|
|
735
745
|
# File: process_info.rb | Line: 172
|
736
746
|
# Definition: def virtual_memory(pid = $$)
|
737
747
|
LinuxStat::ProcessInfo.virtual_memory(pid)
|
738
|
-
=>
|
748
|
+
=> 97992.704
|
739
749
|
|
740
750
|
```
|
741
751
|
|
@@ -749,27 +759,27 @@ LinuxStat::Swap.any?()
|
|
749
759
|
# File: swap.rb | Line: 68
|
750
760
|
# Definition: def available
|
751
761
|
LinuxStat::Swap.available()
|
752
|
-
=>
|
762
|
+
=> 2293908
|
753
763
|
|
754
764
|
# File: swap.rb | Line: 8
|
755
765
|
# Definition: def list
|
756
766
|
LinuxStat::Swap.list()
|
757
|
-
=> {"/dev/zram0"=>[:partition, 4194300,
|
767
|
+
=> {"/dev/zram0"=>[:partition, 4194300, 1900392, -2]}
|
758
768
|
|
759
769
|
# File: swap.rb | Line: 103
|
760
770
|
# Definition: def percent_available
|
761
771
|
LinuxStat::Swap.percent_available()
|
762
|
-
=> 69
|
772
|
+
=> 54.69
|
763
773
|
|
764
774
|
# File: swap.rb | Line: 89
|
765
775
|
# Definition: def percent_used
|
766
776
|
LinuxStat::Swap.percent_used()
|
767
|
-
=>
|
777
|
+
=> 45.31
|
768
778
|
|
769
779
|
# File: swap.rb | Line: 32
|
770
780
|
# Definition: def stat
|
771
781
|
LinuxStat::Swap.stat()
|
772
|
-
=> {:total=>4194300, :used=>
|
782
|
+
=> {:total=>4194300, :used=>1900392, :available=>2293908, :percent_used=>45.31, :percent_available=>54.69}
|
773
783
|
|
774
784
|
# File: swap.rb | Line: 57
|
775
785
|
# Definition: def total
|
@@ -779,7 +789,7 @@ LinuxStat::Swap.total()
|
|
779
789
|
# File: swap.rb | Line: 80
|
780
790
|
# Definition: def used
|
781
791
|
LinuxStat::Swap.used()
|
782
|
-
=>
|
792
|
+
=> 1900392
|
783
793
|
|
784
794
|
```
|
785
795
|
|
@@ -806,6 +816,9 @@ LinuxStat::Sysconf.get_uid()
|
|
806
816
|
LinuxStat::Sysconf.get_user()
|
807
817
|
=> "sourav"
|
808
818
|
|
819
|
+
LinuxStat::Sysconf.hostname()
|
820
|
+
=> "archlinux"
|
821
|
+
|
809
822
|
LinuxStat::Sysconf.hostname_max()
|
810
823
|
=> 64
|
811
824
|
|
@@ -1363,7 +1376,14 @@ Right, the get_login() can return an empty string. But LinuxStat::User.get_user
|
|
1363
1376
|
|
1364
1377
|
## Note 7: Hwdata
|
1365
1378
|
The PCI and USB modules actually rely on hwdata found in /usr/share/hwdata/.
|
1366
|
-
|
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.
|
1367
1387
|
|
1368
1388
|
So it's suggested to install hwdata. But you might face issues with heroku and
|
1369
1389
|
other online PaaS where you can't install it. So Version 1.1.1+ comes with a module function called `hwdata_file = file`.
|
@@ -1377,7 +1397,7 @@ LS::USB.hwdata_file = File.join(__dir__, 'hwdata', 'usb.ids')
|
|
1377
1397
|
|
1378
1398
|
Assuming that you have `pci.ids` and `usb.ids` under ./hwdata directory.
|
1379
1399
|
|
1380
|
-
On rails, you can put this (replace `__dir__` with `Rails.root` inside environment.rb
|
1400
|
+
On rails, you can put this (replace `__dir__` with `Rails.root`) inside environment.rb.
|
1381
1401
|
|
1382
1402
|
But do note that the file can be set only once. It's suggested to do that in the beginning of your app.
|
1383
1403
|
|
data/ext/sysconf/sysconf.c
CHANGED
@@ -119,6 +119,15 @@ static VALUE getEUID(VALUE obj) {
|
|
119
119
|
return INT2FIX(geteuid()) ;
|
120
120
|
}
|
121
121
|
|
122
|
+
static VALUE getHostname(VALUE obj) {
|
123
|
+
int h_max = sysconf(_SC_HOST_NAME_MAX) + 1 ;
|
124
|
+
char hostname[h_max] ;
|
125
|
+
|
126
|
+
short int status = gethostname(hostname, h_max) ;
|
127
|
+
|
128
|
+
return (status < 0) ? rb_str_new_cstr("") : rb_str_new_cstr(hostname) ;
|
129
|
+
}
|
130
|
+
|
122
131
|
void Init_sysconf() {
|
123
132
|
VALUE _linux_stat = rb_define_module("LinuxStat") ;
|
124
133
|
VALUE _sysconf = rb_define_module_under(_linux_stat, "Sysconf") ;
|
@@ -144,4 +153,6 @@ void Init_sysconf() {
|
|
144
153
|
|
145
154
|
rb_define_module_function(_sysconf, "get_user", getUser, 0) ;
|
146
155
|
rb_define_module_function(_sysconf, "get_login", getUser, 0) ;
|
156
|
+
|
157
|
+
rb_define_module_function(_sysconf, "hostname", getHostname, 0) ;
|
147
158
|
}
|
data/lib/linux_stat/os.rb
CHANGED
@@ -51,14 +51,46 @@ module LinuxStat
|
|
51
51
|
v[:DISTRIB_DESCRIPTION]
|
52
52
|
elsif v.key?(:DISTRIB_ID)
|
53
53
|
v[:DISTRIB_ID]
|
54
|
-
elsif File.readable?('/etc/issue')
|
55
|
-
IO.read('/etc/issue').strip
|
54
|
+
elsif File.readable?('/etc/issue'.freeze)
|
55
|
+
IO.read('/etc/issue'.freeze, encoding: 'ASCII-8bit').strip
|
56
56
|
else
|
57
57
|
'Unknown'.freeze
|
58
58
|
end
|
59
59
|
end
|
60
60
|
end
|
61
61
|
|
62
|
+
##
|
63
|
+
# Gives you the version of the OS you are using.
|
64
|
+
#
|
65
|
+
# On ArchLinux for example:
|
66
|
+
# LinuxStat::OS.version
|
67
|
+
#
|
68
|
+
# => "rolling"
|
69
|
+
#
|
70
|
+
# On Ubuntu 20.04:
|
71
|
+
# LinuxStat::OS.version
|
72
|
+
#
|
73
|
+
# => "20.04"
|
74
|
+
#
|
75
|
+
# On CentOS 26:
|
76
|
+
# LinuxStat::OS.version
|
77
|
+
#
|
78
|
+
# => "26"
|
79
|
+
#
|
80
|
+
# The return type is String.
|
81
|
+
# But if the information isn't available, it will return an empty frozen String.
|
82
|
+
def version
|
83
|
+
@@distrib_version ||= if os_release.key?(:VERSION_ID)
|
84
|
+
os_release[:VERSION_ID]
|
85
|
+
elsif lsb_release.key?(:DISTRIB_RELEASE)
|
86
|
+
lsb_release[:DISTRIB_RELEASE]
|
87
|
+
elsif os_release.key?(:VERSION)
|
88
|
+
os_release[:VERSION]
|
89
|
+
else
|
90
|
+
''.freeze
|
91
|
+
end
|
92
|
+
end
|
93
|
+
|
62
94
|
##
|
63
95
|
# Uses utsname.h to determine the machine
|
64
96
|
#
|
@@ -70,22 +102,18 @@ module LinuxStat
|
|
70
102
|
##
|
71
103
|
# Uses utsname.h to determine the system nodename
|
72
104
|
#
|
73
|
-
# It returns String but if the info isn't available, it will return an empty String
|
105
|
+
# It returns String but if the info isn't available, it will return an empty String.
|
74
106
|
def nodename
|
75
|
-
|
107
|
+
LinuxStat::Uname.nodename
|
76
108
|
end
|
77
109
|
|
78
110
|
##
|
79
|
-
#
|
111
|
+
# Returns the hostname from LinuxStat::Sysconf.hostname.
|
80
112
|
#
|
81
113
|
# The return type is String.
|
82
|
-
# If the info info isn't available, it will return
|
114
|
+
# If the info info isn't available, it will return an empty String.
|
83
115
|
def hostname
|
84
|
-
|
85
|
-
IO.read('/etc/hostname').strip
|
86
|
-
else
|
87
|
-
'localhost'
|
88
|
-
end
|
116
|
+
LinuxStat::Sysconf.hostname
|
89
117
|
end
|
90
118
|
|
91
119
|
##
|
@@ -114,7 +142,7 @@ module LinuxStat
|
|
114
142
|
def uptime
|
115
143
|
return {} unless uptime_readable?
|
116
144
|
|
117
|
-
uptime = IO.read('/proc/uptime').to_f
|
145
|
+
uptime = IO.read('/proc/uptime'.freeze).to_f
|
118
146
|
uptime_i = uptime.to_i
|
119
147
|
|
120
148
|
h = uptime_i / 3600
|
@@ -128,16 +156,21 @@ module LinuxStat
|
|
128
156
|
}.freeze
|
129
157
|
end
|
130
158
|
|
159
|
+
alias distrib_version version
|
160
|
+
|
131
161
|
private
|
132
162
|
def release(file)
|
133
163
|
IO.readlines(file, 4096).reduce({}) { |h, x|
|
134
164
|
x.strip!
|
135
165
|
next h if x.empty?
|
136
166
|
|
137
|
-
splitted = x.split(
|
167
|
+
splitted = x.split(?=.freeze)
|
168
|
+
|
169
|
+
key = splitted[0].to_s
|
170
|
+
key.strip!
|
138
171
|
|
139
|
-
|
140
|
-
value
|
172
|
+
value = splitted[1..-1].join(?=.freeze).to_s
|
173
|
+
value.strip!
|
141
174
|
|
142
175
|
value[0] = ''.freeze if value[0] == ?".freeze
|
143
176
|
value[-1] = ''.freeze if value[-1] == ?".freeze
|
data/lib/linux_stat/version.rb
CHANGED