linux_stat 2.2.3 → 2.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 +4 -4
- data/README.md +41 -8
- data/exe/linuxstat.rb +152 -102
- data/ext/fs_stat/disk_stat.h +25 -0
- data/ext/fs_stat/extconf.rb +2 -1
- data/ext/fs_stat/fs_stat.c +10 -1
- data/ext/fs_stat/sector_size.h +13 -0
- data/ext/misc/integer/extconf.rb +2 -0
- data/ext/misc/integer/integer?.c +63 -0
- data/ext/nproc/nproc.c +1 -1
- data/ext/procfs/loadavg_pid.h +1 -1
- data/ext/procfs/procfs.c +6 -0
- data/ext/procfs/stat.h +69 -3
- data/ext/procfs/statm.h +5 -5
- data/ext/procfs/uptime.h +1 -1
- data/ext/sysconf/sysconf.c +17 -17
- data/ext/sysinfo/sysinfo.c +11 -11
- data/ext/utsname/utsname.c +5 -5
- data/lib/linux_stat/battery.rb +1 -1
- data/lib/linux_stat/cpu.rb +121 -12
- data/lib/linux_stat/filesystem.rb +45 -0
- data/lib/linux_stat/mounts.rb +3 -3
- data/lib/linux_stat/net.rb +2 -2
- data/lib/linux_stat/os.rb +2 -1
- data/lib/linux_stat/pci.rb +9 -9
- data/lib/linux_stat/process.rb +14 -24
- data/lib/linux_stat/process_info.rb +1 -1
- data/lib/linux_stat/swap.rb +2 -1
- data/lib/linux_stat/thermal.rb +4 -4
- data/lib/linux_stat/usb.rb +10 -10
- data/lib/linux_stat/user.rb +10 -4
- data/lib/linux_stat/version.rb +1 -1
- data/lib/linux_stat.rb +1 -0
- metadata +8 -3
data/lib/linux_stat/process.rb
CHANGED
@@ -1,25 +1,15 @@
|
|
1
1
|
module LinuxStat
|
2
2
|
# Shows various information about a process that is either
|
3
3
|
# running, sleeping, idle or a zombie.
|
4
|
-
|
5
4
|
module Process
|
6
5
|
class << self
|
7
6
|
##
|
8
7
|
# Returns the list of processes from /proc/.
|
8
|
+
# The output doesn't guarantee a sorted list, in fact it's shuffled most of the time.
|
9
9
|
#
|
10
10
|
# The return type is an Array of Integers.
|
11
11
|
def list
|
12
|
-
|
13
|
-
ret, i = [], -1
|
14
|
-
count = d.length
|
15
|
-
|
16
|
-
while(i += 1) < count
|
17
|
-
pid = File.split(d[i])[1]
|
18
|
-
pid_i = pid.to_i
|
19
|
-
ret << pid_i if pid_i.to_s == pid
|
20
|
-
end
|
21
|
-
|
22
|
-
ret
|
12
|
+
LinuxStat::ProcFS.list_process
|
23
13
|
end
|
24
14
|
|
25
15
|
##
|
@@ -27,7 +17,7 @@ module LinuxStat
|
|
27
17
|
#
|
28
18
|
# The return type is Integer.
|
29
19
|
def count
|
30
|
-
|
20
|
+
LinuxStat::ProcFS.list_process.length
|
31
21
|
end
|
32
22
|
|
33
23
|
##
|
@@ -36,14 +26,14 @@ module LinuxStat
|
|
36
26
|
def names
|
37
27
|
h, i = {}, -1
|
38
28
|
|
39
|
-
l =
|
29
|
+
l = LinuxStat::ProcFS.list_process
|
40
30
|
count = l.length
|
41
31
|
|
42
32
|
while(i += 1) < count
|
43
33
|
x = l[i]
|
44
34
|
|
45
35
|
begin
|
46
|
-
h.
|
36
|
+
h.store(x, IO.read("/proc/#{x}/comm").strip)
|
47
37
|
rescue StandardError
|
48
38
|
end
|
49
39
|
end
|
@@ -57,7 +47,7 @@ module LinuxStat
|
|
57
47
|
def cmdlines
|
58
48
|
h, i = {}, -1
|
59
49
|
|
60
|
-
l =
|
50
|
+
l = LinuxStat::ProcFS.list_process
|
61
51
|
count = l.length
|
62
52
|
|
63
53
|
while(i += 1) < count
|
@@ -66,7 +56,7 @@ module LinuxStat
|
|
66
56
|
begin
|
67
57
|
cmdlines = IO.read("/proc/#{x}/cmdline").strip
|
68
58
|
cmdlines.gsub!(?\u0000.freeze, ?\s.freeze)
|
69
|
-
h.
|
59
|
+
h.store(x, cmdlines)
|
70
60
|
rescue StandardError
|
71
61
|
end
|
72
62
|
end
|
@@ -78,14 +68,14 @@ module LinuxStat
|
|
78
68
|
def types
|
79
69
|
h, i = {}, -1
|
80
70
|
|
81
|
-
l =
|
71
|
+
l = LinuxStat::ProcFS.list_process
|
82
72
|
count = l.length
|
83
73
|
|
84
74
|
while(i += 1) < count
|
85
75
|
x = l[i]
|
86
76
|
|
87
77
|
begin
|
88
|
-
h.
|
78
|
+
h.store(x,
|
89
79
|
case LinuxStat::ProcFS.ps_state(x)
|
90
80
|
when ?S.freeze then :sleeping
|
91
81
|
when ?I.freeze then :idle
|
@@ -109,7 +99,7 @@ module LinuxStat
|
|
109
99
|
# Returns all the id of processes that are sleeping.
|
110
100
|
# The return type is an Array of Integers.
|
111
101
|
def sleeping
|
112
|
-
|
102
|
+
LinuxStat::ProcFS.list_process.select { |x|
|
113
103
|
LinuxStat::ProcFS.ps_state(x) == ?S.freeze
|
114
104
|
}
|
115
105
|
end
|
@@ -118,7 +108,7 @@ module LinuxStat
|
|
118
108
|
# Returns all the id of processes that are idle.
|
119
109
|
# The return type is an Array of Integers.
|
120
110
|
def idle
|
121
|
-
|
111
|
+
LinuxStat::ProcFS.list_process.select { |x|
|
122
112
|
LinuxStat::ProcFS.ps_state(x) == ?I.freeze
|
123
113
|
}
|
124
114
|
end
|
@@ -127,7 +117,7 @@ module LinuxStat
|
|
127
117
|
# Returns all the id of processes that are zombies.
|
128
118
|
# The return type is an Array of Integers.
|
129
119
|
def zombie
|
130
|
-
|
120
|
+
LinuxStat::ProcFS.list_process.select { |x|
|
131
121
|
LinuxStat::ProcFS.ps_state(x) == ?Z.freeze
|
132
122
|
}
|
133
123
|
end
|
@@ -136,7 +126,7 @@ module LinuxStat
|
|
136
126
|
# Returns all the id of processes that are running.
|
137
127
|
# The return type is an Array of Integers.
|
138
128
|
def running
|
139
|
-
|
129
|
+
LinuxStat::ProcFS.list_process.select { |x|
|
140
130
|
LinuxStat::ProcFS.ps_state(x) == ?R.freeze
|
141
131
|
}
|
142
132
|
end
|
@@ -145,7 +135,7 @@ module LinuxStat
|
|
145
135
|
# Returns all the id of processes that are stopped.
|
146
136
|
# The return type is an Array of Integers.
|
147
137
|
def stopped
|
148
|
-
|
138
|
+
LinuxStat::ProcFS.list_process.select { |x|
|
149
139
|
v = LinuxStat::ProcFS.ps_state(x)
|
150
140
|
v == ?T.freeze || v == ?t.freeze
|
151
141
|
}
|
data/lib/linux_stat/swap.rb
CHANGED
@@ -13,7 +13,8 @@ module LinuxStat
|
|
13
13
|
file = IO.readlines('/proc/swaps'.freeze).drop(1)
|
14
14
|
file.reduce({}) do |h, x|
|
15
15
|
name, *stats = x.strip.split
|
16
|
-
h.
|
16
|
+
h.store(name, stats.map! { |v| LinuxStat::Misc.integer?(v) ? v.to_i : v.to_sym })
|
17
|
+
h
|
17
18
|
end
|
18
19
|
end
|
19
20
|
|
data/lib/linux_stat/thermal.rb
CHANGED
@@ -107,10 +107,10 @@ module LinuxStat
|
|
107
107
|
|
108
108
|
h = {path: path, name: name}
|
109
109
|
|
110
|
-
h.
|
111
|
-
h.
|
112
|
-
h.
|
113
|
-
h.
|
110
|
+
h.store(:label, label) if label
|
111
|
+
h.store(key, value)
|
112
|
+
h.store(:temp_crit, temp_crit) if temp_crit
|
113
|
+
h.store(:temp_crit, temp_max) if temp_max
|
114
114
|
|
115
115
|
ret.push(h)
|
116
116
|
end
|
data/lib/linux_stat/usb.rb
CHANGED
@@ -102,20 +102,20 @@ module LinuxStat
|
|
102
102
|
vendor_id: id_vendor, product_id: id_product
|
103
103
|
}
|
104
104
|
|
105
|
-
ret.
|
106
|
-
ret.
|
105
|
+
ret.store(:bus_num, bus_num.to_i) unless bus_num.empty?
|
106
|
+
ret.store(:dev_num, dev_num.to_i) unless dev_num.empty?
|
107
107
|
|
108
|
-
ret.
|
108
|
+
ret.store(:serial, serial) unless serial.empty?
|
109
109
|
|
110
|
-
ret.
|
111
|
-
ret.
|
112
|
-
ret.
|
110
|
+
ret.store(:hwdata, query) unless query.empty?
|
111
|
+
ret.store(:product, product) unless product.empty?
|
112
|
+
ret.store(:manufacturer, manufacturer) unless manufacturer.empty?
|
113
113
|
|
114
|
-
ret.
|
115
|
-
ret.
|
114
|
+
ret.store(:removable, is_removable) unless is_removable.nil?
|
115
|
+
ret.store(:authorized, authorized == 1)
|
116
116
|
|
117
|
-
ret.
|
118
|
-
ret.
|
117
|
+
ret.store(:b_max_power, b_max_power) unless b_max_power.empty?
|
118
|
+
ret.store(:b_max_packet_size0, b_max_packet_size0) if b_max_packet_size0
|
119
119
|
|
120
120
|
ret
|
121
121
|
rescue StandardError
|
data/lib/linux_stat/user.rb
CHANGED
@@ -25,9 +25,11 @@ module LinuxStat
|
|
25
25
|
def ids
|
26
26
|
return {} unless passwd_readable?
|
27
27
|
passwd_splitted.reduce({}) { |h, x|
|
28
|
-
h.
|
28
|
+
h.store(x[0].to_sym, {
|
29
29
|
uid: x[2].to_i, gid: x[3].to_i
|
30
30
|
})
|
31
|
+
|
32
|
+
h
|
31
33
|
}
|
32
34
|
end
|
33
35
|
|
@@ -42,8 +44,10 @@ module LinuxStat
|
|
42
44
|
def uids
|
43
45
|
return {} unless passwd_readable?
|
44
46
|
passwd_splitted.reduce({}) { |h, x|
|
45
|
-
h.
|
47
|
+
h.store(x[0].to_sym, x[2].to_i)
|
48
|
+
h
|
46
49
|
}
|
50
|
+
|
47
51
|
end
|
48
52
|
|
49
53
|
##
|
@@ -59,7 +63,8 @@ module LinuxStat
|
|
59
63
|
return {} unless passwd_readable?
|
60
64
|
|
61
65
|
passwd_splitted.reduce({}) { |h, x|
|
62
|
-
h.
|
66
|
+
h.store(x[0].to_sym, x[3].to_i)
|
67
|
+
h
|
63
68
|
}
|
64
69
|
end
|
65
70
|
|
@@ -76,7 +81,8 @@ module LinuxStat
|
|
76
81
|
return {} unless passwd_readable?
|
77
82
|
passwd.reduce({}) { |h, x|
|
78
83
|
splitted = x.split(?:)
|
79
|
-
h.
|
84
|
+
h.store(splitted[0].to_sym, splitted[5])
|
85
|
+
h
|
80
86
|
}
|
81
87
|
end
|
82
88
|
|
data/lib/linux_stat/version.rb
CHANGED
data/lib/linux_stat.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: 2.
|
4
|
+
version: 2.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-
|
11
|
+
date: 2021-10-23 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: Linux only, efficient linux system utilization reporting and system monitoring
|
14
14
|
gem
|
@@ -18,6 +18,7 @@ executables:
|
|
18
18
|
- linuxstat.rb
|
19
19
|
extensions:
|
20
20
|
- ext/fs_stat/extconf.rb
|
21
|
+
- ext/misc/integer/extconf.rb
|
21
22
|
- ext/nproc/extconf.rb
|
22
23
|
- ext/procfs/extconf.rb
|
23
24
|
- ext/sysconf/extconf.rb
|
@@ -31,8 +32,12 @@ files:
|
|
31
32
|
- bin/console
|
32
33
|
- bin/setup
|
33
34
|
- exe/linuxstat.rb
|
35
|
+
- ext/fs_stat/disk_stat.h
|
34
36
|
- ext/fs_stat/extconf.rb
|
35
37
|
- ext/fs_stat/fs_stat.c
|
38
|
+
- ext/fs_stat/sector_size.h
|
39
|
+
- ext/misc/integer/extconf.rb
|
40
|
+
- ext/misc/integer/integer?.c
|
36
41
|
- ext/nproc/extconf.rb
|
37
42
|
- ext/nproc/nproc.c
|
38
43
|
- ext/procfs/extconf.rb
|
@@ -85,7 +90,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
85
90
|
- !ruby/object:Gem::Version
|
86
91
|
version: '0'
|
87
92
|
requirements: []
|
88
|
-
rubygems_version: 3.2.
|
93
|
+
rubygems_version: 3.2.29
|
89
94
|
signing_key:
|
90
95
|
specification_version: 4
|
91
96
|
summary: Efficient linux system reporting gem
|