linux_stat 0.5.2 → 0.6.5

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: 1c68e104d55d755cd1cef1e8901a7dd67b1a901b132d9a7786fabfd75b41cf5a
4
- data.tar.gz: 94d102c6244b8da52b5f7aa7b1ea903546b5ef6e615c6317233b510005b6ded7
3
+ metadata.gz: 73b3180065620ed0fc96662eaa96fa9e7971176e7a5d19054ae1f10b3204987c
4
+ data.tar.gz: 4fb253f925728426bfad5764b97cc59b71771365e984e78478ff996d7e63378c
5
5
  SHA512:
6
- metadata.gz: b94d6afea3d307c845f316ce21f66e93944e1b33ad9576ecd8d55e299d6d520732677f99ea8fba3dcb3f6f5c6c8aae98526cc21b2c0218d7a8d49bdd7896cdec
7
- data.tar.gz: cecbaee79f9844c5a6ad83720071a7977697edeb958d2336a68fa9f3b19ccb28074641c9620c88574dd0b5074ba6069a3457543a2cad86c11d9c5562d6e83da6
6
+ metadata.gz: f4b2b9296a34fbb4415587a5f6752602a3eb35f2e7da6af38e9c76a9946e18a5a120b54901d61cd43d2e624612564cfddc50c330dee7b910a5eeb12ed0b34a73
7
+ data.tar.gz: 2753d9fe91b324f93ce59ea4abd3d84178f515b6e31053b1b382866089dc242f680533f3fded18c9840cbdd1679d7a81920cb87b563454c8423aa2dc3fe35307
data/README.md CHANGED
@@ -103,7 +103,7 @@ LinuxStat::CPU.count
103
103
  => 4
104
104
 
105
105
  LinuxStat::CPU.cur_freq
106
- => [2000050, 2000024, 1998134, 1975870]
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=>3.57, 1=>0.0, 2=>0.0, 3=>0.0, 4=>0.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
- => 3.45
118
+ => 0.0
119
119
 
120
120
  LinuxStat::CPU.usage
121
- => 9.68
121
+ => 20.0
122
122
 
123
123
  LinuxStat::CPU.usages
124
- => {0=>6.67, 1=>0.0, 2=>25.0, 3=>12.5, 4=>14.29}
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
- => 36234563584
131
+ => 33120964608
132
132
 
133
133
  LinuxStat::Filesystem.free
134
- => 36234563584
134
+ => 33120964608
135
135
 
136
136
  LinuxStat::Filesystem.stat
137
- => {:total=>119981191168, :free=>36234563584, :used=>83746627584}
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=>8846329, :block_avail_unpriv=>8846329, :inodes=>58612160, :free_inodes=>56635312, :filesystem_id=>2050, :mount_flags=>1024, :max_filename_length=>255}
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
- => 83746627584
146
+ => 86860226560
147
147
 
148
148
  ```
149
149
 
150
150
  ### LinuxStat::Kernel
151
151
  ```
152
152
  LinuxStat::Kernel.build_date
153
- => 2020-10-21 01:11:20 +0000
153
+ => 2020-11-20 07:44:55 +0000
154
154
 
155
155
  LinuxStat::Kernel.build_date_string
156
- => "21 Oct 2020 01:11:20 +0000"
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.1-xanmod1-1"
171
+ => "5.9.9-xanmod1-1"
172
172
 
173
173
  LinuxStat::Kernel.string
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"
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.1-xanmod1-1"
180
+ => "5.9.9-xanmod1-1"
181
181
 
182
182
  ```
183
183
 
184
184
  ### LinuxStat::Memory
185
185
  ```
186
186
  LinuxStat::Memory.available
187
- => 602148
187
+ => 579264
188
188
 
189
189
  LinuxStat::Memory.percent_available
190
- => 15.7
190
+ => 15.1
191
191
 
192
192
  LinuxStat::Memory.percent_used
193
- => 84.3
193
+ => 84.9
194
194
 
195
195
  LinuxStat::Memory.stat
196
- => {:total=>3836256, :used=>3234108, :available=>602148, :percent_used=>84.3, :percent_available=>15.7}
196
+ => {:total=>3836236, :used=>3256972, :available=>579264, :percent_used=>84.9, :percent_available=>15.1}
197
197
 
198
198
  LinuxStat::Memory.total
199
- => 3836256
199
+ => 3836236
200
200
 
201
201
  LinuxStat::Memory.used
202
- => 3234108
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=1891804k,nr_inodes=472951,mode=755 0 0", "run /run tmpfs rw,nosuid,nodev,relatime,mode=755 0 0", "...
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.43.107"
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=>15, :minute=>19, :second=>34.72}
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
- => 228
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, 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...
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, 112, 114, 115, 117, 118, 119, 121, 131, 134,...
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-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...
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
- => [49287]
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, 112, 114, 115, 173, 175, 193, 219, 235, 301, 312, 313, 315, 326, 328, 340, 363, 364, 365, 366, 373, 376, 378, 381, 395,...
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,37 +318,46 @@ LinuxStat::Process.zombie
288
318
  ### LinuxStat::ProcessInfo
289
319
  ```
290
320
  LinuxStat::ProcessInfo.cmdline
291
- => "/usr/bin/ruby /home/sourav/.gem/ruby/2.7.0/bin/linuxstat.rb --html -md"
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=>3}
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
- => 3
336
+ => 1
304
337
 
305
338
  LinuxStat::ProcessInfo.mem_stat
306
- => {:memory=>11748, :virtual_memory=>81680, :resident_memory=>17928}
339
+ => {:memory=>10051.584, :virtual_memory=>81801.216, :resident_memory=>15986.688}
307
340
 
308
341
  LinuxStat::ProcessInfo.memory
309
- => 11748
342
+ => 10051.584
343
+
344
+ LinuxStat::ProcessInfo.owner
345
+ => "sourav"
310
346
 
311
347
  LinuxStat::ProcessInfo.resident_memory
312
- => 17928
348
+ => 15986.688
313
349
 
314
350
  LinuxStat::ProcessInfo.threads
315
351
  => 1
316
352
 
317
353
  LinuxStat::ProcessInfo.total_io
318
- => {:read_bytes=>3932160, :write_bytes=>0}
354
+ => {:read_bytes=>0, :write_bytes=>0}
355
+
356
+ LinuxStat::ProcessInfo.uid
357
+ => {:real=>1000, :effective=>1000, :saved_set=>1000, :filesystem_uid=>1000}
319
358
 
320
359
  LinuxStat::ProcessInfo.virtual_memory
321
- => 81680
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
- => 3358184
370
+ => 3383720
332
371
 
333
372
  LinuxStat::Swap.list
334
- => {"/dev/zram0"=>[:partition, 4194300, 836116, -2]}
373
+ => {"/dev/zram0"=>[:partition, 4194300, 810580, -2]}
335
374
 
336
375
  LinuxStat::Swap.percent_available
337
- => 80.07
376
+ => 80.67
338
377
 
339
378
  LinuxStat::Swap.percent_used
340
- => 19.93
379
+ => 19.33
341
380
 
342
381
  LinuxStat::Swap.stat
343
- => {:total=>4194300, :used=>836116, :available=>3358184, :percent_used=>19.93, :percent_available=>80.07}
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
- => 836116
388
+ => 810580
350
389
 
351
390
  ```
352
391
 
@@ -379,7 +418,7 @@ LinuxStat::Sysconf.login_name_max
379
418
  LinuxStat::Sysconf.open_max
380
419
  => 1024
381
420
 
382
- LinuxStat::Sysconf.page_size_max
421
+ LinuxStat::Sysconf.pagesize
383
422
  => 4096
384
423
 
385
424
  LinuxStat::Sysconf.posix_version
@@ -405,24 +444,30 @@ LinuxStat::Uname.nodename
405
444
  => "archlinux"
406
445
 
407
446
  LinuxStat::Uname.release
408
- => "5.9.1-xanmod1-1"
447
+ => "5.9.9-xanmod1-1"
409
448
 
410
449
  LinuxStat::Uname.sysname
411
450
  => "Linux"
412
451
 
413
452
  LinuxStat::Uname.version
414
- => "#1 SMP PREEMPT Wed, 21 Oct 2020 01:11:20 +0000"
453
+ => "#1 SMP PREEMPT Fri, 20 Nov 2020 07:44:55 +0000"
415
454
 
416
455
  ```
417
456
 
418
457
  ### LinuxStat::User
419
458
  ```
459
+ LinuxStat::User.get_current_user
460
+ => "sourav"
461
+
420
462
  LinuxStat::User.get_euid
421
463
  => 1000
422
464
 
423
465
  LinuxStat::User.get_gid
424
466
  => 1000
425
467
 
468
+ LinuxStat::User.get_login
469
+ => "sourav"
470
+
426
471
  LinuxStat::User.get_uid
427
472
  => 1000
428
473
 
@@ -469,7 +514,71 @@ LinuxStat::User.usernames_by_uid
469
514
 
470
515
  ---
471
516
 
472
- ## Note 1: Filesystem
517
+ ## Note 1: CPU usage, and Net usage
518
+ To calculate the current usage, we need to get two usages at a given interval, and subtract the 2nd from the 1st.
519
+ For example, if the current download (`LinuxStat::Net.total_bytes_received`) is 1000 bytes, and if 0.1 seconds ago, it was 100 bytes, that means 900 bytes was received in 0.1 seconds.
520
+ That means the current speed is 9000 bytes/s or 9 kB/s.
521
+
522
+ Without the polling, it's not really possible to calculate the current usage. Although the total usage can be calculated.
523
+ A system monitor does that, too...
524
+
525
+ Thus these methods requires a polling interval:
526
+
527
+ 1. LinuxStat::CPU.stat, usage, total_usage, usage.
528
+ 2. LinuxStat::ProcessInfo.cpu_usage, cpu_stat.
529
+ 3. LinuxStat::Net.usage, current_usage.
530
+
531
+ They sleep for a given interval and then differentiate between the data.
532
+
533
+ For more info look at the ri documentation for the above methods.
534
+
535
+ These methods can slow down your application a bit unless you implement them in a thread.
536
+
537
+ Other methods doesn't have the sleep implemented, and they just works under a millisecond.
538
+
539
+ For example:
540
+
541
+ ```
542
+ LinuxStat::CPU.stat(0.1)
543
+ => {0=>7.69, 1=>0.0, 2=>0.0, 3=>18.18, 4=>10.0}
544
+ ```
545
+ This will sleep for 0.1 seconds. To be reliable, use a time like 0.05 seconds or so.
546
+
547
+ If you want to build a system monitor and don't want to wait, you have to do something like this:
548
+
549
+ ```
550
+ #!/usr/bin/ruby
551
+ require 'linux_stat'
552
+
553
+ usages = []
554
+ thread = Thread.new { }
555
+ counter = 0
556
+
557
+ while true
558
+ thread = Thread.new { usages = LinuxStat::CPU.usages(0.5).values } unless thread.alive?
559
+
560
+ # clears the screen and prints the info
561
+ puts "\e[2J\e[H\e[3J"\
562
+ "#{counter += 1}\n"\
563
+ "\e[1;33mTotal CPU Usage:\e[0m #{usages[0]}%\n"\
564
+ "#{usages[1..-1].to_a.map.with_index { |x, i| "\e[1;33mCore #{i}\e[0m => #{x}%\n" }.join}"\
565
+ "Total Download: #{LinuxStat::PrettifyBytes.convert_decimal LinuxStat::Net.total_bytes_received}\n"\
566
+ "Total Upload: #{LinuxStat::PrettifyBytes.convert_decimal LinuxStat::Net.total_bytes_transmitted}"
567
+ end
568
+ ```
569
+
570
+ This will not wait in every loop for 0.5 seconds, but it will not update the cpu usage in every loop either.
571
+ So what you will be seeing in the CPU usage in every 0.5 seconds interval.
572
+
573
+ You will also see the counter increases like crazy. Which means it's not getting waited for 0.5 seconds.
574
+
575
+ But the other methods doesn't have this delay, thus in this example,
576
+ you will be able see the "Total Download" and "Total Upload" in real time,
577
+ well as soon as the Linux kernel updates the data and ruby executes the loop.
578
+
579
+ Just run the linuxstat.rb command to test what method takes what time measured in microseconds.
580
+
581
+ ## Note 2: Filesystem
473
582
 
474
583
  Filesystem can take arguments. By default it's '/' or the root of the system...
475
584
 
@@ -491,7 +600,7 @@ $ irb
491
600
  irb(main):001:0> require 'linux_stat'
492
601
  => true
493
602
 
494
- irb(main):002:0> LinuxStat::Mounts.list.find { |x| x.include?('/run/media/sourav') }.split[1]
603
+ irb(main):002:0> LinuxStat::Mounts.mount_point('/dev/sdb1')
495
604
  => "/run/media/sourav/5c2b7af7-d4c3-4ab4-a035-06d18ffc8e6f"
496
605
 
497
606
  irb(main):003:0> thumbdrive = _
@@ -504,7 +613,7 @@ irb(main):005:0> LinuxStat::Filesystem.total(thumbdrive).fdiv(1024 ** 3).to_s <<
504
613
  => "29.305004119873047 GiB"
505
614
  ```
506
615
 
507
- ## Note 2: ProcessInfo
616
+ ## Note 3: ProcessInfo
508
617
 
509
618
  All the methods LinuxStat::ProcessInfo can take an argument containing the Process ID of a process.
510
619
  By default it's $$ or the PID of the current process, ruby, itself.
@@ -556,7 +665,7 @@ irb(main):002:0> LinuxStat::ProcessInfo.memory(LinuxStat::Process.names.find { |
556
665
  => "467.51 MiB"
557
666
  ```
558
667
 
559
- ## Note 3: FS
668
+ ## Note 4: FS
560
669
 
561
670
  LinuxStat::FS module gives you the raw info in Hash collected from statvfs.
562
671
 
@@ -581,7 +690,7 @@ irb(main):003:0> t = Time.now ; puts LinuxStat::FS.stat('/') ; Time.now - t
581
690
 
582
691
  To learn more about them, just run ri and the method name. To see all available methods.
583
692
 
584
- ## Note 4: User
693
+ ## Note 5: User
585
694
  Most of the LinuxStat::User supports arguments.
586
695
 
587
696
  For example, to get a user's home by the username:
@@ -627,7 +736,7 @@ irb(main):006:0> LinuxStat::User.home_by_gid(0)
627
736
  Or to get the UID/GID by username:
628
737
 
629
738
  ```
630
- $ irb
739
+ $ irb
631
740
  irb(main):001:0> require 'linux_stat'
632
741
  => true
633
742
 
@@ -644,6 +753,119 @@ irb(main):005:0> LinuxStat::User.gid_by_username('InvalidUser')
644
753
  => nil
645
754
  ```
646
755
 
756
+ Or to get the current user (in docker for example):
757
+
758
+ ```
759
+ $ irb
760
+ irb(main):001:0> require 'linux_stat'
761
+ => true
762
+
763
+ irb(main):002:0> LinuxStat::User.get_current_user
764
+ => "x"
765
+
766
+ irb(main):003:0> LinuxStat::User.get_user
767
+ => "x"
768
+
769
+ irb(main):004:0> LinuxStat::User.get_login
770
+ => ""
771
+ ```
772
+
773
+ 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.
774
+
775
+ ## Note 6: PrettifyBytes
776
+ Often times we need to work with KB, MB GB, TB, or KiB, MiB, GiB, TiB, etc.
777
+ And we need some work to convert bytes to those units.
778
+ Because LinuxStat provides a lot of data in bytes, and kilobytes, it's quite tedious to convert them all the time.
779
+ To avoid such duplication, it comes with a PrettifyBytes module.
780
+
781
+ For example, to convert bytes to decimal suffixes:
782
+
783
+ ```
784
+ $irb
785
+ irb(main):001:0> require 'linux_stat'
786
+ => true
787
+
788
+ irb(main):002:0> LinuxStat::PrettifyBytes.convert_decimal(1000)
789
+ => "1.00 kilobyte"
790
+
791
+ irb(main):003:0> LinuxStat::PrettifyBytes.convert_decimal(10000)
792
+ => "10.00 kilobytes"
793
+
794
+ irb(main):004:0> LinuxStat::PrettifyBytes.convert_decimal(100000)
795
+ => "100.00 kilobytes"
796
+
797
+ irb(main):005:0> LinuxStat::PrettifyBytes.convert_decimal(10 ** 13)
798
+ => "10.00 terabytes"
799
+ ```
800
+
801
+ To convert bytes to binary suffixes:
802
+
803
+ ```
804
+ irb(main):006:0> LinuxStat::PrettifyBytes.convert_binary(1000)
805
+ => "1000.00 bytes"
806
+
807
+ irb(main):007:0> LinuxStat::PrettifyBytes.convert_binary(10000)
808
+ => "9.77 kibibytes"
809
+
810
+ irb(main):008:0> LinuxStat::PrettifyBytes.convert_binary(100000)
811
+ => "97.66 kibibytes"
812
+
813
+ irb(main):009:0> LinuxStat::PrettifyBytes.convert_binary(10 ** 13)
814
+ => "9.09 tebibytes"
815
+ ```
816
+
817
+ To convert them to short Metric decimal suffixes:
818
+
819
+ ```
820
+ irb(main):010:0> LinuxStat::PrettifyBytes.convert_short_decimal(1000)
821
+ => "1.00 kB"
822
+
823
+ irb(main):011:0> LinuxStat::PrettifyBytes.convert_short_decimal(10000)
824
+ => "10.00 kB"
825
+
826
+ irb(main):012:0> LinuxStat::PrettifyBytes.convert_short_decimal(100000)
827
+ => "100.00 kB"
828
+
829
+ irb(main):013:0> LinuxStat::PrettifyBytes.convert_short_decimal(10 ** 13)
830
+ => "10.00 TB"
831
+ ```
832
+
833
+ To convert them to short IEC binary suffixes:
834
+
835
+ ```
836
+ irb(main):014:0> LinuxStat::PrettifyBytes.convert_short_binary(1000)
837
+ => "1000 B"
838
+
839
+ irb(main):015:0> LinuxStat::PrettifyBytes.convert_short_binary(10000)
840
+ => "9.77 KiB"
841
+
842
+ irb(main):016:0> LinuxStat::PrettifyBytes.convert_short_binary(100000)
843
+ => "97.66 KiB"
844
+
845
+ irb(main):017:0> LinuxStat::PrettifyBytes.convert_short_binary(10 ** 13)
846
+ => "9.09 TiB"
847
+ ```
848
+
849
+ It can support values upto hundreds of yottabytes and yobibytes, or yb and yib. You can also do stuff like:
850
+
851
+ ```
852
+ $ irb
853
+ irb(main):001:0> require 'linux_stat'
854
+ => true
855
+
856
+ irb(main):002:0> LinuxStat::PrettifyBytes.convert_short_decimal(LinuxStat::Mounts.device_stat('/dev/sdb1')[:total])
857
+ => "31.47 GB"
858
+
859
+ irb(main):003:0> LinuxStat::PrettifyBytes.convert_short_binary(LinuxStat::Mounts.device_stat('/dev/sdb1')[:total])
860
+ => "29.31 GiB"
861
+
862
+ irb(main):004:0> LinuxStat::PrettifyBytes.convert_short_binary(LinuxStat::Mounts.device_stat('/dev/sdb1')[:used])
863
+ => "26.80 GiB"
864
+
865
+ irb(main):005:0> LinuxStat::PrettifyBytes.convert_short_binary(LinuxStat::Mounts.device_stat('/dev/sdb1')[:available])
866
+ => "2.51 GiB"
867
+ ```
868
+
647
869
  Read the ri documentation for more info.
648
870
 
649
871
  ---