linux_stat 0.3.1 → 0.5.2

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: 1c68e104d55d755cd1cef1e8901a7dd67b1a901b132d9a7786fabfd75b41cf5a
4
+ data.tar.gz: 94d102c6244b8da52b5f7aa7b1ea903546b5ef6e615c6317233b510005b6ded7
5
5
  SHA512:
6
- metadata.gz: 580b5af4a00f4b2078e2d7cf9e249ba9648a5ab5965fe26c15f73c0cb843eeae6470e00d28fb096100f7b5445e47fcdce354c713c3aff4139fcb8a53221d68f0
7
- data.tar.gz: 6ebaa17fd1aaf45910a297df8b992e495e3f8c594c2b69181bdd1c9536bb2be40a8ad4fb569f4be076aac1eaf70fc0d86d7930eedde79615db6ffcfcb498dc50
6
+ metadata.gz: b94d6afea3d307c845f316ce21f66e93944e1b33ad9576ecd8d55e299d6d520732677f99ea8fba3dcb3f6f5c6c8aae98526cc21b2c0218d7a8d49bdd7896cdec
7
+ data.tar.gz: cecbaee79f9844c5a6ad83720071a7977697edeb958d2336a68fa9f3b19ccb28074641c9620c88574dd0b5074ba6069a3457543a2cad86c11d9c5562d6e83da6
@@ -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
- ![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:
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
- => [1998722, 1998401, 1974377, 1875264]
106
+ => [2000050, 2000024, 1998134, 1975870]
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=>3.57, 1=>0.0, 2=>0.0, 3=>0.0, 4=>0.0}
112
116
 
113
117
  LinuxStat::CPU.total_usage
114
118
  => 3.45
115
119
 
116
120
  LinuxStat::CPU.usage
117
- => 6.45
121
+ => 9.68
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=>6.67, 1=>0.0, 2=>25.0, 3=>12.5, 4=>14.29}
121
125
 
122
126
  ```
123
127
 
124
128
  ### LinuxStat::Filesystem
125
129
  ```
126
130
  LinuxStat::Filesystem.available
127
- => 43155402752
131
+ => 36234563584
128
132
 
129
133
  LinuxStat::Filesystem.free
130
- => 43155402752
134
+ => 36234563584
131
135
 
132
136
  LinuxStat::Filesystem.stat
133
- => {:total=>119981191168, :free=>43155402752, :used=>76825788416}
137
+ => {:total=>119981191168, :free=>36234563584, :used=>83746627584}
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=>8846329, :block_avail_unpriv=>8846329, :inodes=>58612160, :free_inodes=>56635312, :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
+ => 83746627584
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
+ => 602148
175
188
 
176
189
  LinuxStat::Memory.percent_available
177
- => 10.52
190
+ => 15.7
178
191
 
179
192
  LinuxStat::Memory.percent_used
180
- => 89.48
193
+ => 84.3
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=>3234108, :available=>602148, :percent_used=>84.3, :percent_available=>15.7}
184
197
 
185
198
  LinuxStat::Memory.total
186
- => 3836264
199
+ => 3836256
187
200
 
188
201
  LinuxStat::Memory.used
189
- => 3432540
202
+ => 3234108
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.43.107"
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=>15, :minute=>19, :second=>34.72}
238
257
 
239
258
  ```
240
259
 
241
260
  ### LinuxStat::Process
242
261
  ```
243
262
  LinuxStat::Process.count
244
- => 210
263
+ => 228
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, 119, 121, 131, 134, 140, 152, 153, 174, 176, 178, 182, 183, 187, 188, 189, 190, 191, 192, 225, 231, 280, 327, 329, 335, 5823, 5824, 5825, 5826, 5827, 5828, 43047, 4...
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, 119, 121, 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
+ => [49287]
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, 173, 175, 193, 219, 235, 301, 312, 313, 315, 326, 328, 340, 363, 364, 365, 366, 373, 376, 378, 381, 395,...
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,33 +285,368 @@ LinuxStat::Process.zombie
266
285
 
267
286
  ```
268
287
 
288
+ ### LinuxStat::ProcessInfo
289
+ ```
290
+ LinuxStat::ProcessInfo.cmdline
291
+ => "/usr/bin/ruby /home/sourav/.gem/ruby/2.7.0/bin/linuxstat.rb --html -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=>3}
298
+
299
+ LinuxStat::ProcessInfo.cpu_usage
300
+ => 0.0
301
+
302
+ LinuxStat::ProcessInfo.last_executed_cpu
303
+ => 3
304
+
305
+ LinuxStat::ProcessInfo.mem_stat
306
+ => {:memory=>11748, :virtual_memory=>81680, :resident_memory=>17928}
307
+
308
+ LinuxStat::ProcessInfo.memory
309
+ => 11748
310
+
311
+ LinuxStat::ProcessInfo.resident_memory
312
+ => 17928
313
+
314
+ LinuxStat::ProcessInfo.threads
315
+ => 1
316
+
317
+ LinuxStat::ProcessInfo.total_io
318
+ => {:read_bytes=>3932160, :write_bytes=>0}
319
+
320
+ LinuxStat::ProcessInfo.virtual_memory
321
+ => 81680
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
+ => 3358184
276
332
 
277
333
  LinuxStat::Swap.list
278
- => {"/dev/zram0"=>[:partition, 4194300, 2280364, -2]}
334
+ => {"/dev/zram0"=>[:partition, 4194300, 836116, -2]}
279
335
 
280
336
  LinuxStat::Swap.percent_available
281
- => 45.63
337
+ => 80.07
282
338
 
283
339
  LinuxStat::Swap.percent_used
284
- => 54.37
340
+ => 19.93
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=>836116, :available=>3358184, :percent_used=>19.93, :percent_available=>80.07}
288
344
 
289
345
  LinuxStat::Swap.total
290
346
  => 4194300
291
347
 
292
348
  LinuxStat::Swap.used
293
- => 2280364
349
+ => 836116
350
+
351
+ ```
352
+
353
+ ### LinuxStat::Sysconf
354
+ ```
355
+ LinuxStat::Sysconf.child_max
356
+ => 2000000
357
+
358
+ LinuxStat::Sysconf.get_euid
359
+ => 1000
360
+
361
+ LinuxStat::Sysconf.get_gid
362
+ => 1000
363
+
364
+ LinuxStat::Sysconf.get_login
365
+ => "sourav"
366
+
367
+ LinuxStat::Sysconf.get_uid
368
+ => 1000
369
+
370
+ LinuxStat::Sysconf.get_user
371
+ => "sourav"
372
+
373
+ LinuxStat::Sysconf.hostname_max
374
+ => 64
375
+
376
+ LinuxStat::Sysconf.login_name_max
377
+ => 256
378
+
379
+ LinuxStat::Sysconf.open_max
380
+ => 1024
381
+
382
+ LinuxStat::Sysconf.page_size_max
383
+ => 4096
384
+
385
+ LinuxStat::Sysconf.posix_version
386
+ => 200809
387
+
388
+ LinuxStat::Sysconf.sc_clk_tck
389
+ => 100
390
+
391
+ LinuxStat::Sysconf.stream_max
392
+ => 16
393
+
394
+ LinuxStat::Sysconf.tty_name_max
395
+ => 32
396
+
397
+ ```
398
+
399
+ ### LinuxStat::Uname
400
+ ```
401
+ LinuxStat::Uname.machine
402
+ => "x86_64"
403
+
404
+ LinuxStat::Uname.nodename
405
+ => "archlinux"
406
+
407
+ LinuxStat::Uname.release
408
+ => "5.9.1-xanmod1-1"
409
+
410
+ LinuxStat::Uname.sysname
411
+ => "Linux"
412
+
413
+ LinuxStat::Uname.version
414
+ => "#1 SMP PREEMPT Wed, 21 Oct 2020 01:11:20 +0000"
415
+
416
+ ```
417
+
418
+ ### LinuxStat::User
419
+ ```
420
+ LinuxStat::User.get_euid
421
+ => 1000
422
+
423
+ LinuxStat::User.get_gid
424
+ => 1000
425
+
426
+ LinuxStat::User.get_uid
427
+ => 1000
428
+
429
+ LinuxStat::User.get_user
430
+ => "sourav"
431
+
432
+ LinuxStat::User.gid_by_username
433
+ => 1000
434
+
435
+ LinuxStat::User.gids
436
+ => {: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, :...
437
+
438
+ LinuxStat::User.home_by_gid
439
+ => "/home/sourav"
440
+
441
+ LinuxStat::User.home_by_username
442
+ => "/home/sourav"
443
+
444
+ LinuxStat::User.home_directories
445
+ => {: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...
446
+
447
+ LinuxStat::User.homes_by_uid
448
+ => ["/home/sourav"]
449
+
450
+ LinuxStat::User.ids
451
+ => {: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...
452
+
453
+ LinuxStat::User.list
454
+ => ["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...
455
+
456
+ LinuxStat::User.uid_by_username
457
+ => 1000
458
+
459
+ LinuxStat::User.uids
460
+ => {: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...
461
+
462
+ LinuxStat::User.username_by_gid
463
+ => "sourav"
464
+
465
+ LinuxStat::User.usernames_by_uid
466
+ => ["sourav"]
467
+
468
+ ```
469
+
470
+ ---
471
+
472
+ ## Note 1: Filesystem
473
+
474
+ Filesystem can take arguments. By default it's '/' or the root of the system...
475
+
476
+ But for the sake of example, to get the free disk space of /, you do:
477
+
478
+ ```
479
+ $ irb
480
+ irb(main):001:0> require 'linux_stat'
481
+ => true
482
+
483
+ irb(main):002:0> LinuxStat::Filesystem.free('/').fdiv(1024 ** 3).to_s << " GiB"
484
+ => "35.666873931884766 GiB"
485
+ ```
486
+
487
+ To see the free and total space of a thumbdrive:
488
+
489
+ ```
490
+ $ irb
491
+ irb(main):001:0> require 'linux_stat'
492
+ => true
493
+
494
+ irb(main):002:0> LinuxStat::Mounts.list.find { |x| x.include?('/run/media/sourav') }.split[1]
495
+ => "/run/media/sourav/5c2b7af7-d4c3-4ab4-a035-06d18ffc8e6f"
496
+
497
+ irb(main):003:0> thumbdrive = _
498
+ => "/run/media/sourav/5c2b7af7-d4c3-4ab4-a035-06d18ffc8e6f"
499
+
500
+ irb(main):004:0> LinuxStat::Filesystem.free(thumbdrive).fdiv(1024 ** 3).to_s << " GiB"
501
+ => "2.504791259765625 GiB"
502
+
503
+ irb(main):005:0> LinuxStat::Filesystem.total(thumbdrive).fdiv(1024 ** 3).to_s << " GiB"
504
+ => "29.305004119873047 GiB"
505
+ ```
506
+
507
+ ## Note 2: ProcessInfo
508
+
509
+ All the methods LinuxStat::ProcessInfo can take an argument containing the Process ID of a process.
510
+ By default it's $$ or the PID of the current process, ruby, itself.
511
+
512
+ Example:
513
+ 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):
514
+
515
+ 1. Get the PID of Firefox:
516
+ ```
517
+ LinuxStat::Process.names.find { |x| x[1].include? 'firefox' }[0]
518
+ => 770 # but this differs all the time
519
+ ```
520
+
521
+ 2. Get the CPU usage:
522
+ ```
523
+ $ irb
524
+ irb(main):001:0> require 'linux_stat'
525
+ => true
526
+
527
+ irb(main):002:0> pid = LinuxStat::Process.names.find { |x| x[1].include? 'firefox' }[0]
528
+ => 770
529
+
530
+ irb(main):003:0> LinuxStat::ProcessInfo.cpu_usage(pid: pid)
531
+ => 0.0
532
+
533
+ irb(main):004:0> LinuxStat::ProcessInfo.cpu_usage(pid: pid)
534
+ => 15.0
535
+ ```
536
+
537
+ To get the memory usage of Firefox (for example):
294
538
 
295
539
  ```
540
+ $ irb
541
+ irb(main):001:0> require 'linux_stat'
542
+ => true
543
+
544
+ irb(main):002:0> LinuxStat::ProcessInfo.mem_stat(LinuxStat::Process.names.find { |x| x[1].include? 'firefox'.freeze }[0])
545
+ => {:memory=>468472, :virtual_memory=>4754080, :resident_memory=>814388}
546
+ ```
547
+
548
+ To get ONLY the memory usage in MiB:
549
+
550
+ ```
551
+ $ irb
552
+ irb(main):001:0> require 'linux_stat'
553
+ => true
554
+
555
+ 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"
556
+ => "467.51 MiB"
557
+ ```
558
+
559
+ ## Note 3: FS
560
+
561
+ LinuxStat::FS module gives you the raw info in Hash collected from statvfs.
562
+
563
+ 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.
564
+
565
+ It always requires an argument, and it's very fast. It directly calls the C API without any intermediate Ruby code.
566
+
567
+ For example, to get the info about '/' or root:
568
+
569
+ ```
570
+ $ irb
571
+ irb(main):001:0> require 'linux_stat'
572
+ => true
573
+
574
+ irb(main):002:0> LinuxStat::FS.stat('/')
575
+ => {: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}
576
+
577
+ irb(main):003:0> t = Time.now ; puts LinuxStat::FS.stat('/') ; Time.now - t
578
+ {: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}
579
+ => 5.0468e-05
580
+ ```
581
+
582
+ To learn more about them, just run ri and the method name. To see all available methods.
583
+
584
+ ## Note 4: User
585
+ Most of the LinuxStat::User supports arguments.
586
+
587
+ For example, to get a user's home by the username:
588
+
589
+ ```
590
+ $ irb
591
+ irb(main):001:0> require 'linux_stat'
592
+ => true
593
+
594
+ irb(main):002:0> LinuxStat::User.home_by_username('root')
595
+ => "/root"
596
+
597
+ irb(main):003:0> LinuxStat::User.home_by_username('ftp')
598
+ => "/srv/ftp"
599
+
600
+ irb(main):004:0> LinuxStat::User.home_by_username('mail')
601
+ => "/var/spool/mail"
602
+ ```
603
+
604
+ Or to get the user's home by the GID/UID:
605
+
606
+ ```
607
+ $ irb
608
+ irb(main):001:0> require 'linux_stat'
609
+ => true
610
+
611
+ irb(main):002:0> LinuxStat::User.homes_by_uid(1001)
612
+ => ["/home/userx", "/home/userz"]
613
+
614
+ irb(main):003:0> LinuxStat::User.homes_by_uid(1000)
615
+ => ["/home/sourav"]
616
+
617
+ irb(main):004:0> LinuxStat::User.home_by_gid(1001)
618
+ => "/home/userx"
619
+
620
+ irb(main):005:0> LinuxStat::User.home_by_gid(1000)
621
+ => "/home/sourav"
622
+
623
+ irb(main):006:0> LinuxStat::User.home_by_gid(0)
624
+ => "/root"
625
+ ```
626
+
627
+ Or to get the UID/GID by username:
628
+
629
+ ```
630
+ $ irb
631
+ irb(main):001:0> require 'linux_stat'
632
+ => true
633
+
634
+ irb(main):002:0> LinuxStat::User.uid_by_username('root')
635
+ => 0
636
+
637
+ irb(main):003:0> LinuxStat::User.uid_by_username('ftp')
638
+ => 14
639
+
640
+ irb(main):004:0> LinuxStat::User.gid_by_username('ftp')
641
+ => 11
642
+
643
+ irb(main):005:0> LinuxStat::User.gid_by_username('InvalidUser')
644
+ => nil
645
+ ```
646
+
647
+ Read the ri documentation for more info.
648
+
649
+ ---
296
650
 
297
651
  ## Return Types
298
652
  + 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.
@@ -307,55 +661,78 @@ LinuxStat::Swap.used
307
661
 
308
662
  If some error is *raised* it should be reported as a bug.
309
663
 
664
+ ---
665
+
310
666
  ## Ruby on Rails
311
667
 
312
668
  1. Just add `gem linux_stat`:
313
669
 
314
670
  ```
315
- bundle add linux_stat
671
+ $ bundle add linux_stat
316
672
  ```
317
673
 
318
674
  You can use LinuxStat directly in rails.
319
675
 
320
- ![RailsApp](https://raw.githubusercontent.com/Souravgoswami/linux_stat/master/logo/rails.gif)
676
+ ![RailsApp](https://raw.githubusercontent.com/Souravgoswami/linux_stat/master/images/rails.gif)
321
677
 
322
- Don't need to worry about versions if you are using anything > 0.2.1.
678
+ ---
323
679
 
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.
680
+ ## Android
325
681
 
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.
682
+ LinuxStat does support Android OS. But it's not rigorously tested on all device like android apps.
683
+
684
+ But in Termux you can just run LinuxStat without facing issues.
685
+ 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.
686
+
687
+ ![termux](https://raw.githubusercontent.com/Souravgoswami/linux_stat/master/images/termux.webp)
688
+
689
+ Issues regarding running LinuxStat on termux are also welcomed.
690
+
691
+ ---
327
692
 
328
693
  ## Development
694
+ After checking out the repo, compile and install this gem onto your local machine with `bundle exec rake install`
695
+
696
+ You can also run `bin/console` for an interactive prompt that will allow you to experiment.
329
697
 
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.
698
+ To test all modules, run `rake install` and then `exe/linuxstat.rb`. Also check "Testing" below.
331
699
 
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).
700
+ ---
333
701
 
334
702
  ## Testing
335
- Like other gems, this doesn't have a test like RSpec. We suggest using the bin/linuxstat.rb file on various systems.
703
+ Like other gems, this doesn't have a test like RSpec.
704
+
705
+ We suggest using the exe/linuxstat.rb file on various Linux systems to test.
706
+
707
+ First you need to execute `bundle exec rake install` to compile and install this gem.
708
+
336
709
  If you need to test a specific module, say the CPU, just run it like this:
337
710
 
338
711
  ```
339
- $ ruby bin/linuxstat.rb CPU
712
+ $ ruby exe/linuxstat.rb CPU
340
713
  ```
341
714
 
342
715
  Or:
343
716
  ```
344
- $ ruby bin/linuxstat.rb cpu
717
+ $ ruby exe/linuxstat.rb cpu
345
718
  ```
346
719
 
347
720
  That is, the argument passed is not case-sensitive.
348
721
  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
722
 
350
723
  ```
351
- $ ruby bin/linuxstat.rb upc
724
+ $ ruby exe/linuxstat.rb upc
352
725
  ```
353
726
  This is not a valid module and can't be run.
354
727
 
728
+ ---
729
+
355
730
  ## Contributing
356
731
 
357
732
  Bug reports and pull requests are welcome on GitHub at https://github.com/Souravgoswami/linux_stat.
358
733
 
734
+ ---
735
+
359
736
  ## License
360
737
 
361
738
  The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).