linux_stat 0.6.5 → 0.7.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 +1 -1
- data/ext/fs_stat/fs_stat.c +0 -1
- data/ext/sysconf/sysconf.c +0 -1
- data/ext/utsname/utsname.c +0 -1
- data/lib/linux_stat/os.rb +2 -2
- data/lib/linux_stat/process_info.rb +92 -5
- data/lib/linux_stat/user.rb +1 -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: a54eca551d77c1284989f5f8edeea8e363d32228e0ea5a2d28b2df9eefeedf53
|
4
|
+
data.tar.gz: 407820d169fe900f639cd43730bd03eb66c43a2ec0bcd5c3d1399af741418c4a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ff513a54d80eb9e9c101dd2fb92ff874c3e644da5752e8f7b2c9bdf535d56a1d942e64ed3b083eb051dfcb62be02cb521b51f0b1e08baef7f3ec0a261bacd1f1
|
7
|
+
data.tar.gz: ef5b77eb019ab19976a5799a276f22a6967603c6d03b0219a6314e74e00a275a288102f0ab6d753e38867b96d6621e8673a9b0fa733d772c2d97118749ada933
|
data/README.md
CHANGED
@@ -10,7 +10,7 @@ It only works for Linux, and detecting the OS is upto the user of this gem.
|
|
10
10
|
---
|
11
11
|
|
12
12
|
## Dependencies:
|
13
|
-
+ You need to have the C
|
13
|
+
+ You need to have the C compiler installed to be able to compile the C extensions.
|
14
14
|
On Arch Linux:
|
15
15
|
```
|
16
16
|
# pacman -S gcc make
|
data/ext/fs_stat/fs_stat.c
CHANGED
data/ext/sysconf/sysconf.c
CHANGED
data/ext/utsname/utsname.c
CHANGED
data/lib/linux_stat/os.rb
CHANGED
@@ -135,8 +135,8 @@ module LinuxStat
|
|
135
135
|
key = splitted[0].to_s.strip
|
136
136
|
value = splitted[1..-1].join(?=).to_s.strip
|
137
137
|
|
138
|
-
value[0] = '' if value[0] == ?"
|
139
|
-
value[-1] = '' if value[-1] == ?"
|
138
|
+
value[0] = ''.freeze if value[0] == ?".freeze
|
139
|
+
value[-1] = ''.freeze if value[-1] == ?".freeze
|
140
140
|
|
141
141
|
h.merge!( key.to_sym => value )
|
142
142
|
}
|
@@ -345,7 +345,7 @@ module LinuxStat
|
|
345
345
|
file = "/proc/#{pid}/stat".freeze
|
346
346
|
return nil unless File.readable?(file)
|
347
347
|
|
348
|
-
data = IO.
|
348
|
+
data = IO.foreach(file, ' '.freeze).first(20)[-1]
|
349
349
|
data ? data.to_i : nil
|
350
350
|
end
|
351
351
|
|
@@ -383,7 +383,7 @@ module LinuxStat
|
|
383
383
|
file = "/proc/#{pid}/status".freeze
|
384
384
|
return nil unless File.readable?(file)
|
385
385
|
|
386
|
-
data = IO.
|
386
|
+
data = IO.foreach(file.freeze).find { |x|
|
387
387
|
x[/Uid.*\d*/]
|
388
388
|
}.to_s.split.drop(1)
|
389
389
|
|
@@ -402,12 +402,12 @@ module LinuxStat
|
|
402
402
|
#
|
403
403
|
# :real, :effective, :saved_set, :filesystem_uid
|
404
404
|
#
|
405
|
-
# If the info isn't available it
|
405
|
+
# If the info isn't available or the argument passed doesn't exist as a process ID, it will return an empty Hash.
|
406
406
|
def gid(pid = $$)
|
407
407
|
file = "/proc/#{pid}/status".freeze
|
408
408
|
return nil unless File.readable?(file)
|
409
409
|
|
410
|
-
data = IO.
|
410
|
+
data = IO.foreach(file.freeze).find { |x|
|
411
411
|
x[/Gid.*\d*/]
|
412
412
|
}.split.drop(1)
|
413
413
|
|
@@ -428,13 +428,100 @@ module LinuxStat
|
|
428
428
|
file = "/proc/#{pid}/status".freeze
|
429
429
|
return ''.freeze unless File.readable?(file)
|
430
430
|
|
431
|
-
gid = IO.
|
431
|
+
gid = IO.foreach(file.freeze).find { |x|
|
432
432
|
x[/Gid.*\d*/]
|
433
433
|
}.split.drop(1)[2].to_i
|
434
434
|
|
435
435
|
LinuxStat::User.username_by_gid(gid)
|
436
436
|
end
|
437
437
|
|
438
|
+
##
|
439
|
+
# = start_time(pid = $$)
|
440
|
+
#
|
441
|
+
# Returns the time (as Time object) the process was started.
|
442
|
+
#
|
443
|
+
# For example:
|
444
|
+
# LinuxStat::ProcessInfo.start_time 14183
|
445
|
+
#
|
446
|
+
# => 2020-12-16 13:31:43.559061275 +0000
|
447
|
+
#
|
448
|
+
# If the info isn't available or the argument passed doesn't exist as a process ID, it will return nil.
|
449
|
+
#
|
450
|
+
# The timezone returned based on current TZ.
|
451
|
+
# Thus the timezone could be affected by changing the ENV['TZ'] variable.
|
452
|
+
#
|
453
|
+
# Don't trust the timezone returned by the time.
|
454
|
+
def start_time(pid = $$)
|
455
|
+
stat_file = "/proc/#{pid}/stat".freeze
|
456
|
+
uptime = "/proc/uptime".freeze
|
457
|
+
|
458
|
+
@@u_readable ||= File.readable?(uptime)
|
459
|
+
return nil unless @@u_readable && File.readable?(stat_file)
|
460
|
+
|
461
|
+
Time.now.-(IO.foreach(uptime, ' '.freeze).next.to_i - (IO.read(stat_file).split[21].to_i / get_ticks))
|
462
|
+
end
|
463
|
+
|
464
|
+
##
|
465
|
+
# = running_time(pid = $$)
|
466
|
+
#
|
467
|
+
# Returns the time (in seconds, as Float) the process is running for.
|
468
|
+
#
|
469
|
+
# For example:
|
470
|
+
# LinuxStat::ProcessInfo.running_time 14183
|
471
|
+
#
|
472
|
+
# => 1947.619999999999
|
473
|
+
#
|
474
|
+
# If the info isn't available or the argument passed doesn't exist as a process ID, it will return nil.
|
475
|
+
def running_time(pid = $$)
|
476
|
+
stat_file = "/proc/#{pid}/stat".freeze
|
477
|
+
uptime = "/proc/uptime".freeze
|
478
|
+
|
479
|
+
@@u_readable ||= File.readable?(uptime)
|
480
|
+
return nil unless @@u_readable && File.readable?(stat_file)
|
481
|
+
|
482
|
+
IO.foreach(uptime, ' '.freeze).next.to_f - (IO.read(stat_file).split[21].to_i / get_ticks)
|
483
|
+
end
|
484
|
+
|
485
|
+
##
|
486
|
+
# = state(pid = $$)
|
487
|
+
# Returns the state of the process as a frozen String
|
488
|
+
#
|
489
|
+
# * A process could have multiple states:
|
490
|
+
#
|
491
|
+
# 1. S => Sleeping
|
492
|
+
#
|
493
|
+
# 2. R => Running
|
494
|
+
#
|
495
|
+
# 3. I => Idle
|
496
|
+
#
|
497
|
+
# 4. Z => Zombie
|
498
|
+
#
|
499
|
+
# It returns any one of them.
|
500
|
+
#
|
501
|
+
# If the info isn't available or the argument passed doesn't exist as a process ID,
|
502
|
+
# it will return an empty String.
|
503
|
+
def state(pid = $$)
|
504
|
+
file = "/proc/#{pid}/stat".freeze
|
505
|
+
return ''.freeze unless File.readable?(file)
|
506
|
+
IO.foreach(file, ' '.freeze).first(3)[-1].tap(&:rstrip!).freeze
|
507
|
+
end
|
508
|
+
|
509
|
+
##
|
510
|
+
# = nice(pid = $$)
|
511
|
+
# Returns the nice of the process
|
512
|
+
#
|
513
|
+
# The output value is an Integer ranging from -20 to 19
|
514
|
+
#
|
515
|
+
# -20 means the process has high priority, and 19 means the process has low priority
|
516
|
+
#
|
517
|
+
# If the info isn't available or the argument passed doesn't exist as a process ID, it will return nil.
|
518
|
+
def nice(pid = $$)
|
519
|
+
file = "/proc/#{pid}/stat"
|
520
|
+
return nil unless File.readable?(file)
|
521
|
+
|
522
|
+
IO.foreach(file, ' ').first(19)[-1].to_i
|
523
|
+
end
|
524
|
+
|
438
525
|
private
|
439
526
|
def get_ticks
|
440
527
|
@@ticks ||= Sysconf.sc_clk_tck
|
data/lib/linux_stat/user.rb
CHANGED
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: 0.
|
4
|
+
version: 0.7.0
|
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-16 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: Linux only, efficient linux system utilization reporting and system monitoring
|
14
14
|
gem
|