linux_stat 0.3.3 → 0.6.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/LICENSE.txt +21 -0
- data/README.md +522 -45
- data/bin/console +1 -1
- data/bin/setup +0 -2
- data/{bin → exe}/linuxstat.rb +43 -7
- data/ext/fs_stat/fs_stat.c +4 -1
- data/ext/sysconf/extconf.rb +7 -0
- data/ext/sysconf/sysconf.c +81 -0
- data/ext/utsname/utsname.c +27 -5
- data/lib/linux_stat.rb +15 -5
- data/lib/linux_stat/battery.rb +2 -2
- data/lib/linux_stat/bios.rb +10 -6
- data/lib/linux_stat/cpu.rb +24 -7
- data/lib/linux_stat/filesystem.rb +5 -7
- data/lib/linux_stat/kernel.rb +16 -8
- data/lib/linux_stat/memory.rb +8 -2
- data/lib/linux_stat/mounts.rb +152 -1
- data/lib/linux_stat/os.rb +11 -9
- data/lib/linux_stat/prettify_bytes.rb +75 -0
- data/lib/linux_stat/process_info.rb +381 -0
- data/lib/linux_stat/swap.rb +6 -1
- data/lib/linux_stat/user.rb +298 -0
- data/lib/linux_stat/version.rb +1 -1
- metadata +16 -10
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e6d3a089c2e214eb53f564d64014d6da9b900467e8b8285be6be6516c92fb366
|
4
|
+
data.tar.gz: 6cc0a5b86b5b9163d2ae1d57b761d8cf6900ff2864987c3b2b39a5072e5d8174
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e9d1ce304cec1210fd3cb4f75b36a105b35bc54828106d1d880331b5d8ec6429f120be21200014599a22693950386aa838e03cc20a0fc41c0b819204c6c2da81
|
7
|
+
data.tar.gz: 45ea80ecccb20956945b420bfec45ca0e3f3770233418469fd741f554977c9ab07cb14002f9a887094db0b078f5ae9cc5c1b6a25865e8024a5ade4c278dd7ed8
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2020 Sourav Goswami
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
CHANGED
@@ -1,22 +1,24 @@
|
|
1
1
|
# LinuxStat
|
2
2
|

|
3
3
|
|
4
|
-
For reading the HTML version, visit [linux_stat](https://souravgoswami.github.io/linux_stat/).
|
4
|
+
For reading the eyecandy HTML version, visit [linux_stat](https://souravgoswami.github.io/linux_stat/).
|
5
5
|
|
6
6
|
LinuxStat lets you read status of a Linux system. It can show you cpu stats and usages, memory stats and usages, swap stats and usages, battery usage, bios info, kernel details, local ip, os details and parse os-release + lsb-release, etc.
|
7
7
|
|
8
8
|
It only works for Linux, and detecting the OS is upto the user of this gem.
|
9
9
|
|
10
|
+
---
|
11
|
+
|
10
12
|
## Dependencies:
|
11
13
|
+ You need to have the C compile to be able to compile the C extension.
|
12
14
|
On Arch Linux:
|
13
15
|
```
|
14
|
-
# pacman -S gcc
|
16
|
+
# pacman -S gcc make
|
15
17
|
```
|
16
18
|
|
17
19
|
On Debian based systems:
|
18
20
|
```
|
19
|
-
# apt install gcc
|
21
|
+
# apt install gcc build-essential
|
20
22
|
```
|
21
23
|
|
22
24
|
+ You might also require ruby-dev in Debian based systems which provides support for ruby.h header file:
|
@@ -26,6 +28,8 @@ On Debian based systems:
|
|
26
28
|
|
27
29
|
+ Once your are done, and you can compile the C file, you can follow the installation!
|
28
30
|
|
31
|
+
---
|
32
|
+
|
29
33
|
## Installation
|
30
34
|
|
31
35
|
Add this line to your application's Gemfile:
|
@@ -99,7 +103,7 @@ LinuxStat::CPU.count
|
|
99
103
|
=> 4
|
100
104
|
|
101
105
|
LinuxStat::CPU.cur_freq
|
102
|
-
=> [
|
106
|
+
=> [1863999, 1934584, 1996927, 1978102]
|
103
107
|
|
104
108
|
LinuxStat::CPU.max_freq
|
105
109
|
=> [2000000, 2000000, 2000000, 2000000]
|
@@ -108,92 +112,116 @@ LinuxStat::CPU.model
|
|
108
112
|
=> "Intel(R) Core(TM) i3-6006U CPU @ 2.00GHz"
|
109
113
|
|
110
114
|
LinuxStat::CPU.stat
|
111
|
-
=> {0=>
|
115
|
+
=> {0=>20.0, 1=>50.0, 2=>0.0, 3=>0.0, 4=>0.0}
|
112
116
|
|
113
117
|
LinuxStat::CPU.total_usage
|
114
|
-
=>
|
118
|
+
=> 0.0
|
115
119
|
|
116
120
|
LinuxStat::CPU.usage
|
117
|
-
=>
|
121
|
+
=> 25.0
|
118
122
|
|
119
123
|
LinuxStat::CPU.usages
|
120
|
-
=> {0=>
|
124
|
+
=> {0=>0.0, 1=>0.0, 2=>0.0, 3=>0.0, 4=>0.0}
|
121
125
|
|
122
126
|
```
|
123
127
|
|
124
128
|
### LinuxStat::Filesystem
|
125
129
|
```
|
126
130
|
LinuxStat::Filesystem.available
|
127
|
-
=>
|
131
|
+
=> 34612666368
|
128
132
|
|
129
133
|
LinuxStat::Filesystem.free
|
130
|
-
=>
|
134
|
+
=> 34612666368
|
131
135
|
|
132
136
|
LinuxStat::Filesystem.stat
|
133
|
-
=> {:total=>119981191168, :free=>
|
137
|
+
=> {:total=>119981191168, :free=>34612666368, :used=>85368524800}
|
134
138
|
|
135
139
|
LinuxStat::Filesystem.stat_raw
|
136
|
-
=> {:block_size=>4096, :fragment_size=>4096, :blocks=>29292283, :block_free=>
|
140
|
+
=> {:block_size=>4096, :fragment_size=>4096, :blocks=>29292283, :block_free=>8450358, :block_avail_unpriv=>8450358, :inodes=>58612160, :free_inodes=>56582049, :filesystem_id=>2050, :mount_flags=>1024, :max_filename_length=>255}
|
137
141
|
|
138
142
|
LinuxStat::Filesystem.total
|
139
143
|
=> 119981191168
|
140
144
|
|
141
145
|
LinuxStat::Filesystem.used
|
142
|
-
=>
|
146
|
+
=> 85368524800
|
143
147
|
|
144
148
|
```
|
145
149
|
|
146
150
|
### LinuxStat::Kernel
|
147
151
|
```
|
148
152
|
LinuxStat::Kernel.build_date
|
149
|
-
=> 2020-
|
153
|
+
=> 2020-11-20 07:44:55 +0000
|
150
154
|
|
151
155
|
LinuxStat::Kernel.build_date_string
|
152
|
-
=> "
|
156
|
+
=> "20 Nov 2020 07:44:55 +0000"
|
153
157
|
|
154
158
|
LinuxStat::Kernel.build_user
|
155
159
|
=> "souravgoswami@archlinux"
|
156
160
|
|
161
|
+
LinuxStat::Kernel.clk_tck
|
162
|
+
=> 100
|
163
|
+
|
157
164
|
LinuxStat::Kernel.compiler
|
158
165
|
=> [:gcc, "10.2.0"]
|
159
166
|
|
160
167
|
LinuxStat::Kernel.compiler_version
|
161
168
|
=> "10.2.0"
|
162
169
|
|
170
|
+
LinuxStat::Kernel.release
|
171
|
+
=> "5.9.9-xanmod1-1"
|
172
|
+
|
163
173
|
LinuxStat::Kernel.string
|
164
|
-
=> "Linux version 5.9.
|
174
|
+
=> "Linux version 5.9.9-xanmod1-1 (souravgoswami@archlinux) (gcc (GCC) 10.2.0, GNU ld (GNU Binutils) 2.35.1) #1 SMP PREEMPT Fri, 20 Nov 2020 07:44:55 +0000"
|
175
|
+
|
176
|
+
LinuxStat::Kernel.ticks
|
177
|
+
=> 100
|
165
178
|
|
166
179
|
LinuxStat::Kernel.version
|
167
|
-
=> "5.9.
|
180
|
+
=> "5.9.9-xanmod1-1"
|
168
181
|
|
169
182
|
```
|
170
183
|
|
171
184
|
### LinuxStat::Memory
|
172
185
|
```
|
173
186
|
LinuxStat::Memory.available
|
174
|
-
=>
|
187
|
+
=> 185060
|
175
188
|
|
176
189
|
LinuxStat::Memory.percent_available
|
177
|
-
=>
|
190
|
+
=> 4.82
|
178
191
|
|
179
192
|
LinuxStat::Memory.percent_used
|
180
|
-
=>
|
193
|
+
=> 95.18
|
181
194
|
|
182
195
|
LinuxStat::Memory.stat
|
183
|
-
=> {:total=>
|
196
|
+
=> {:total=>3836228, :used=>3651168, :available=>185060, :percent_used=>95.18, :percent_available=>4.82}
|
184
197
|
|
185
198
|
LinuxStat::Memory.total
|
186
|
-
=>
|
199
|
+
=> 3836228
|
187
200
|
|
188
201
|
LinuxStat::Memory.used
|
189
|
-
=>
|
202
|
+
=> 3651168
|
190
203
|
|
191
204
|
```
|
192
205
|
|
193
206
|
### LinuxStat::Mounts
|
194
207
|
```
|
208
|
+
LinuxStat::Mounts.device_stat
|
209
|
+
=> {:mountpoint=>"/", :total=>119981191168, :free=>34098106368, :available=>34098106368, :used=>85883084800, :percent_used=>71.58, :percent_free=>28.42, :percent_available=>28.42}
|
210
|
+
|
211
|
+
LinuxStat::Mounts.devices_stat
|
212
|
+
=> {"proc"=>{:mountpoint=>"/proc", :total=>0, :free=>0, :available=>0, :used=>0, :percent_used=>NaN, :percent_free=>NaN, :percent_available=>NaN}, "sys"=>{:mountpoint=>"/sys", :total=>0, :free=>0, :available=>0, :used=>0, :percent_used=>NaN, :percent_fre...
|
213
|
+
|
195
214
|
LinuxStat::Mounts.list
|
196
|
-
=> ["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=
|
215
|
+
=> ["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=1892904k,nr_inodes=473226,mode=755 0 0", "run /run tmpfs rw,nosuid,nodev,relatime,mode=755 0 0", "...
|
216
|
+
|
217
|
+
LinuxStat::Mounts.list_devices
|
218
|
+
=> ["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...
|
219
|
+
|
220
|
+
LinuxStat::Mounts.list_devices_mount_point
|
221
|
+
=> {"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/perf_event", "pstore...
|
222
|
+
|
223
|
+
LinuxStat::Mounts.mount_point
|
224
|
+
=> "/"
|
197
225
|
|
198
226
|
LinuxStat::Mounts.root
|
199
227
|
=> "/dev/sda2"
|
@@ -205,14 +233,14 @@ LinuxStat::Mounts.root_mount_options
|
|
205
233
|
=> "rw,noatime,attr2,inode64,logbufs=8,logbsize=32k,noquota"
|
206
234
|
|
207
235
|
LinuxStat::Mounts.tmpfs
|
208
|
-
=> {"/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", "/
|
236
|
+
=> {"/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...
|
209
237
|
|
210
238
|
```
|
211
239
|
|
212
240
|
### LinuxStat::Net
|
213
241
|
```
|
214
242
|
LinuxStat::Net.ipv4_private
|
215
|
-
=> "192.168.0.
|
243
|
+
=> "192.168.0.102"
|
216
244
|
|
217
245
|
```
|
218
246
|
|
@@ -230,33 +258,39 @@ LinuxStat::OS.hostname
|
|
230
258
|
LinuxStat::OS.lsb_release
|
231
259
|
=> {:LSB_VERSION=>"1.4", :DISTRIB_ID=>"Arch", :DISTRIB_RELEASE=>"rolling", :DISTRIB_DESCRIPTION=>"Arch Linux"}
|
232
260
|
|
261
|
+
LinuxStat::OS.machine
|
262
|
+
=> "x86_64"
|
263
|
+
|
264
|
+
LinuxStat::OS.nodename
|
265
|
+
=> "archlinux"
|
266
|
+
|
233
267
|
LinuxStat::OS.os_release
|
234
268
|
=> {: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/"...
|
235
269
|
|
236
270
|
LinuxStat::OS.uptime
|
237
|
-
=> {:hour=>
|
271
|
+
=> {:hour=>9, :minute=>21, :second=>17.73}
|
238
272
|
|
239
273
|
```
|
240
274
|
|
241
275
|
### LinuxStat::Process
|
242
276
|
```
|
243
277
|
LinuxStat::Process.count
|
244
|
-
=>
|
278
|
+
=> 214
|
245
279
|
|
246
280
|
LinuxStat::Process.idle
|
247
|
-
=> [3, 4, 6, 9, 12, 23, 30, 37, 39, 49, 102, 103, 104, 106, 107, 108, 109, 110, 117, 118, 119,
|
281
|
+
=> [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, 152, 153, 178, 180, 183, 184, 188, 192, 193, 194, 195, 196, 197, 199, 241, 287, 337, 341, 349, 3799, 3800, 3801, 3802, 3803, 3804, 17865, 2...
|
248
282
|
|
249
283
|
LinuxStat::Process.list
|
250
|
-
=> [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, 119,
|
284
|
+
=> [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, 119, 121, 131, 134,...
|
251
285
|
|
252
286
|
LinuxStat::Process.names
|
253
|
-
=> {1=>"systemd", 2=>"kthreadd", 3=>"rcu_gp", 4=>"rcu_par_gp", 6=>"kworker/0:0H-
|
287
|
+
=> {1=>"systemd", 2=>"kthreadd", 3=>"rcu_gp", 4=>"rcu_par_gp", 6=>"kworker/0:0H-kblockd", 9=>"mm_percpu_wq", 10=>"ksoftirqd/0", 11=>"rcuc/0", 12=>"rcu_preempt", 13=>"rcub/0", 14=>"migration/0", 15=>"idle_inject/0", 16=>"cpuhp/0", 17=>"cpuhp/1", 18=>"idle...
|
254
288
|
|
255
289
|
LinuxStat::Process.running
|
256
|
-
=> [
|
290
|
+
=> [24893]
|
257
291
|
|
258
292
|
LinuxStat::Process.sleeping
|
259
|
-
=> [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,
|
293
|
+
=> [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, 177, 179, 198, 228, 246, 310, 316, 323, 324, 325, 336, 338, 370, 371, 372, 373, 380, 384, 388, 399, 410,...
|
260
294
|
|
261
295
|
LinuxStat::Process.types
|
262
296
|
=> {1=>:sleeping, 2=>:sleeping, 3=>:idle, 4=>:idle, 6=>:idle, 9=>:idle, 10=>:sleeping, 11=>:sleeping, 12=>:idle, 13=>:sleeping, 14=>:sleeping, 15=>:sleeping, 16=>:sleeping, 17=>:sleeping, 18=>:sleeping, 19=>:sleeping, 20=>:sleeping, 21=>:sleeping, 23=>:i...
|
@@ -266,34 +300,459 @@ LinuxStat::Process.zombie
|
|
266
300
|
|
267
301
|
```
|
268
302
|
|
303
|
+
### LinuxStat::ProcessInfo
|
304
|
+
```
|
305
|
+
LinuxStat::ProcessInfo.cmdline
|
306
|
+
=> "ruby exe/linuxstat.rb -md"
|
307
|
+
|
308
|
+
LinuxStat::ProcessInfo.command_name
|
309
|
+
=> "ruby"
|
310
|
+
|
311
|
+
LinuxStat::ProcessInfo.cpu_stat
|
312
|
+
=> {:cpu_usage=>0.0, :threads=>1, :last_executed_cpu=>2}
|
313
|
+
|
314
|
+
LinuxStat::ProcessInfo.cpu_usage
|
315
|
+
=> 0.0
|
316
|
+
|
317
|
+
LinuxStat::ProcessInfo.gid
|
318
|
+
=> {:real=>1000, :effective=>1000, :saved_set=>1000, :filesystem_uid=>1000}
|
319
|
+
|
320
|
+
LinuxStat::ProcessInfo.last_executed_cpu
|
321
|
+
=> 2
|
322
|
+
|
323
|
+
LinuxStat::ProcessInfo.mem_stat
|
324
|
+
=> {:memory=>9752, :virtual_memory=>79824, :resident_memory=>15564}
|
325
|
+
|
326
|
+
LinuxStat::ProcessInfo.memory
|
327
|
+
=> 9752
|
328
|
+
|
329
|
+
LinuxStat::ProcessInfo.owner
|
330
|
+
=> "sourav"
|
331
|
+
|
332
|
+
LinuxStat::ProcessInfo.resident_memory
|
333
|
+
=> 15564
|
334
|
+
|
335
|
+
LinuxStat::ProcessInfo.threads
|
336
|
+
=> 1
|
337
|
+
|
338
|
+
LinuxStat::ProcessInfo.total_io
|
339
|
+
=> {:read_bytes=>0, :write_bytes=>0}
|
340
|
+
|
341
|
+
LinuxStat::ProcessInfo.uid
|
342
|
+
=> {:real=>1000, :effective=>1000, :saved_set=>1000, :filesystem_uid=>1000}
|
343
|
+
|
344
|
+
LinuxStat::ProcessInfo.virtual_memory
|
345
|
+
=> 79824
|
346
|
+
|
347
|
+
```
|
348
|
+
|
269
349
|
### LinuxStat::Swap
|
270
350
|
```
|
271
351
|
LinuxStat::Swap.any?
|
272
352
|
=> true
|
273
353
|
|
274
354
|
LinuxStat::Swap.available
|
275
|
-
=>
|
355
|
+
=> 1929788
|
276
356
|
|
277
357
|
LinuxStat::Swap.list
|
278
|
-
=> {"/dev/zram0"=>[:partition, 4194300,
|
358
|
+
=> {"/dev/zram0"=>[:partition, 4194300, 2264512, -2]}
|
279
359
|
|
280
360
|
LinuxStat::Swap.percent_available
|
281
|
-
=>
|
361
|
+
=> 46.01
|
282
362
|
|
283
363
|
LinuxStat::Swap.percent_used
|
284
|
-
=>
|
364
|
+
=> 53.99
|
285
365
|
|
286
366
|
LinuxStat::Swap.stat
|
287
|
-
=> {:total=>4194300, :used=>
|
367
|
+
=> {:total=>4194300, :used=>2264512, :available=>1929788, :percent_used=>53.99, :percent_available=>46.01}
|
288
368
|
|
289
369
|
LinuxStat::Swap.total
|
290
370
|
=> 4194300
|
291
371
|
|
292
372
|
LinuxStat::Swap.used
|
293
|
-
=>
|
373
|
+
=> 2264512
|
374
|
+
|
375
|
+
```
|
376
|
+
|
377
|
+
### LinuxStat::Sysconf
|
378
|
+
```
|
379
|
+
LinuxStat::Sysconf.child_max
|
380
|
+
=> 2000000
|
381
|
+
|
382
|
+
LinuxStat::Sysconf.get_euid
|
383
|
+
=> 1000
|
384
|
+
|
385
|
+
LinuxStat::Sysconf.get_gid
|
386
|
+
=> 1000
|
387
|
+
|
388
|
+
LinuxStat::Sysconf.get_login
|
389
|
+
=> "sourav"
|
390
|
+
|
391
|
+
LinuxStat::Sysconf.get_uid
|
392
|
+
=> 1000
|
393
|
+
|
394
|
+
LinuxStat::Sysconf.get_user
|
395
|
+
=> "sourav"
|
396
|
+
|
397
|
+
LinuxStat::Sysconf.hostname_max
|
398
|
+
=> 64
|
399
|
+
|
400
|
+
LinuxStat::Sysconf.login_name_max
|
401
|
+
=> 256
|
402
|
+
|
403
|
+
LinuxStat::Sysconf.open_max
|
404
|
+
=> 1024
|
405
|
+
|
406
|
+
LinuxStat::Sysconf.page_size_max
|
407
|
+
=> 4096
|
408
|
+
|
409
|
+
LinuxStat::Sysconf.posix_version
|
410
|
+
=> 200809
|
411
|
+
|
412
|
+
LinuxStat::Sysconf.sc_clk_tck
|
413
|
+
=> 100
|
414
|
+
|
415
|
+
LinuxStat::Sysconf.stream_max
|
416
|
+
=> 16
|
417
|
+
|
418
|
+
LinuxStat::Sysconf.tty_name_max
|
419
|
+
=> 32
|
420
|
+
|
421
|
+
```
|
422
|
+
|
423
|
+
### LinuxStat::Uname
|
424
|
+
```
|
425
|
+
LinuxStat::Uname.machine
|
426
|
+
=> "x86_64"
|
427
|
+
|
428
|
+
LinuxStat::Uname.nodename
|
429
|
+
=> "archlinux"
|
430
|
+
|
431
|
+
LinuxStat::Uname.release
|
432
|
+
=> "5.9.9-xanmod1-1"
|
433
|
+
|
434
|
+
LinuxStat::Uname.sysname
|
435
|
+
=> "Linux"
|
436
|
+
|
437
|
+
LinuxStat::Uname.version
|
438
|
+
=> "#1 SMP PREEMPT Fri, 20 Nov 2020 07:44:55 +0000"
|
439
|
+
|
440
|
+
```
|
441
|
+
|
442
|
+
### LinuxStat::User
|
443
|
+
```
|
444
|
+
LinuxStat::User.get_current_user
|
445
|
+
=> "sourav"
|
446
|
+
|
447
|
+
LinuxStat::User.get_euid
|
448
|
+
=> 1000
|
449
|
+
|
450
|
+
LinuxStat::User.get_gid
|
451
|
+
=> 1000
|
452
|
+
|
453
|
+
LinuxStat::User.get_login
|
454
|
+
=> "sourav"
|
455
|
+
|
456
|
+
LinuxStat::User.get_uid
|
457
|
+
=> 1000
|
458
|
+
|
459
|
+
LinuxStat::User.get_user
|
460
|
+
=> "sourav"
|
461
|
+
|
462
|
+
LinuxStat::User.gid_by_username
|
463
|
+
=> 1000
|
464
|
+
|
465
|
+
LinuxStat::User.gids
|
466
|
+
=> {:root=>0, :bin=>1, :daemon=>2, :mail=>12, :ftp=>11, :http=>33, :nobody=>65534, :dbus=>81, :"systemd-journal-remote"=>982, :"systemd-network"=>981, :"systemd-resolve"=>980, :"systemd-timesync"=>979, :"systemd-coredump"=>978, :uuidd=>68, :avahi=>977, :...
|
467
|
+
|
468
|
+
LinuxStat::User.home_by_gid
|
469
|
+
=> "/home/sourav"
|
470
|
+
|
471
|
+
LinuxStat::User.home_by_username
|
472
|
+
=> "/home/sourav"
|
473
|
+
|
474
|
+
LinuxStat::User.home_directories
|
475
|
+
=> {:root=>"/root", :bin=>"/", :daemon=>"/", :mail=>"/var/spool/mail", :ftp=>"/srv/ftp", :http=>"/srv/http", :nobody=>"/", :dbus=>"/", :"systemd-journal-remote"=>"/", :"systemd-network"=>"/", :"systemd-resolve"=>"/", :"systemd-timesync"=>"/", :"systemd-c...
|
476
|
+
|
477
|
+
LinuxStat::User.homes_by_uid
|
478
|
+
=> ["/home/sourav"]
|
479
|
+
|
480
|
+
LinuxStat::User.ids
|
481
|
+
=> {:root=>{:uid=>0, :gid=>0}, :bin=>{:uid=>1, :gid=>1}, :daemon=>{:uid=>2, :gid=>2}, :mail=>{:uid=>8, :gid=>12}, :ftp=>{:uid=>14, :gid=>11}, :http=>{:uid=>33, :gid=>33}, :nobody=>{:uid=>65534, :gid=>65534}, :dbus=>{:uid=>81, :gid=>81}, :"systemd-journal...
|
482
|
+
|
483
|
+
LinuxStat::User.list
|
484
|
+
=> ["root", "bin", "daemon", "mail", "ftp", "http", "nobody", "dbus", "systemd-journal-remote", "systemd-network", "systemd-resolve", "systemd-timesync", "systemd-coredump", "uuidd", "avahi", "colord", "git", "lxdm", "polkitd", "rtkit", "usbmux", "sourav...
|
485
|
+
|
486
|
+
LinuxStat::User.uid_by_username
|
487
|
+
=> 1000
|
488
|
+
|
489
|
+
LinuxStat::User.uids
|
490
|
+
=> {:root=>0, :bin=>1, :daemon=>2, :mail=>8, :ftp=>14, :http=>33, :nobody=>65534, :dbus=>81, :"systemd-journal-remote"=>982, :"systemd-network"=>981, :"systemd-resolve"=>980, :"systemd-timesync"=>979, :"systemd-coredump"=>978, :uuidd=>68, :avahi=>977, :c...
|
491
|
+
|
492
|
+
LinuxStat::User.username_by_gid
|
493
|
+
=> "sourav"
|
294
494
|
|
495
|
+
LinuxStat::User.usernames_by_uid
|
496
|
+
=> ["sourav"]
|
497
|
+
|
498
|
+
```
|
499
|
+
|
500
|
+
---
|
501
|
+
|
502
|
+
## Note 1: Filesystem
|
503
|
+
|
504
|
+
Filesystem can take arguments. By default it's '/' or the root of the system...
|
505
|
+
|
506
|
+
But for the sake of example, to get the free disk space of /, you do:
|
507
|
+
|
508
|
+
```
|
509
|
+
$ irb
|
510
|
+
irb(main):001:0> require 'linux_stat'
|
511
|
+
=> true
|
512
|
+
|
513
|
+
irb(main):002:0> LinuxStat::Filesystem.free('/').fdiv(1024 ** 3).to_s << " GiB"
|
514
|
+
=> "35.666873931884766 GiB"
|
515
|
+
```
|
516
|
+
|
517
|
+
To see the free and total space of a thumbdrive:
|
518
|
+
|
519
|
+
```
|
520
|
+
$ irb
|
521
|
+
irb(main):001:0> require 'linux_stat'
|
522
|
+
=> true
|
523
|
+
|
524
|
+
irb(main):002:0> LinuxStat::Mounts.list.find { |x| x.include?('/run/media/sourav') }.split[1]
|
525
|
+
=> "/run/media/sourav/5c2b7af7-d4c3-4ab4-a035-06d18ffc8e6f"
|
526
|
+
|
527
|
+
irb(main):003:0> thumbdrive = _
|
528
|
+
=> "/run/media/sourav/5c2b7af7-d4c3-4ab4-a035-06d18ffc8e6f"
|
529
|
+
|
530
|
+
irb(main):004:0> LinuxStat::Filesystem.free(thumbdrive).fdiv(1024 ** 3).to_s << " GiB"
|
531
|
+
=> "2.504791259765625 GiB"
|
532
|
+
|
533
|
+
irb(main):005:0> LinuxStat::Filesystem.total(thumbdrive).fdiv(1024 ** 3).to_s << " GiB"
|
534
|
+
=> "29.305004119873047 GiB"
|
535
|
+
```
|
536
|
+
|
537
|
+
## Note 2: ProcessInfo
|
538
|
+
|
539
|
+
All the methods LinuxStat::ProcessInfo can take an argument containing the Process ID of a process.
|
540
|
+
By default it's $$ or the PID of the current process, ruby, itself.
|
541
|
+
|
542
|
+
Example:
|
543
|
+
Say you want to see how much CPU Firefox is consuming, for that you have to do the following (firefox can create a lot of child process though):
|
544
|
+
|
545
|
+
1. Get the PID of Firefox:
|
546
|
+
```
|
547
|
+
LinuxStat::Process.names.find { |x| x[1].include? 'firefox' }[0]
|
548
|
+
=> 770 # but this differs all the time
|
295
549
|
```
|
296
550
|
|
551
|
+
2. Get the CPU usage:
|
552
|
+
```
|
553
|
+
$ irb
|
554
|
+
irb(main):001:0> require 'linux_stat'
|
555
|
+
=> true
|
556
|
+
|
557
|
+
irb(main):002:0> pid = LinuxStat::Process.names.find { |x| x[1].include? 'firefox' }[0]
|
558
|
+
=> 770
|
559
|
+
|
560
|
+
irb(main):003:0> LinuxStat::ProcessInfo.cpu_usage(pid: pid)
|
561
|
+
=> 0.0
|
562
|
+
|
563
|
+
irb(main):004:0> LinuxStat::ProcessInfo.cpu_usage(pid: pid)
|
564
|
+
=> 15.0
|
565
|
+
```
|
566
|
+
|
567
|
+
To get the memory usage of Firefox (for example):
|
568
|
+
|
569
|
+
```
|
570
|
+
$ irb
|
571
|
+
irb(main):001:0> require 'linux_stat'
|
572
|
+
=> true
|
573
|
+
|
574
|
+
irb(main):002:0> LinuxStat::ProcessInfo.mem_stat(LinuxStat::Process.names.find { |x| x[1].include? 'firefox'.freeze }[0])
|
575
|
+
=> {:memory=>468472, :virtual_memory=>4754080, :resident_memory=>814388}
|
576
|
+
```
|
577
|
+
|
578
|
+
To get ONLY the memory usage in MiB:
|
579
|
+
|
580
|
+
```
|
581
|
+
$ irb
|
582
|
+
irb(main):001:0> require 'linux_stat'
|
583
|
+
=> true
|
584
|
+
|
585
|
+
irb(main):002:0> LinuxStat::ProcessInfo.memory(LinuxStat::Process.names.find { |x| x[1].include? 'firefox'.freeze }[0]).fdiv(1024).round(2).to_s << " MiB"
|
586
|
+
=> "467.51 MiB"
|
587
|
+
```
|
588
|
+
|
589
|
+
## Note 3: FS
|
590
|
+
|
591
|
+
LinuxStat::FS module gives you the raw info in Hash collected from statvfs.
|
592
|
+
|
593
|
+
It's not documented above because it's not suggested to run this directly. But it shouldn't cause any issue. `LinuxStat::Filesystem.stat_raw(fs = '/')` does that automatically.
|
594
|
+
|
595
|
+
It always requires an argument, and it's very fast. It directly calls the C API without any intermediate Ruby code.
|
596
|
+
|
597
|
+
For example, to get the info about '/' or root:
|
598
|
+
|
599
|
+
```
|
600
|
+
$ irb
|
601
|
+
irb(main):001:0> require 'linux_stat'
|
602
|
+
=> true
|
603
|
+
|
604
|
+
irb(main):002:0> LinuxStat::FS.stat('/')
|
605
|
+
=> {:block_size=>4096, :fragment_size=>4096, :blocks=>29292283, :block_free=>9349843, :block_avail_unpriv=>9349843, :inodes=>58612160, :free_inodes=>56708247, :filesystem_id=>2050, :mount_flags=>1024, :max_filename_length=>255}
|
606
|
+
|
607
|
+
irb(main):003:0> t = Time.now ; puts LinuxStat::FS.stat('/') ; Time.now - t
|
608
|
+
{:block_size=>4096, :fragment_size=>4096, :blocks=>29292283, :block_free=>9349843, :block_avail_unpriv=>9349843, :inodes=>58612160, :free_inodes=>56708247, :filesystem_id=>2050, :mount_flags=>1024, :max_filename_length=>255}
|
609
|
+
=> 5.0468e-05
|
610
|
+
```
|
611
|
+
|
612
|
+
To learn more about them, just run ri and the method name. To see all available methods.
|
613
|
+
|
614
|
+
## Note 4: User
|
615
|
+
Most of the LinuxStat::User supports arguments.
|
616
|
+
|
617
|
+
For example, to get a user's home by the username:
|
618
|
+
|
619
|
+
```
|
620
|
+
$ irb
|
621
|
+
irb(main):001:0> require 'linux_stat'
|
622
|
+
=> true
|
623
|
+
|
624
|
+
irb(main):002:0> LinuxStat::User.home_by_username('root')
|
625
|
+
=> "/root"
|
626
|
+
|
627
|
+
irb(main):003:0> LinuxStat::User.home_by_username('ftp')
|
628
|
+
=> "/srv/ftp"
|
629
|
+
|
630
|
+
irb(main):004:0> LinuxStat::User.home_by_username('mail')
|
631
|
+
=> "/var/spool/mail"
|
632
|
+
```
|
633
|
+
|
634
|
+
Or to get the user's home by the GID/UID:
|
635
|
+
|
636
|
+
```
|
637
|
+
$ irb
|
638
|
+
irb(main):001:0> require 'linux_stat'
|
639
|
+
=> true
|
640
|
+
|
641
|
+
irb(main):002:0> LinuxStat::User.homes_by_uid(1001)
|
642
|
+
=> ["/home/userx", "/home/userz"]
|
643
|
+
|
644
|
+
irb(main):003:0> LinuxStat::User.homes_by_uid(1000)
|
645
|
+
=> ["/home/sourav"]
|
646
|
+
|
647
|
+
irb(main):004:0> LinuxStat::User.home_by_gid(1001)
|
648
|
+
=> "/home/userx"
|
649
|
+
|
650
|
+
irb(main):005:0> LinuxStat::User.home_by_gid(1000)
|
651
|
+
=> "/home/sourav"
|
652
|
+
|
653
|
+
irb(main):006:0> LinuxStat::User.home_by_gid(0)
|
654
|
+
=> "/root"
|
655
|
+
```
|
656
|
+
|
657
|
+
Or to get the UID/GID by username:
|
658
|
+
|
659
|
+
```
|
660
|
+
$ irb
|
661
|
+
irb(main):001:0> require 'linux_stat'
|
662
|
+
=> true
|
663
|
+
|
664
|
+
irb(main):002:0> LinuxStat::User.uid_by_username('root')
|
665
|
+
=> 0
|
666
|
+
|
667
|
+
irb(main):003:0> LinuxStat::User.uid_by_username('ftp')
|
668
|
+
=> 14
|
669
|
+
|
670
|
+
irb(main):004:0> LinuxStat::User.gid_by_username('ftp')
|
671
|
+
=> 11
|
672
|
+
|
673
|
+
irb(main):005:0> LinuxStat::User.gid_by_username('InvalidUser')
|
674
|
+
=> nil
|
675
|
+
```
|
676
|
+
|
677
|
+
## Note 5: PrettifyBytes
|
678
|
+
Often times we need to work with KB, MB GB, TB, or KiB, MiB, GiB, TiB, etc.
|
679
|
+
And we need some work to convert bytes to those units.
|
680
|
+
Because LinuxStat provides a lot of data in bytes, and kilobytes, it's quite tedious to convert them all the time.
|
681
|
+
To avoid such duplication, it comes with a PrettifyBytes module.
|
682
|
+
|
683
|
+
For example, to convert bytes to decimal suffixes:
|
684
|
+
|
685
|
+
```
|
686
|
+
irb(main):001:0> require 'linux_stat'
|
687
|
+
=> true
|
688
|
+
|
689
|
+
irb(main):002:0> LinuxStat::PrettifyBytes.convert_decimal(1000)
|
690
|
+
=> "1.00 kilobyte"
|
691
|
+
|
692
|
+
irb(main):003:0> LinuxStat::PrettifyBytes.convert_decimal(10000)
|
693
|
+
=> "10.00 kilobytes"
|
694
|
+
|
695
|
+
irb(main):004:0> LinuxStat::PrettifyBytes.convert_decimal(100000)
|
696
|
+
=> "100.00 kilobytes"
|
697
|
+
|
698
|
+
irb(main):005:0> LinuxStat::PrettifyBytes.convert_decimal(10 ** 13)
|
699
|
+
=> "10.00 terabytes"
|
700
|
+
```
|
701
|
+
|
702
|
+
To convert bytes to binary suffixes:
|
703
|
+
|
704
|
+
```
|
705
|
+
irb(main):007:0> LinuxStat::PrettifyBytes.convert_binary(1000)
|
706
|
+
=> "1000.00 bytes"
|
707
|
+
|
708
|
+
irb(main):008:0> LinuxStat::PrettifyBytes.convert_binary(10000)
|
709
|
+
=> "9.77 kibibytes"
|
710
|
+
|
711
|
+
irb(main):009:0> LinuxStat::PrettifyBytes.convert_binary(100000)
|
712
|
+
=> "97.66 kibibytes"
|
713
|
+
|
714
|
+
irb(main):010:0> LinuxStat::PrettifyBytes.convert_binary(10 ** 13)
|
715
|
+
=> "9.09 tebibytes"
|
716
|
+
```
|
717
|
+
|
718
|
+
To convert them to short Metric decimal suffixes:
|
719
|
+
|
720
|
+
```
|
721
|
+
irb(main):017:0> LinuxStat::PrettifyBytes.convert_short_decimal(1000)
|
722
|
+
=> "1.00 kB"
|
723
|
+
|
724
|
+
irb(main):018:0> LinuxStat::PrettifyBytes.convert_short_decimal(10000)
|
725
|
+
=> "10.00 kB"
|
726
|
+
|
727
|
+
irb(main):019:0> LinuxStat::PrettifyBytes.convert_short_decimal(100000)
|
728
|
+
=> "100.00 kB"
|
729
|
+
|
730
|
+
irb(main):020:0> LinuxStat::PrettifyBytes.convert_short_decimal(10 ** 13)
|
731
|
+
=> "10.00 TB"
|
732
|
+
```
|
733
|
+
|
734
|
+
To convert them to short IEC binary suffixes:
|
735
|
+
|
736
|
+
```
|
737
|
+
irb(main):013:0> LinuxStat::PrettifyBytes.convert_short_binary(1000)
|
738
|
+
=> "1000 B"
|
739
|
+
|
740
|
+
irb(main):014:0> LinuxStat::PrettifyBytes.convert_short_binary(10000)
|
741
|
+
=> "9.77 KiB"
|
742
|
+
|
743
|
+
irb(main):015:0> LinuxStat::PrettifyBytes.convert_short_binary(100000)
|
744
|
+
=> "97.66 KiB"
|
745
|
+
|
746
|
+
irb(main):016:0> LinuxStat::PrettifyBytes.convert_short_binary(10 ** 13)
|
747
|
+
=> "9.09 TiB"
|
748
|
+
```
|
749
|
+
|
750
|
+
It can support values upto hundreds of yottabytes and yobibytes, or yb and yib.
|
751
|
+
|
752
|
+
Read the ri documentation for more info.
|
753
|
+
|
754
|
+
---
|
755
|
+
|
297
756
|
## Return Types
|
298
757
|
+ In general, if a method returns either a Float or a Integer or a Time, it will return a Float or Integer or Time in all cases. But if the status isn't available, it will return nil.
|
299
758
|
|
@@ -307,6 +766,8 @@ LinuxStat::Swap.used
|
|
307
766
|
|
308
767
|
If some error is *raised* it should be reported as a bug.
|
309
768
|
|
769
|
+
---
|
770
|
+
|
310
771
|
## Ruby on Rails
|
311
772
|
|
312
773
|
1. Just add `gem linux_stat`:
|
@@ -319,48 +780,64 @@ You can use LinuxStat directly in rails.
|
|
319
780
|
|
320
781
|

|
321
782
|
|
783
|
+
---
|
322
784
|
|
323
785
|
## Android
|
324
786
|
|
325
787
|
LinuxStat does support Android OS. But it's not rigorously tested on all device like android apps.
|
326
788
|
|
327
789
|
But in Termux you can just run LinuxStat without facing issues.
|
790
|
+
Note that the CPU count can differ due to hotplugging feature. So if you see the CPU count changes, there's not really nothing to do about that.
|
328
791
|
|
329
792
|

|
330
793
|
|
331
794
|
Issues regarding running LinuxStat on termux are also welcomed.
|
332
795
|
|
796
|
+
---
|
797
|
+
|
333
798
|
## Development
|
799
|
+
After checking out the repo, compile and install this gem onto your local machine with `bundle exec rake install`
|
334
800
|
|
335
|
-
|
801
|
+
You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
336
802
|
|
337
|
-
To
|
803
|
+
To test all modules, run `rake install` and then `exe/linuxstat.rb`. Also check "Testing" below.
|
804
|
+
|
805
|
+
---
|
338
806
|
|
339
807
|
## Testing
|
340
|
-
Like other gems, this doesn't have a test like RSpec.
|
808
|
+
Like other gems, this doesn't have a test like RSpec.
|
809
|
+
|
810
|
+
We suggest using the exe/linuxstat.rb file on various Linux systems to test.
|
811
|
+
|
812
|
+
First you need to execute `bundle exec rake install` to compile and install this gem.
|
813
|
+
|
341
814
|
If you need to test a specific module, say the CPU, just run it like this:
|
342
815
|
|
343
816
|
```
|
344
|
-
$ ruby
|
817
|
+
$ ruby exe/linuxstat.rb CPU
|
345
818
|
```
|
346
819
|
|
347
820
|
Or:
|
348
821
|
```
|
349
|
-
$ ruby
|
822
|
+
$ ruby exe/linuxstat.rb cpu
|
350
823
|
```
|
351
824
|
|
352
825
|
That is, the argument passed is not case-sensitive.
|
353
826
|
But if the argument passed isn't available and outright wrong, it will run all the module methods. For example, you can't do:
|
354
827
|
|
355
828
|
```
|
356
|
-
$ ruby
|
829
|
+
$ ruby exe/linuxstat.rb upc
|
357
830
|
```
|
358
831
|
This is not a valid module and can't be run.
|
359
832
|
|
833
|
+
---
|
834
|
+
|
360
835
|
## Contributing
|
361
836
|
|
362
837
|
Bug reports and pull requests are welcome on GitHub at https://github.com/Souravgoswami/linux_stat.
|
363
838
|
|
839
|
+
---
|
840
|
+
|
364
841
|
## License
|
365
842
|
|
366
843
|
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|