linux_stat 0.3.1 → 0.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 918383341aa375e1414e08c13b38829373caa174c64769541955180ce9d6e09c
4
- data.tar.gz: b821c81eee9bf5c9061057ab653e336adbbeaacf51d9b4141e6a1d72073058b6
3
+ metadata.gz: 349ddabe649c7cdec58e01537c6c28ab47f9d30b413208baf5fae4c0c7a26804
4
+ data.tar.gz: e66ba391b2264c53f6d2619ee64d8907e5435079b29bcc76bf2d54516ea82949
5
5
  SHA512:
6
- metadata.gz: 580b5af4a00f4b2078e2d7cf9e249ba9648a5ab5965fe26c15f73c0cb843eeae6470e00d28fb096100f7b5445e47fcdce354c713c3aff4139fcb8a53221d68f0
7
- data.tar.gz: 6ebaa17fd1aaf45910a297df8b992e495e3f8c594c2b69181bdd1c9536bb2be40a8ad4fb569f4be076aac1eaf70fc0d86d7930eedde79615db6ffcfcb498dc50
6
+ metadata.gz: 1f7274982f6330ed5023b6e7adf33f325163e382c9fdc81be8181c65ad182ba1e77433af792e1167d603673af147ff7e0601a42975f25ac2393206db755a27f5
7
+ data.tar.gz: 61d48ba5bcf4598d8df63173bfbecfe4fd6a91552f32195a540e344961ee4e2ebcb9decf492d092b41ca034908b82948b9e6d727e678e3b41f434c5771794070
@@ -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,12 +1,14 @@
1
1
  # LinuxStat
2
- ![logo](https://raw.githubusercontent.com/Souravgoswami/linux_stat/master/logo/logo.jpg)
2
+ ![logo](https://raw.githubusercontent.com/Souravgoswami/linux_stat/master/images/logo.jpg)
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:
@@ -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
- => [1998722, 1998401, 1974377, 1875264]
106
+ => [1999998, 2000003, 2000015, 2000009]
103
107
 
104
108
  LinuxStat::CPU.max_freq
105
109
  => [2000000, 2000000, 2000000, 2000000]
@@ -108,38 +112,38 @@ LinuxStat::CPU.model
108
112
  => "Intel(R) Core(TM) i3-6006U CPU @ 2.00GHz"
109
113
 
110
114
  LinuxStat::CPU.stat
111
- => {0=>6.45, 1=>0.0, 2=>0.0, 3=>12.5, 4=>0.0}
115
+ => {0=>14.29, 1=>25.0, 2=>0.0, 3=>25.0, 4=>14.29}
112
116
 
113
117
  LinuxStat::CPU.total_usage
114
- => 3.45
118
+ => 18.75
115
119
 
116
120
  LinuxStat::CPU.usage
117
- => 6.45
121
+ => 14.29
118
122
 
119
123
  LinuxStat::CPU.usages
120
- => {0=>9.68, 1=>11.11, 2=>12.5, 3=>14.29, 4=>12.5}
124
+ => {0=>16.67, 1=>14.29, 2=>28.57, 3=>0.0, 4=>25.0}
121
125
 
122
126
  ```
123
127
 
124
128
  ### LinuxStat::Filesystem
125
129
  ```
126
130
  LinuxStat::Filesystem.available
127
- => 43155402752
131
+ => 42144575488
128
132
 
129
133
  LinuxStat::Filesystem.free
130
- => 43155402752
134
+ => 42144575488
131
135
 
132
136
  LinuxStat::Filesystem.stat
133
- => {:total=>119981191168, :free=>43155402752, :used=>76825788416}
137
+ => {:total=>119981191168, :free=>42144575488, :used=>77836615680}
134
138
 
135
139
  LinuxStat::Filesystem.stat_raw
136
- => {:block_size=>4096, :fragment_size=>4096, :blocks=>29292283, :block_free=>10535987, :block_avail_unpriv=>10535987, :inodes=>58612160, :free_inodes=>56718515, :filesystem_id=>2050, :mount_flags=>1024, :max_filename_length=>255}
140
+ => {:block_size=>4096, :fragment_size=>4096, :blocks=>29292283, :block_free=>10289203, :block_avail_unpriv=>10289203, :inodes=>58612160, :free_inodes=>56716465, :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
- => 76825788416
146
+ => 77836615680
143
147
 
144
148
  ```
145
149
 
@@ -154,15 +158,24 @@ LinuxStat::Kernel.build_date_string
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.1-xanmod1-1"
172
+
163
173
  LinuxStat::Kernel.string
164
174
  => "Linux version 5.9.1-xanmod1-1 (souravgoswami@archlinux) (gcc (GCC) 10.2.0, GNU ld (GNU Binutils) 2.35.1) #1 SMP PREEMPT Wed, 21 Oct 2020 01:11:20 +0000"
165
175
 
176
+ LinuxStat::Kernel.ticks
177
+ => 100
178
+
166
179
  LinuxStat::Kernel.version
167
180
  => "5.9.1-xanmod1-1"
168
181
 
@@ -171,29 +184,29 @@ LinuxStat::Kernel.version
171
184
  ### LinuxStat::Memory
172
185
  ```
173
186
  LinuxStat::Memory.available
174
- => 403724
187
+ => 606548
175
188
 
176
189
  LinuxStat::Memory.percent_available
177
- => 10.52
190
+ => 15.81
178
191
 
179
192
  LinuxStat::Memory.percent_used
180
- => 89.48
193
+ => 84.19
181
194
 
182
195
  LinuxStat::Memory.stat
183
- => {:total=>3836264, :used=>3432540, :available=>403724, :percent_used=>89.48, :percent_available=>10.52}
196
+ => {:total=>3836256, :used=>3229708, :available=>606548, :percent_used=>84.19, :percent_available=>15.81}
184
197
 
185
198
  LinuxStat::Memory.total
186
- => 3836264
199
+ => 3836256
187
200
 
188
201
  LinuxStat::Memory.used
189
- => 3432540
202
+ => 3229708
190
203
 
191
204
  ```
192
205
 
193
206
  ### LinuxStat::Mounts
194
207
  ```
195
208
  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=1891796k,nr_inodes=472949,mode=755 0 0", "run /run tmpfs rw,nosuid,nodev,relatime,mode=755 0 0", "...
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=1891804k,nr_inodes=472951,mode=755 0 0", "run /run tmpfs rw,nosuid,nodev,relatime,mode=755 0 0", "...
197
210
 
198
211
  LinuxStat::Mounts.root
199
212
  => "/dev/sda2"
@@ -205,14 +218,14 @@ LinuxStat::Mounts.root_mount_options
205
218
  => "rw,noatime,attr2,inode64,logbufs=8,logbsize=32k,noquota"
206
219
 
207
220
  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", "/ramdisk"=>"tmpfs /ramdisk tmpfs rw,nosuid,nodev,relatime,size=6291456k 0 0", "/tmp...
221
+ => {"/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
222
 
210
223
  ```
211
224
 
212
225
  ### LinuxStat::Net
213
226
  ```
214
227
  LinuxStat::Net.ipv4_private
215
- => "192.168.0.106"
228
+ => "192.168.0.101"
216
229
 
217
230
  ```
218
231
 
@@ -230,33 +243,39 @@ LinuxStat::OS.hostname
230
243
  LinuxStat::OS.lsb_release
231
244
  => {:LSB_VERSION=>"1.4", :DISTRIB_ID=>"Arch", :DISTRIB_RELEASE=>"rolling", :DISTRIB_DESCRIPTION=>"Arch Linux"}
232
245
 
246
+ LinuxStat::OS.machine
247
+ => "x86_64"
248
+
249
+ LinuxStat::OS.nodename
250
+ => "archlinux"
251
+
233
252
  LinuxStat::OS.os_release
234
253
  => {: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
254
 
236
255
  LinuxStat::OS.uptime
237
- => {:hour=>10, :minute=>54, :second=>22.45}
256
+ => {:hour=>9, :minute=>10, :second=>19.41}
238
257
 
239
258
  ```
240
259
 
241
260
  ### LinuxStat::Process
242
261
  ```
243
262
  LinuxStat::Process.count
244
- => 210
263
+ => 221
245
264
 
246
265
  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, 122, 131, 134, 140, 152, 153, 179, 181, 183, 184, 191, 192, 193, 194, 195, 196, 198, 236, 286, 314, 324, 346, 385, 3540, 3541, 3542, 3543, 3544, 3545, 30463, 3...
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, 168, 170, 173, 174, 182, 183, 184, 185, 186, 187, 214, 224, 268, 308, 313, 314, 330, 2357, 2358, 2359, 2360, 2361, 2362, 25094, 2...
248
267
 
249
268
  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, 122, 131, 134,...
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, 112, 114, 115, 117, 118, 120, 122, 131, 134,...
251
270
 
252
271
  LinuxStat::Process.names
253
- => {1=>"systemd", 2=>"kthreadd", 3=>"rcu_gp", 4=>"rcu_par_gp", 6=>"kworker/0:0H-events_highpri", 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...
272
+ => {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
273
 
255
274
  LinuxStat::Process.running
256
- => [33736]
275
+ => [30804]
257
276
 
258
277
  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, 178, 180, 197, 225, 239, 309, 317, 329, 332, 333, 334, 338, 367, 368, 369, 370, 378, 381, 383, 384, 402,...
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, 112, 114, 115, 167, 169, 188, 215, 228, 307, 309, 311, 316, 317, 319, 320, 354, 355, 356, 357, 364, 368, 370, 384, 397,...
260
279
 
261
280
  LinuxStat::Process.types
262
281
  => {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 +285,354 @@ LinuxStat::Process.zombie
266
285
 
267
286
  ```
268
287
 
288
+ ### LinuxStat::ProcessInfo
289
+ ```
290
+ LinuxStat::ProcessInfo.cmdline
291
+ => "ruby exe/linuxstat.rb -md"
292
+
293
+ LinuxStat::ProcessInfo.command_name
294
+ => "ruby"
295
+
296
+ LinuxStat::ProcessInfo.cpu_stat
297
+ => {:cpu_usage=>0.0, :threads=>1, :last_executed_cpu=>2}
298
+
299
+ LinuxStat::ProcessInfo.cpu_usage
300
+ => 0.0
301
+
302
+ LinuxStat::ProcessInfo.last_executed_cpu
303
+ => 2
304
+
305
+ LinuxStat::ProcessInfo.mem_stat
306
+ => {:memory=>9644, :virtual_memory=>79568, :resident_memory=>15764}
307
+
308
+ LinuxStat::ProcessInfo.memory
309
+ => 9644
310
+
311
+ LinuxStat::ProcessInfo.resident_memory
312
+ => 15764
313
+
314
+ LinuxStat::ProcessInfo.threads
315
+ => 1
316
+
317
+ LinuxStat::ProcessInfo.total_io
318
+ => {:read_bytes=>0, :write_bytes=>0}
319
+
320
+ LinuxStat::ProcessInfo.virtual_memory
321
+ => 79568
322
+
323
+ ```
324
+
269
325
  ### LinuxStat::Swap
270
326
  ```
271
327
  LinuxStat::Swap.any?
272
328
  => true
273
329
 
274
330
  LinuxStat::Swap.available
275
- => 1913936
331
+ => 2256212
276
332
 
277
333
  LinuxStat::Swap.list
278
- => {"/dev/zram0"=>[:partition, 4194300, 2280364, -2]}
334
+ => {"/dev/zram0"=>[:partition, 4194300, 1938088, -2]}
279
335
 
280
336
  LinuxStat::Swap.percent_available
281
- => 45.63
337
+ => 53.79
282
338
 
283
339
  LinuxStat::Swap.percent_used
284
- => 54.37
340
+ => 46.21
285
341
 
286
342
  LinuxStat::Swap.stat
287
- => {:total=>4194300, :used=>2280364, :available=>1913936, :percent_used=>54.37, :percent_available=>45.63}
343
+ => {:total=>4194300, :used=>1938088, :available=>2256212, :percent_used=>46.21, :percent_available=>53.79}
288
344
 
289
345
  LinuxStat::Swap.total
290
346
  => 4194300
291
347
 
292
348
  LinuxStat::Swap.used
293
- => 2280364
349
+ => 1938088
350
+
351
+ ```
352
+
353
+ ### LinuxStat::Sysconf
354
+ ```
355
+ LinuxStat::Sysconf.child_max
356
+ => 2000000
357
+
358
+ LinuxStat::Sysconf.hostname_max
359
+ => 64
360
+
361
+ LinuxStat::Sysconf.login_name_max
362
+ => 256
363
+
364
+ LinuxStat::Sysconf.open_max
365
+ => 8192
366
+
367
+ LinuxStat::Sysconf.page_size_max
368
+ => 4096
369
+
370
+ LinuxStat::Sysconf.posix_version
371
+ => 200809
372
+
373
+ LinuxStat::Sysconf.sc_clk_tck
374
+ => 100
375
+
376
+ LinuxStat::Sysconf.stream_max
377
+ => 16
378
+
379
+ LinuxStat::Sysconf.tty_name_max
380
+ => 32
294
381
 
295
382
  ```
296
383
 
384
+ ### LinuxStat::Uname
385
+ ```
386
+ LinuxStat::Uname.machine
387
+ => "x86_64"
388
+
389
+ LinuxStat::Uname.nodename
390
+ => "archlinux"
391
+
392
+ LinuxStat::Uname.release
393
+ => "5.9.1-xanmod1-1"
394
+
395
+ LinuxStat::Uname.sysname
396
+ => "Linux"
397
+
398
+ LinuxStat::Uname.version
399
+ => "#1 SMP PREEMPT Wed, 21 Oct 2020 01:11:20 +0000"
400
+
401
+ ```
402
+
403
+ ### LinuxStat::User
404
+ ```
405
+ LinuxStat::User.get_euid
406
+ => 1000
407
+
408
+ LinuxStat::User.get_gid
409
+ => 1000
410
+
411
+ LinuxStat::User.get_uid
412
+ => 1000
413
+
414
+ LinuxStat::User.get_user
415
+ => "sourav"
416
+
417
+ LinuxStat::User.gid_by_username
418
+ => 1000
419
+
420
+ LinuxStat::User.gids
421
+ => {: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, :...
422
+
423
+ LinuxStat::User.home_by_gid
424
+ => "/home/sourav"
425
+
426
+ LinuxStat::User.home_by_username
427
+ => "/home/sourav"
428
+
429
+ LinuxStat::User.home_directories
430
+ => {: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...
431
+
432
+ LinuxStat::User.homes_by_uid
433
+ => ["/home/sourav"]
434
+
435
+ LinuxStat::User.ids
436
+ => {: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...
437
+
438
+ LinuxStat::User.list
439
+ => ["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...
440
+
441
+ LinuxStat::User.uid_by_username
442
+ => 1000
443
+
444
+ LinuxStat::User.uids
445
+ => {: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...
446
+
447
+ LinuxStat::User.username_by_gid
448
+ => "sourav"
449
+
450
+ LinuxStat::User.usernames_by_uid
451
+ => ["sourav"]
452
+
453
+ ```
454
+
455
+ ---
456
+
457
+ ## Note 1: Filesystem
458
+
459
+ Filesystem can take arguments. By default it's '/' or the root of the system...
460
+
461
+ But for the sake of example, to get the free disk space of /, you do:
462
+
463
+ ```
464
+ $ irb
465
+ irb(main):001:0> require 'linux_stat'
466
+ => true
467
+
468
+ irb(main):002:0> LinuxStat::Filesystem.free('/').fdiv(1024 ** 3).to_s << " GiB"
469
+ => "35.666873931884766 GiB"
470
+ ```
471
+
472
+ To see the free and total space of a thumbdrive:
473
+
474
+ ```
475
+ $ irb
476
+ irb(main):001:0> require 'linux_stat'
477
+ => true
478
+
479
+ irb(main):002:0> LinuxStat::Mounts.list.find { |x| x.include?('/run/media/sourav') }.split[1]
480
+ => "/run/media/sourav/5c2b7af7-d4c3-4ab4-a035-06d18ffc8e6f"
481
+
482
+ irb(main):003:0> thumbdrive = _
483
+ => "/run/media/sourav/5c2b7af7-d4c3-4ab4-a035-06d18ffc8e6f"
484
+
485
+ irb(main):004:0> LinuxStat::Filesystem.free(thumbdrive).fdiv(1024 ** 3).to_s << " GiB"
486
+ => "2.504791259765625 GiB"
487
+
488
+ irb(main):005:0> LinuxStat::Filesystem.total(thumbdrive).fdiv(1024 ** 3).to_s << " GiB"
489
+ => "29.305004119873047 GiB"
490
+ ```
491
+
492
+ ## Note 2: ProcessInfo
493
+
494
+ All the methods LinuxStat::ProcessInfo can take an argument containing the Process ID of a process.
495
+ By default it's $$ or the PID of the current process, ruby, itself.
496
+
497
+ Example:
498
+ 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):
499
+
500
+ 1. Get the PID of Firefox:
501
+ ```
502
+ LinuxStat::Process.names.find { |x| x[1].include? 'firefox' }[0]
503
+ => 770 # but this differs all the time
504
+ ```
505
+
506
+ 2. Get the CPU usage:
507
+ ```
508
+ $ irb
509
+ irb(main):001:0> require 'linux_stat'
510
+ => true
511
+
512
+ irb(main):002:0> pid = LinuxStat::Process.names.find { |x| x[1].include? 'firefox' }[0]
513
+ => 770
514
+
515
+ irb(main):003:0> LinuxStat::ProcessInfo.cpu_usage(pid: pid)
516
+ => 0.0
517
+
518
+ irb(main):004:0> LinuxStat::ProcessInfo.cpu_usage(pid: pid)
519
+ => 15.0
520
+ ```
521
+
522
+ To get the memory usage of Firefox (for example):
523
+
524
+ ```
525
+ $ irb
526
+ irb(main):001:0> require 'linux_stat'
527
+ => true
528
+
529
+ irb(main):002:0> LinuxStat::ProcessInfo.mem_stat(LinuxStat::Process.names.find { |x| x[1].include? 'firefox'.freeze }[0])
530
+ => {:memory=>468472, :virtual_memory=>4754080, :resident_memory=>814388}
531
+ ```
532
+
533
+ To get ONLY the memory usage in MiB:
534
+
535
+ ```
536
+ $ irb
537
+ irb(main):001:0> require 'linux_stat'
538
+ => true
539
+
540
+ 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"
541
+ => "467.51 MiB"
542
+ ```
543
+
544
+ ## Note 3: FS
545
+
546
+ LinuxStat::FS module gives you the raw info in Hash collected from statvfs.
547
+
548
+ 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.
549
+
550
+ It always requires an argument, and it's very fast. It directly calls the C API without any intermediate Ruby code.
551
+
552
+ For example, to get the info about '/' or root:
553
+
554
+ ```
555
+ $ irb
556
+ irb(main):001:0> require 'linux_stat'
557
+ => true
558
+
559
+ irb(main):002:0> LinuxStat::FS.stat('/')
560
+ => {: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}
561
+
562
+ irb(main):003:0> t = Time.now ; puts LinuxStat::FS.stat('/') ; Time.now - t
563
+ {: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}
564
+ => 5.0468e-05
565
+ ```
566
+
567
+ To learn more about them, just run ri and the method name. To see all available methods:
568
+
569
+ ## Note 4: User
570
+ Most of the LinuxStat::User supports arguments.
571
+
572
+ For example, to get a user's home by the username:
573
+
574
+ ```
575
+ $ irb
576
+ irb(main):001:0> require 'linux_stat'
577
+ => true
578
+
579
+ irb(main):002:0> LinuxStat::User.home_by_username('root')
580
+ => "/root"
581
+
582
+ irb(main):003:0> LinuxStat::User.home_by_username('ftp')
583
+ => "/srv/ftp"
584
+
585
+ irb(main):004:0> LinuxStat::User.home_by_username('mail')
586
+ => "/var/spool/mail"
587
+ ```
588
+
589
+ Or to get the user's home by the GID/UID:
590
+
591
+ ```
592
+ $ irb
593
+ irb(main):001:0> require 'linux_stat'
594
+ => true
595
+
596
+ irb(main):002:0> LinuxStat::User.homes_by_uid(1001)
597
+ => ["/home/userx", "/home/userz"]
598
+
599
+ irb(main):003:0> LinuxStat::User.homes_by_uid(1000)
600
+ => ["/home/sourav"]
601
+
602
+ irb(main):004:0> LinuxStat::User.home_by_gid(1001)
603
+ => "/home/userx"
604
+
605
+ irb(main):005:0> LinuxStat::User.home_by_gid(1000)
606
+ => "/home/sourav"
607
+
608
+ irb(main):006:0> LinuxStat::User.home_by_gid(0)
609
+ => "/root"
610
+ ```
611
+
612
+ Or to get the UID/GID by username:
613
+
614
+ ```
615
+ $ irb
616
+ irb(main):001:0> require 'linux_stat'
617
+ => true
618
+
619
+ irb(main):002:0> LinuxStat::User.uid_by_username('root')
620
+ => 0
621
+
622
+ irb(main):003:0> LinuxStat::User.uid_by_username('ftp')
623
+ => 14
624
+
625
+ irb(main):004:0> LinuxStat::User.gid_by_username('ftp')
626
+ => 11
627
+
628
+ irb(main):005:0> LinuxStat::User.gid_by_username('InvalidUser')
629
+ => nil
630
+ ```
631
+
632
+ Read the ri documentation for more info.
633
+
634
+ ---
635
+
297
636
  ## Return Types
298
637
  + 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
638
 
@@ -307,55 +646,78 @@ LinuxStat::Swap.used
307
646
 
308
647
  If some error is *raised* it should be reported as a bug.
309
648
 
649
+ ---
650
+
310
651
  ## Ruby on Rails
311
652
 
312
653
  1. Just add `gem linux_stat`:
313
654
 
314
655
  ```
315
- bundle add linux_stat
656
+ $ bundle add linux_stat
316
657
  ```
317
658
 
318
659
  You can use LinuxStat directly in rails.
319
660
 
320
- ![RailsApp](https://raw.githubusercontent.com/Souravgoswami/linux_stat/master/logo/rails.gif)
661
+ ![RailsApp](https://raw.githubusercontent.com/Souravgoswami/linux_stat/master/images/rails.gif)
321
662
 
322
- Don't need to worry about versions if you are using anything > 0.2.1.
663
+ ---
323
664
 
324
- Newer versions will have bug fixes, performance improvements and new features but the return types of old methods will always be the same across upgrades > 0.2.1.
665
+ ## Android
325
666
 
326
- Even if we remove something, there will be always a deprecation warning for some months or for even a year before we actually remove it.
667
+ LinuxStat does support Android OS. But it's not rigorously tested on all device like android apps.
668
+
669
+ But in Termux you can just run LinuxStat without facing issues.
670
+ 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.
671
+
672
+ ![termux](https://raw.githubusercontent.com/Souravgoswami/linux_stat/master/images/termux.webp)
673
+
674
+ Issues regarding running LinuxStat on termux are also welcomed.
675
+
676
+ ---
327
677
 
328
678
  ## Development
679
+ After checking out the repo, compile and install this gem onto your local machine with `bundle exec rake install`
680
+
681
+ You can also run `bin/console` for an interactive prompt that will allow you to experiment.
329
682
 
330
- After checking out the repo, run `bin/setup` to install dependencies. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
683
+ To test all modules, run `rake install` and then `exe/linuxstat.rb`. Also check "Testing" below.
331
684
 
332
- To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
685
+ ---
333
686
 
334
687
  ## Testing
335
- Like other gems, this doesn't have a test like RSpec. We suggest using the bin/linuxstat.rb file on various systems.
688
+ Like other gems, this doesn't have a test like RSpec.
689
+
690
+ We suggest using the exe/linuxstat.rb file on various Linux systems to test.
691
+
692
+ First you need to execute `bundle exec rake install` to compile and install this gem.
693
+
336
694
  If you need to test a specific module, say the CPU, just run it like this:
337
695
 
338
696
  ```
339
- $ ruby bin/linuxstat.rb CPU
697
+ $ ruby exe/linuxstat.rb CPU
340
698
  ```
341
699
 
342
700
  Or:
343
701
  ```
344
- $ ruby bin/linuxstat.rb cpu
702
+ $ ruby exe/linuxstat.rb cpu
345
703
  ```
346
704
 
347
705
  That is, the argument passed is not case-sensitive.
348
706
  But if the argument passed isn't available and outright wrong, it will run all the module methods. For example, you can't do:
349
707
 
350
708
  ```
351
- $ ruby bin/linuxstat.rb upc
709
+ $ ruby exe/linuxstat.rb upc
352
710
  ```
353
711
  This is not a valid module and can't be run.
354
712
 
713
+ ---
714
+
355
715
  ## Contributing
356
716
 
357
717
  Bug reports and pull requests are welcome on GitHub at https://github.com/Souravgoswami/linux_stat.
358
718
 
719
+ ---
720
+
359
721
  ## License
360
722
 
361
723
  The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).