linux_stat 0.4.2 → 0.6.3
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 +354 -57
- data/bin/console +1 -1
- data/bin/setup +0 -2
- data/{bin → exe}/linuxstat.rb +7 -9
- data/ext/fs_stat/fs_stat.c +2 -0
- data/ext/sysconf/sysconf.c +30 -2
- data/ext/utsname/utsname.c +2 -0
- data/lib/linux_stat.rb +32 -4
- data/lib/linux_stat/cpu.rb +14 -5
- data/lib/linux_stat/kernel.rb +1 -2
- data/lib/linux_stat/mounts.rb +152 -1
- data/lib/linux_stat/net.rb +107 -1
- data/lib/linux_stat/prettify_bytes.rb +75 -0
- data/lib/linux_stat/process_info.rb +107 -48
- data/lib/linux_stat/user.rb +298 -0
- data/lib/linux_stat/version.rb +1 -1
- metadata +11 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 05ad75bfd711c7ac7960645e2609416e868f2b425cbac94b503198db8b011aa4
|
4
|
+
data.tar.gz: f6291a5aaa6903839d7915c8e8494d88cf165dd6e82143ff0fc71dcea19628d8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f4406f12e2035652f26f9eb518bb4386e644622938d506880cc3f2899937e060b594d6067a8b4a4b66c85db24f068b13a70e59cbac4f9770cc937569e506da26
|
7
|
+
data.tar.gz: b0bbb6cd4570228bafaa2fe89d2bc6a75e67803334e907bcf6e3c3a3fb70f1333ac98da133484b37d8fe279d991ffd18cad617fa931f77c9c7150798cc2d580a
|
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
@@ -13,12 +13,12 @@ It only works for Linux, and detecting the OS is upto the user of this gem.
|
|
13
13
|
+ You need to have the C compile to be able to compile the C extension.
|
14
14
|
On Arch Linux:
|
15
15
|
```
|
16
|
-
# pacman -S gcc
|
16
|
+
# pacman -S gcc make
|
17
17
|
```
|
18
18
|
|
19
19
|
On Debian based systems:
|
20
20
|
```
|
21
|
-
# apt install gcc
|
21
|
+
# apt install gcc build-essential
|
22
22
|
```
|
23
23
|
|
24
24
|
+ You might also require ruby-dev in Debian based systems which provides support for ruby.h header file:
|
@@ -103,7 +103,7 @@ LinuxStat::CPU.count
|
|
103
103
|
=> 4
|
104
104
|
|
105
105
|
LinuxStat::CPU.cur_freq
|
106
|
-
=> [
|
106
|
+
=> [2000063, 2000108, 2000332, 2000028]
|
107
107
|
|
108
108
|
LinuxStat::CPU.max_freq
|
109
109
|
=> [2000000, 2000000, 2000000, 2000000]
|
@@ -112,48 +112,48 @@ LinuxStat::CPU.model
|
|
112
112
|
=> "Intel(R) Core(TM) i3-6006U CPU @ 2.00GHz"
|
113
113
|
|
114
114
|
LinuxStat::CPU.stat
|
115
|
-
=> {0=>
|
115
|
+
=> {0=>0.0, 1=>0.0, 2=>0.0, 3=>0.0, 4=>0.0}
|
116
116
|
|
117
117
|
LinuxStat::CPU.total_usage
|
118
|
-
=>
|
118
|
+
=> 0.0
|
119
119
|
|
120
120
|
LinuxStat::CPU.usage
|
121
|
-
=>
|
121
|
+
=> 20.0
|
122
122
|
|
123
123
|
LinuxStat::CPU.usages
|
124
|
-
=> {0=>
|
124
|
+
=> {0=>20.0, 1=>0.0, 2=>0.0, 3=>50.0, 4=>100.0}
|
125
125
|
|
126
126
|
```
|
127
127
|
|
128
128
|
### LinuxStat::Filesystem
|
129
129
|
```
|
130
130
|
LinuxStat::Filesystem.available
|
131
|
-
=>
|
131
|
+
=> 33120964608
|
132
132
|
|
133
133
|
LinuxStat::Filesystem.free
|
134
|
-
=>
|
134
|
+
=> 33120964608
|
135
135
|
|
136
136
|
LinuxStat::Filesystem.stat
|
137
|
-
=> {:total=>119981191168, :free=>
|
137
|
+
=> {:total=>119981191168, :free=>33120964608, :used=>86860226560}
|
138
138
|
|
139
139
|
LinuxStat::Filesystem.stat_raw
|
140
|
-
=> {:block_size=>4096, :fragment_size=>4096, :blocks=>29292283, :block_free=>
|
140
|
+
=> {:block_size=>4096, :fragment_size=>4096, :blocks=>29292283, :block_free=>8086173, :block_avail_unpriv=>8086173, :inodes=>58612160, :free_inodes=>56567338, :filesystem_id=>2050, :mount_flags=>1024, :max_filename_length=>255}
|
141
141
|
|
142
142
|
LinuxStat::Filesystem.total
|
143
143
|
=> 119981191168
|
144
144
|
|
145
145
|
LinuxStat::Filesystem.used
|
146
|
-
=>
|
146
|
+
=> 86860226560
|
147
147
|
|
148
148
|
```
|
149
149
|
|
150
150
|
### LinuxStat::Kernel
|
151
151
|
```
|
152
152
|
LinuxStat::Kernel.build_date
|
153
|
-
=> 2020-
|
153
|
+
=> 2020-11-20 07:44:55 +0000
|
154
154
|
|
155
155
|
LinuxStat::Kernel.build_date_string
|
156
|
-
=> "
|
156
|
+
=> "20 Nov 2020 07:44:55 +0000"
|
157
157
|
|
158
158
|
LinuxStat::Kernel.build_user
|
159
159
|
=> "souravgoswami@archlinux"
|
@@ -168,45 +168,60 @@ LinuxStat::Kernel.compiler_version
|
|
168
168
|
=> "10.2.0"
|
169
169
|
|
170
170
|
LinuxStat::Kernel.release
|
171
|
-
=> "5.9.
|
171
|
+
=> "5.9.9-xanmod1-1"
|
172
172
|
|
173
173
|
LinuxStat::Kernel.string
|
174
|
-
=> "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
175
|
|
176
176
|
LinuxStat::Kernel.ticks
|
177
177
|
=> 100
|
178
178
|
|
179
179
|
LinuxStat::Kernel.version
|
180
|
-
=> "5.9.
|
180
|
+
=> "5.9.9-xanmod1-1"
|
181
181
|
|
182
182
|
```
|
183
183
|
|
184
184
|
### LinuxStat::Memory
|
185
185
|
```
|
186
186
|
LinuxStat::Memory.available
|
187
|
-
=>
|
187
|
+
=> 579264
|
188
188
|
|
189
189
|
LinuxStat::Memory.percent_available
|
190
|
-
=> 15.
|
190
|
+
=> 15.1
|
191
191
|
|
192
192
|
LinuxStat::Memory.percent_used
|
193
|
-
=> 84.
|
193
|
+
=> 84.9
|
194
194
|
|
195
195
|
LinuxStat::Memory.stat
|
196
|
-
=> {:total=>
|
196
|
+
=> {:total=>3836236, :used=>3256972, :available=>579264, :percent_used=>84.9, :percent_available=>15.1}
|
197
197
|
|
198
198
|
LinuxStat::Memory.total
|
199
|
-
=>
|
199
|
+
=> 3836236
|
200
200
|
|
201
201
|
LinuxStat::Memory.used
|
202
|
-
=>
|
202
|
+
=> 3256972
|
203
203
|
|
204
204
|
```
|
205
205
|
|
206
206
|
### LinuxStat::Mounts
|
207
207
|
```
|
208
|
+
LinuxStat::Mounts.device_stat
|
209
|
+
=> {:mountpoint=>"/", :total=>119981191168, :free=>33120964608, :available=>33120964608, :used=>86860226560, :percent_used=>72.39, :percent_free=>27.61, :percent_available=>27.61}
|
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
|
+
|
208
214
|
LinuxStat::Mounts.list
|
209
|
-
=> ["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=1892908k,nr_inodes=473227,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
|
+
=> "/"
|
210
225
|
|
211
226
|
LinuxStat::Mounts.root
|
212
227
|
=> "/dev/sda2"
|
@@ -224,8 +239,23 @@ LinuxStat::Mounts.tmpfs
|
|
224
239
|
|
225
240
|
### LinuxStat::Net
|
226
241
|
```
|
242
|
+
LinuxStat::Net.current_usage
|
243
|
+
=> {:received=>2183400.0, :transmitted=>114860.0}
|
244
|
+
|
227
245
|
LinuxStat::Net.ipv4_private
|
228
|
-
=> "192.168.0.
|
246
|
+
=> "192.168.0.102"
|
247
|
+
|
248
|
+
LinuxStat::Net.total_bytes
|
249
|
+
=> {:received=>294316415, :transmitted=>45313147}
|
250
|
+
|
251
|
+
LinuxStat::Net.total_bytes_received
|
252
|
+
=> 294317913
|
253
|
+
|
254
|
+
LinuxStat::Net.total_bytes_transmitted
|
255
|
+
=> 45313147
|
256
|
+
|
257
|
+
LinuxStat::Net.usage
|
258
|
+
=> {:received=>1643690.0, :transmitted=>146030.0}
|
229
259
|
|
230
260
|
```
|
231
261
|
|
@@ -253,29 +283,29 @@ LinuxStat::OS.os_release
|
|
253
283
|
=> {: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/"...
|
254
284
|
|
255
285
|
LinuxStat::OS.uptime
|
256
|
-
=> {:hour=>
|
286
|
+
=> {:hour=>7, :minute=>44, :second=>29.92}
|
257
287
|
|
258
288
|
```
|
259
289
|
|
260
290
|
### LinuxStat::Process
|
261
291
|
```
|
262
292
|
LinuxStat::Process.count
|
263
|
-
=>
|
293
|
+
=> 205
|
264
294
|
|
265
295
|
LinuxStat::Process.idle
|
266
|
-
=> [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, 152, 153,
|
296
|
+
=> [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, 152, 153, 166, 168, 172, 174, 176, 178, 182, 183, 184, 185, 186, 188, 230, 271, 324, 328, 337, 14228, 14757, 14998, 14999, 15000, 15001, 15...
|
267
297
|
|
268
298
|
LinuxStat::Process.list
|
269
|
-
=> [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,
|
299
|
+
=> [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, 120, 122, 131, 134,...
|
270
300
|
|
271
301
|
LinuxStat::Process.names
|
272
|
-
=> {1=>"systemd", 2=>"kthreadd", 3=>"rcu_gp", 4=>"rcu_par_gp", 6=>"kworker/0:0H
|
302
|
+
=> {1=>"systemd", 2=>"kthreadd", 3=>"rcu_gp", 4=>"rcu_par_gp", 6=>"kworker/0:0H", 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_inject/...
|
273
303
|
|
274
304
|
LinuxStat::Process.running
|
275
|
-
=> [
|
305
|
+
=> [21158]
|
276
306
|
|
277
307
|
LinuxStat::Process.sleeping
|
278
|
-
=> [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,
|
308
|
+
=> [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, 165, 167, 189, 217, 231, 302, 307, 308, 309, 310, 320, 321, 322, 323, 325, 326, 350, 353, 356, 374, 394,...
|
279
309
|
|
280
310
|
LinuxStat::Process.types
|
281
311
|
=> {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...
|
@@ -288,28 +318,34 @@ LinuxStat::Process.zombie
|
|
288
318
|
### LinuxStat::ProcessInfo
|
289
319
|
```
|
290
320
|
LinuxStat::ProcessInfo.cmdline
|
291
|
-
=> "ruby
|
321
|
+
=> "ruby exe/linuxstat.rb -md"
|
292
322
|
|
293
323
|
LinuxStat::ProcessInfo.command_name
|
294
324
|
=> "ruby"
|
295
325
|
|
296
326
|
LinuxStat::ProcessInfo.cpu_stat
|
297
|
-
=> {:cpu_usage=>0.0, :threads=>1, :last_executed_cpu=>
|
327
|
+
=> {:cpu_usage=>0.0, :threads=>1, :last_executed_cpu=>1}
|
298
328
|
|
299
329
|
LinuxStat::ProcessInfo.cpu_usage
|
300
330
|
=> 0.0
|
301
331
|
|
332
|
+
LinuxStat::ProcessInfo.gid
|
333
|
+
=> {:real=>1000, :effective=>1000, :saved_set=>1000, :filesystem_uid=>1000}
|
334
|
+
|
302
335
|
LinuxStat::ProcessInfo.last_executed_cpu
|
303
|
-
=>
|
336
|
+
=> 1
|
304
337
|
|
305
338
|
LinuxStat::ProcessInfo.mem_stat
|
306
|
-
=> {:memory=>
|
339
|
+
=> {:memory=>10051.584, :virtual_memory=>81801.216, :resident_memory=>15986.688}
|
307
340
|
|
308
341
|
LinuxStat::ProcessInfo.memory
|
309
|
-
=>
|
342
|
+
=> 10051.584
|
343
|
+
|
344
|
+
LinuxStat::ProcessInfo.owner
|
345
|
+
=> "sourav"
|
310
346
|
|
311
347
|
LinuxStat::ProcessInfo.resident_memory
|
312
|
-
=>
|
348
|
+
=> 15986.688
|
313
349
|
|
314
350
|
LinuxStat::ProcessInfo.threads
|
315
351
|
=> 1
|
@@ -317,8 +353,11 @@ LinuxStat::ProcessInfo.threads
|
|
317
353
|
LinuxStat::ProcessInfo.total_io
|
318
354
|
=> {:read_bytes=>0, :write_bytes=>0}
|
319
355
|
|
356
|
+
LinuxStat::ProcessInfo.uid
|
357
|
+
=> {:real=>1000, :effective=>1000, :saved_set=>1000, :filesystem_uid=>1000}
|
358
|
+
|
320
359
|
LinuxStat::ProcessInfo.virtual_memory
|
321
|
-
=>
|
360
|
+
=> 81801.216
|
322
361
|
|
323
362
|
```
|
324
363
|
|
@@ -328,25 +367,25 @@ LinuxStat::Swap.any?
|
|
328
367
|
=> true
|
329
368
|
|
330
369
|
LinuxStat::Swap.available
|
331
|
-
=>
|
370
|
+
=> 3383720
|
332
371
|
|
333
372
|
LinuxStat::Swap.list
|
334
|
-
=> {"/dev/zram0"=>[:partition, 4194300,
|
373
|
+
=> {"/dev/zram0"=>[:partition, 4194300, 810580, -2]}
|
335
374
|
|
336
375
|
LinuxStat::Swap.percent_available
|
337
|
-
=>
|
376
|
+
=> 80.67
|
338
377
|
|
339
378
|
LinuxStat::Swap.percent_used
|
340
|
-
=>
|
379
|
+
=> 19.33
|
341
380
|
|
342
381
|
LinuxStat::Swap.stat
|
343
|
-
=> {:total=>4194300, :used=>
|
382
|
+
=> {:total=>4194300, :used=>810580, :available=>3383720, :percent_used=>19.33, :percent_available=>80.67}
|
344
383
|
|
345
384
|
LinuxStat::Swap.total
|
346
385
|
=> 4194300
|
347
386
|
|
348
387
|
LinuxStat::Swap.used
|
349
|
-
=>
|
388
|
+
=> 810580
|
350
389
|
|
351
390
|
```
|
352
391
|
|
@@ -355,6 +394,21 @@ LinuxStat::Swap.used
|
|
355
394
|
LinuxStat::Sysconf.child_max
|
356
395
|
=> 2000000
|
357
396
|
|
397
|
+
LinuxStat::Sysconf.get_euid
|
398
|
+
=> 1000
|
399
|
+
|
400
|
+
LinuxStat::Sysconf.get_gid
|
401
|
+
=> 1000
|
402
|
+
|
403
|
+
LinuxStat::Sysconf.get_login
|
404
|
+
=> "sourav"
|
405
|
+
|
406
|
+
LinuxStat::Sysconf.get_uid
|
407
|
+
=> 1000
|
408
|
+
|
409
|
+
LinuxStat::Sysconf.get_user
|
410
|
+
=> "sourav"
|
411
|
+
|
358
412
|
LinuxStat::Sysconf.hostname_max
|
359
413
|
=> 64
|
360
414
|
|
@@ -362,9 +416,9 @@ LinuxStat::Sysconf.login_name_max
|
|
362
416
|
=> 256
|
363
417
|
|
364
418
|
LinuxStat::Sysconf.open_max
|
365
|
-
=>
|
419
|
+
=> 1024
|
366
420
|
|
367
|
-
LinuxStat::Sysconf.
|
421
|
+
LinuxStat::Sysconf.pagesize
|
368
422
|
=> 4096
|
369
423
|
|
370
424
|
LinuxStat::Sysconf.posix_version
|
@@ -390,15 +444,74 @@ LinuxStat::Uname.nodename
|
|
390
444
|
=> "archlinux"
|
391
445
|
|
392
446
|
LinuxStat::Uname.release
|
393
|
-
=> "5.9.
|
447
|
+
=> "5.9.9-xanmod1-1"
|
394
448
|
|
395
449
|
LinuxStat::Uname.sysname
|
396
450
|
=> "Linux"
|
397
451
|
|
398
452
|
LinuxStat::Uname.version
|
399
|
-
=> "#1 SMP PREEMPT
|
453
|
+
=> "#1 SMP PREEMPT Fri, 20 Nov 2020 07:44:55 +0000"
|
454
|
+
|
455
|
+
```
|
400
456
|
|
457
|
+
### LinuxStat::User
|
401
458
|
```
|
459
|
+
LinuxStat::User.get_current_user
|
460
|
+
=> "sourav"
|
461
|
+
|
462
|
+
LinuxStat::User.get_euid
|
463
|
+
=> 1000
|
464
|
+
|
465
|
+
LinuxStat::User.get_gid
|
466
|
+
=> 1000
|
467
|
+
|
468
|
+
LinuxStat::User.get_login
|
469
|
+
=> "sourav"
|
470
|
+
|
471
|
+
LinuxStat::User.get_uid
|
472
|
+
=> 1000
|
473
|
+
|
474
|
+
LinuxStat::User.get_user
|
475
|
+
=> "sourav"
|
476
|
+
|
477
|
+
LinuxStat::User.gid_by_username
|
478
|
+
=> 1000
|
479
|
+
|
480
|
+
LinuxStat::User.gids
|
481
|
+
=> {: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, :...
|
482
|
+
|
483
|
+
LinuxStat::User.home_by_gid
|
484
|
+
=> "/home/sourav"
|
485
|
+
|
486
|
+
LinuxStat::User.home_by_username
|
487
|
+
=> "/home/sourav"
|
488
|
+
|
489
|
+
LinuxStat::User.home_directories
|
490
|
+
=> {: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...
|
491
|
+
|
492
|
+
LinuxStat::User.homes_by_uid
|
493
|
+
=> ["/home/sourav"]
|
494
|
+
|
495
|
+
LinuxStat::User.ids
|
496
|
+
=> {: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...
|
497
|
+
|
498
|
+
LinuxStat::User.list
|
499
|
+
=> ["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...
|
500
|
+
|
501
|
+
LinuxStat::User.uid_by_username
|
502
|
+
=> 1000
|
503
|
+
|
504
|
+
LinuxStat::User.uids
|
505
|
+
=> {: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...
|
506
|
+
|
507
|
+
LinuxStat::User.username_by_gid
|
508
|
+
=> "sourav"
|
509
|
+
|
510
|
+
LinuxStat::User.usernames_by_uid
|
511
|
+
=> ["sourav"]
|
512
|
+
|
513
|
+
```
|
514
|
+
|
402
515
|
---
|
403
516
|
|
404
517
|
## Note 1: Filesystem
|
@@ -423,7 +536,7 @@ $ irb
|
|
423
536
|
irb(main):001:0> require 'linux_stat'
|
424
537
|
=> true
|
425
538
|
|
426
|
-
irb(main):002:0> LinuxStat::Mounts.
|
539
|
+
irb(main):002:0> LinuxStat::Mounts.mount_point('/dev/sdb1')
|
427
540
|
=> "/run/media/sourav/5c2b7af7-d4c3-4ab4-a035-06d18ffc8e6f"
|
428
541
|
|
429
542
|
irb(main):003:0> thumbdrive = _
|
@@ -511,7 +624,185 @@ irb(main):003:0> t = Time.now ; puts LinuxStat::FS.stat('/') ; Time.now - t
|
|
511
624
|
=> 5.0468e-05
|
512
625
|
```
|
513
626
|
|
514
|
-
To learn more about them, just run ri and the method name. To see all available methods
|
627
|
+
To learn more about them, just run ri and the method name. To see all available methods.
|
628
|
+
|
629
|
+
## Note 4: User
|
630
|
+
Most of the LinuxStat::User supports arguments.
|
631
|
+
|
632
|
+
For example, to get a user's home by the username:
|
633
|
+
|
634
|
+
```
|
635
|
+
$ irb
|
636
|
+
irb(main):001:0> require 'linux_stat'
|
637
|
+
=> true
|
638
|
+
|
639
|
+
irb(main):002:0> LinuxStat::User.home_by_username('root')
|
640
|
+
=> "/root"
|
641
|
+
|
642
|
+
irb(main):003:0> LinuxStat::User.home_by_username('ftp')
|
643
|
+
=> "/srv/ftp"
|
644
|
+
|
645
|
+
irb(main):004:0> LinuxStat::User.home_by_username('mail')
|
646
|
+
=> "/var/spool/mail"
|
647
|
+
```
|
648
|
+
|
649
|
+
Or to get the user's home by the GID/UID:
|
650
|
+
|
651
|
+
```
|
652
|
+
$ irb
|
653
|
+
irb(main):001:0> require 'linux_stat'
|
654
|
+
=> true
|
655
|
+
|
656
|
+
irb(main):002:0> LinuxStat::User.homes_by_uid(1001)
|
657
|
+
=> ["/home/userx", "/home/userz"]
|
658
|
+
|
659
|
+
irb(main):003:0> LinuxStat::User.homes_by_uid(1000)
|
660
|
+
=> ["/home/sourav"]
|
661
|
+
|
662
|
+
irb(main):004:0> LinuxStat::User.home_by_gid(1001)
|
663
|
+
=> "/home/userx"
|
664
|
+
|
665
|
+
irb(main):005:0> LinuxStat::User.home_by_gid(1000)
|
666
|
+
=> "/home/sourav"
|
667
|
+
|
668
|
+
irb(main):006:0> LinuxStat::User.home_by_gid(0)
|
669
|
+
=> "/root"
|
670
|
+
```
|
671
|
+
|
672
|
+
Or to get the UID/GID by username:
|
673
|
+
|
674
|
+
```
|
675
|
+
$ irb
|
676
|
+
irb(main):001:0> require 'linux_stat'
|
677
|
+
=> true
|
678
|
+
|
679
|
+
irb(main):002:0> LinuxStat::User.uid_by_username('root')
|
680
|
+
=> 0
|
681
|
+
|
682
|
+
irb(main):003:0> LinuxStat::User.uid_by_username('ftp')
|
683
|
+
=> 14
|
684
|
+
|
685
|
+
irb(main):004:0> LinuxStat::User.gid_by_username('ftp')
|
686
|
+
=> 11
|
687
|
+
|
688
|
+
irb(main):005:0> LinuxStat::User.gid_by_username('InvalidUser')
|
689
|
+
=> nil
|
690
|
+
```
|
691
|
+
|
692
|
+
Or to get the current user (in docker for example):
|
693
|
+
|
694
|
+
```
|
695
|
+
$ irb
|
696
|
+
irb(main):001:0> require 'linux_stat'
|
697
|
+
=> true
|
698
|
+
|
699
|
+
irb(main):002:0> LinuxStat::User.get_current_user
|
700
|
+
=> "x"
|
701
|
+
|
702
|
+
irb(main):003:0> LinuxStat::User.get_user
|
703
|
+
=> "x"
|
704
|
+
|
705
|
+
irb(main):004:0> LinuxStat::User.get_login
|
706
|
+
=> ""
|
707
|
+
```
|
708
|
+
|
709
|
+
Right, the get_login() can return an empty string. But LinuxStat::User.get_user also aliased as LinuxStat::User.get_current_user shouldn't return an empty string under most circumstances.
|
710
|
+
|
711
|
+
## Note 5: PrettifyBytes
|
712
|
+
Often times we need to work with KB, MB GB, TB, or KiB, MiB, GiB, TiB, etc.
|
713
|
+
And we need some work to convert bytes to those units.
|
714
|
+
Because LinuxStat provides a lot of data in bytes, and kilobytes, it's quite tedious to convert them all the time.
|
715
|
+
To avoid such duplication, it comes with a PrettifyBytes module.
|
716
|
+
|
717
|
+
For example, to convert bytes to decimal suffixes:
|
718
|
+
|
719
|
+
```
|
720
|
+
$irb
|
721
|
+
irb(main):001:0> require 'linux_stat'
|
722
|
+
=> true
|
723
|
+
|
724
|
+
irb(main):002:0> LinuxStat::PrettifyBytes.convert_decimal(1000)
|
725
|
+
=> "1.00 kilobyte"
|
726
|
+
|
727
|
+
irb(main):003:0> LinuxStat::PrettifyBytes.convert_decimal(10000)
|
728
|
+
=> "10.00 kilobytes"
|
729
|
+
|
730
|
+
irb(main):004:0> LinuxStat::PrettifyBytes.convert_decimal(100000)
|
731
|
+
=> "100.00 kilobytes"
|
732
|
+
|
733
|
+
irb(main):005:0> LinuxStat::PrettifyBytes.convert_decimal(10 ** 13)
|
734
|
+
=> "10.00 terabytes"
|
735
|
+
```
|
736
|
+
|
737
|
+
To convert bytes to binary suffixes:
|
738
|
+
|
739
|
+
```
|
740
|
+
irb(main):006:0> LinuxStat::PrettifyBytes.convert_binary(1000)
|
741
|
+
=> "1000.00 bytes"
|
742
|
+
|
743
|
+
irb(main):007:0> LinuxStat::PrettifyBytes.convert_binary(10000)
|
744
|
+
=> "9.77 kibibytes"
|
745
|
+
|
746
|
+
irb(main):008:0> LinuxStat::PrettifyBytes.convert_binary(100000)
|
747
|
+
=> "97.66 kibibytes"
|
748
|
+
|
749
|
+
irb(main):009:0> LinuxStat::PrettifyBytes.convert_binary(10 ** 13)
|
750
|
+
=> "9.09 tebibytes"
|
751
|
+
```
|
752
|
+
|
753
|
+
To convert them to short Metric decimal suffixes:
|
754
|
+
|
755
|
+
```
|
756
|
+
irb(main):010:0> LinuxStat::PrettifyBytes.convert_short_decimal(1000)
|
757
|
+
=> "1.00 kB"
|
758
|
+
|
759
|
+
irb(main):011:0> LinuxStat::PrettifyBytes.convert_short_decimal(10000)
|
760
|
+
=> "10.00 kB"
|
761
|
+
|
762
|
+
irb(main):012:0> LinuxStat::PrettifyBytes.convert_short_decimal(100000)
|
763
|
+
=> "100.00 kB"
|
764
|
+
|
765
|
+
irb(main):013:0> LinuxStat::PrettifyBytes.convert_short_decimal(10 ** 13)
|
766
|
+
=> "10.00 TB"
|
767
|
+
```
|
768
|
+
|
769
|
+
To convert them to short IEC binary suffixes:
|
770
|
+
|
771
|
+
```
|
772
|
+
irb(main):014:0> LinuxStat::PrettifyBytes.convert_short_binary(1000)
|
773
|
+
=> "1000 B"
|
774
|
+
|
775
|
+
irb(main):015:0> LinuxStat::PrettifyBytes.convert_short_binary(10000)
|
776
|
+
=> "9.77 KiB"
|
777
|
+
|
778
|
+
irb(main):016:0> LinuxStat::PrettifyBytes.convert_short_binary(100000)
|
779
|
+
=> "97.66 KiB"
|
780
|
+
|
781
|
+
irb(main):017:0> LinuxStat::PrettifyBytes.convert_short_binary(10 ** 13)
|
782
|
+
=> "9.09 TiB"
|
783
|
+
```
|
784
|
+
|
785
|
+
It can support values upto hundreds of yottabytes and yobibytes, or yb and yib. You can also do stuff like:
|
786
|
+
|
787
|
+
```
|
788
|
+
$ irb
|
789
|
+
irb(main):001:0> require 'linux_stat'
|
790
|
+
=> true
|
791
|
+
|
792
|
+
irb(main):002:0> LinuxStat::PrettifyBytes.convert_short_decimal(LinuxStat::Mounts.device_stat('/dev/sdb1')[:total])
|
793
|
+
=> "31.47 GB"
|
794
|
+
|
795
|
+
irb(main):003:0> LinuxStat::PrettifyBytes.convert_short_binary(LinuxStat::Mounts.device_stat('/dev/sdb1')[:total])
|
796
|
+
=> "29.31 GiB"
|
797
|
+
|
798
|
+
irb(main):004:0> LinuxStat::PrettifyBytes.convert_short_binary(LinuxStat::Mounts.device_stat('/dev/sdb1')[:used])
|
799
|
+
=> "26.80 GiB"
|
800
|
+
|
801
|
+
irb(main):005:0> LinuxStat::PrettifyBytes.convert_short_binary(LinuxStat::Mounts.device_stat('/dev/sdb1')[:available])
|
802
|
+
=> "2.51 GiB"
|
803
|
+
```
|
804
|
+
|
805
|
+
Read the ri documentation for more info.
|
515
806
|
|
516
807
|
---
|
517
808
|
|
@@ -558,31 +849,37 @@ Issues regarding running LinuxStat on termux are also welcomed.
|
|
558
849
|
---
|
559
850
|
|
560
851
|
## Development
|
852
|
+
After checking out the repo, compile and install this gem onto your local machine with `bundle exec rake install`
|
561
853
|
|
562
|
-
|
854
|
+
You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
563
855
|
|
564
|
-
To
|
856
|
+
To test all modules, run `rake install` and then `exe/linuxstat.rb`. Also check "Testing" below.
|
565
857
|
|
566
858
|
---
|
567
859
|
|
568
860
|
## Testing
|
569
|
-
Like other gems, this doesn't have a test like RSpec.
|
861
|
+
Like other gems, this doesn't have a test like RSpec.
|
862
|
+
|
863
|
+
We suggest using the exe/linuxstat.rb file on various Linux systems to test.
|
864
|
+
|
865
|
+
First you need to execute `bundle exec rake install` to compile and install this gem.
|
866
|
+
|
570
867
|
If you need to test a specific module, say the CPU, just run it like this:
|
571
868
|
|
572
869
|
```
|
573
|
-
$ ruby
|
870
|
+
$ ruby exe/linuxstat.rb CPU
|
574
871
|
```
|
575
872
|
|
576
873
|
Or:
|
577
874
|
```
|
578
|
-
$ ruby
|
875
|
+
$ ruby exe/linuxstat.rb cpu
|
579
876
|
```
|
580
877
|
|
581
878
|
That is, the argument passed is not case-sensitive.
|
582
879
|
But if the argument passed isn't available and outright wrong, it will run all the module methods. For example, you can't do:
|
583
880
|
|
584
881
|
```
|
585
|
-
$ ruby
|
882
|
+
$ ruby exe/linuxstat.rb upc
|
586
883
|
```
|
587
884
|
This is not a valid module and can't be run.
|
588
885
|
|