linux_stat 0.6.2 → 0.7.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 +4 -4
- data/README.md +553 -188
- data/exe/linuxstat.rb +95 -6
- data/ext/fs_stat/extconf.rb +5 -1
- data/ext/fs_stat/fs_stat.c +0 -1
- data/ext/sysconf/extconf.rb +5 -1
- data/ext/sysconf/sysconf.c +0 -1
- data/ext/utsname/extconf.rb +5 -1
- data/ext/utsname/utsname.c +0 -1
- data/lib/linux_stat.rb +23 -2
- data/lib/linux_stat/battery.rb +20 -1
- data/lib/linux_stat/bios.rb +8 -0
- data/lib/linux_stat/cpu.rb +20 -3
- data/lib/linux_stat/filesystem.rb +31 -10
- data/lib/linux_stat/kernel.rb +36 -2
- data/lib/linux_stat/memory.rb +7 -0
- data/lib/linux_stat/mounts.rb +24 -0
- data/lib/linux_stat/net.rb +119 -1
- data/lib/linux_stat/os.rb +17 -5
- data/lib/linux_stat/prettify_bytes.rb +47 -12
- data/lib/linux_stat/process.rb +10 -0
- data/lib/linux_stat/process_info.rb +245 -55
- data/lib/linux_stat/swap.rb +15 -1
- data/lib/linux_stat/user.rb +64 -11
- data/lib/linux_stat/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d2e39de1fbc809e3c2ebb150e92cd77584ce6fee22107966bdaab7a7c329e164
|
4
|
+
data.tar.gz: a66c52567c7ccb2e7ace5c7737a797d9de49a912c082d8432ec13fddfaac1e06
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a73282108e1b16b1841e87188fd54099c44fdeecf2f69095335eb2a8ced7a8a5994f00a163bfe3620c17f7a9f487e6761f1895327ebeac3ac41490e4de7f33f9
|
7
|
+
data.tar.gz: 6101b6f1199bf969bcf4b7c28c1cfc1ae4c59177739650aa4962060721da9f36ed4c5d40ecebc45cdf668d715fb2e4d5e33f9b121dc37db4652128b210c36320
|
data/README.md
CHANGED
@@ -1,4 +1,5 @@
|
|
1
|
-
# LinuxStat
|
1
|
+
# LinuxStat [](https://rubygems.org/gems/linux_stat) 
|
2
|
+
|
2
3
|

|
3
4
|
|
4
5
|
For reading the eyecandy HTML version, visit [linux_stat](https://souravgoswami.github.io/linux_stat/).
|
@@ -10,7 +11,7 @@ It only works for Linux, and detecting the OS is upto the user of this gem.
|
|
10
11
|
---
|
11
12
|
|
12
13
|
## Dependencies:
|
13
|
-
+ You need to have the C
|
14
|
+
+ You need to have the C compiler installed to be able to compile the C extensions.
|
14
15
|
On Arch Linux:
|
15
16
|
```
|
16
17
|
# pacman -S gcc make
|
@@ -49,457 +50,821 @@ Or install it yourself as:
|
|
49
50
|
## Usage
|
50
51
|
### LinuxStat::BIOS
|
51
52
|
```
|
52
|
-
|
53
|
+
# File: bios.rb | Line: 56
|
54
|
+
# Definition: def date
|
55
|
+
LinuxStat::BIOS.date()
|
53
56
|
=> "04/10/2017"
|
54
57
|
|
55
|
-
|
58
|
+
# File: bios.rb | Line: 10
|
59
|
+
# Definition: def model
|
60
|
+
LinuxStat::BIOS.model()
|
56
61
|
=> "Inspiron 5567"
|
57
62
|
|
58
|
-
|
63
|
+
# File: bios.rb | Line: 27
|
64
|
+
# Definition: def vendor
|
65
|
+
LinuxStat::BIOS.vendor()
|
59
66
|
=> "Dell Inc."
|
60
67
|
|
61
|
-
|
68
|
+
# File: bios.rb | Line: 42
|
69
|
+
# Definition: def version
|
70
|
+
LinuxStat::BIOS.version()
|
62
71
|
=> "1.1.2"
|
63
72
|
|
64
73
|
```
|
65
74
|
|
66
75
|
### LinuxStat::Battery
|
67
76
|
```
|
68
|
-
|
77
|
+
# File: battery.rb | Line: 100
|
78
|
+
# Definition: def charge
|
79
|
+
LinuxStat::Battery.charge()
|
69
80
|
=> 100.0
|
70
81
|
|
71
|
-
|
82
|
+
# File: battery.rb | Line: 73
|
83
|
+
# Definition: def charging?
|
84
|
+
LinuxStat::Battery.charging?()
|
72
85
|
=> true
|
73
86
|
|
74
|
-
|
87
|
+
# File: battery.rb | Line: 82
|
88
|
+
# Definition: def discharging?
|
89
|
+
LinuxStat::Battery.discharging?()
|
75
90
|
=> false
|
76
91
|
|
77
|
-
|
92
|
+
# File: battery.rb | Line: 91
|
93
|
+
# Definition: def full?
|
94
|
+
LinuxStat::Battery.full?()
|
78
95
|
=> true
|
79
96
|
|
80
|
-
|
97
|
+
# File: battery.rb | Line: 45
|
98
|
+
# Definition: def manufacturer
|
99
|
+
LinuxStat::Battery.manufacturer()
|
81
100
|
=> "Samsung SDI"
|
82
101
|
|
83
|
-
|
102
|
+
# File: battery.rb | Line: 36
|
103
|
+
# Definition: def model
|
104
|
+
LinuxStat::Battery.model()
|
84
105
|
=> "DELL CYMGM77"
|
85
106
|
|
86
|
-
|
107
|
+
# File: battery.rb | Line: 8
|
108
|
+
# Definition: def present?
|
109
|
+
LinuxStat::Battery.present?()
|
87
110
|
=> true
|
88
111
|
|
89
|
-
|
112
|
+
# File: battery.rb | Line: 16
|
113
|
+
# Definition: def stat
|
114
|
+
LinuxStat::Battery.stat()
|
90
115
|
=> {:model=>"DELL CYMGM77", :manufacturer=>"Samsung SDI", :technology=>"Li-ion", :status=>"Full", :charge=>100.0, :charging=>true, :discharging=>false, :full=>true}
|
91
116
|
|
92
|
-
|
117
|
+
# File: battery.rb | Line: 64
|
118
|
+
# Definition: def status
|
119
|
+
LinuxStat::Battery.status()
|
93
120
|
=> "Full"
|
94
121
|
|
95
|
-
|
122
|
+
# File: battery.rb | Line: 54
|
123
|
+
# Definition: def technology
|
124
|
+
LinuxStat::Battery.technology()
|
96
125
|
=> "Li-ion"
|
97
126
|
|
98
127
|
```
|
99
128
|
|
100
129
|
### LinuxStat::CPU
|
101
130
|
```
|
102
|
-
|
131
|
+
# File: cpu.rb | Line: 82
|
132
|
+
# Definition: def count
|
133
|
+
LinuxStat::CPU.count()
|
103
134
|
=> 4
|
104
135
|
|
105
|
-
|
106
|
-
|
136
|
+
# File: cpu.rb | Line: 101
|
137
|
+
# Definition: def cur_freq
|
138
|
+
LinuxStat::CPU.cur_freq()
|
139
|
+
=> [2000018, 2000008, 2000003, 1992870]
|
107
140
|
|
108
|
-
|
141
|
+
# File: cpu.rb | Line: 116
|
142
|
+
# Definition: def max_freq
|
143
|
+
LinuxStat::CPU.max_freq()
|
109
144
|
=> [2000000, 2000000, 2000000, 2000000]
|
110
145
|
|
111
|
-
|
146
|
+
# File: cpu.rb | Line: 93
|
147
|
+
# Definition: def model
|
148
|
+
LinuxStat::CPU.model()
|
112
149
|
=> "Intel(R) Core(TM) i3-6006U CPU @ 2.00GHz"
|
113
150
|
|
114
|
-
|
115
|
-
|
151
|
+
# File: cpu.rb | Line: 21
|
152
|
+
# Definition: def stat(sleep = ticks_to_ms)
|
153
|
+
LinuxStat::CPU.stat(sleep)
|
154
|
+
=> {0=>25.0, 1=>50.0, 2=>0.0, 3=>0.0, 4=>50.0}
|
116
155
|
|
117
|
-
|
118
|
-
|
156
|
+
# File: linuxstat.rb | Line: 11
|
157
|
+
# Definition: define_singleton_method(:total_usage) do
|
158
|
+
LinuxStat::CPU.total_usage()
|
159
|
+
=> nil
|
119
160
|
|
120
|
-
|
121
|
-
|
161
|
+
# File: cpu.rb | Line: 63
|
162
|
+
# Definition: def total_usage(sleep = ticks_to_ms)
|
163
|
+
LinuxStat::CPU.usage(sleep)
|
164
|
+
=> 60.0
|
122
165
|
|
123
|
-
|
124
|
-
|
166
|
+
# File: cpu.rb | Line: 21
|
167
|
+
# Definition: def stat(sleep = ticks_to_ms)
|
168
|
+
LinuxStat::CPU.usages(sleep)
|
169
|
+
=> {0=>33.33, 1=>0.0, 2=>0.0, 3=>0.0, 4=>100.0}
|
125
170
|
|
126
171
|
```
|
127
172
|
|
128
|
-
### LinuxStat::
|
173
|
+
### LinuxStat::FS
|
174
|
+
```
|
129
175
|
```
|
130
|
-
LinuxStat::Filesystem.available
|
131
|
-
=> 34612666368
|
132
|
-
|
133
|
-
LinuxStat::Filesystem.free
|
134
|
-
=> 34612666368
|
135
|
-
|
136
|
-
LinuxStat::Filesystem.stat
|
137
|
-
=> {:total=>119981191168, :free=>34612666368, :used=>85368524800}
|
138
|
-
|
139
|
-
LinuxStat::Filesystem.stat_raw
|
140
|
-
=> {:block_size=>4096, :fragment_size=>4096, :blocks=>29292283, :block_free=>8450358, :block_avail_unpriv=>8450358, :inodes=>58612160, :free_inodes=>56582049, :filesystem_id=>2050, :mount_flags=>1024, :max_filename_length=>255}
|
141
176
|
|
142
|
-
LinuxStat::Filesystem
|
177
|
+
### LinuxStat::Filesystem
|
178
|
+
```
|
179
|
+
# File: filesystem.rb | Line: 92
|
180
|
+
# Definition: def available(fs = ?/.freeze)
|
181
|
+
LinuxStat::Filesystem.available(fs)
|
182
|
+
=> 52544614400
|
183
|
+
|
184
|
+
# File: filesystem.rb | Line: 58
|
185
|
+
# Definition: def free(fs = ?/.freeze)
|
186
|
+
LinuxStat::Filesystem.free(fs)
|
187
|
+
=> 52544614400
|
188
|
+
|
189
|
+
# File: filesystem.rb | Line: 19
|
190
|
+
# Definition: def stat(fs = ?/.freeze)
|
191
|
+
LinuxStat::Filesystem.stat(fs)
|
192
|
+
=> {:total=>119981191168, :free=>52544614400, :used=>67436576768}
|
193
|
+
|
194
|
+
# File: filesystem.rb | Line: 108
|
195
|
+
# Definition: def stat_raw(fs = ?/.freeze)
|
196
|
+
LinuxStat::Filesystem.stat_raw(fs)
|
197
|
+
=> {:block_size=>4096, :fragment_size=>4096, :blocks=>29292283, :block_free=>12828275, :block_avail_unpriv=>12828275, :inodes=>58612160, :free_inodes=>56968579, :filesystem_id=>2050, :mount_flags=>1024, :max_filename_length=>255}
|
198
|
+
|
199
|
+
# File: filesystem.rb | Line: 39
|
200
|
+
# Definition: def total(fs = ?/.freeze)
|
201
|
+
LinuxStat::Filesystem.total(fs)
|
143
202
|
=> 119981191168
|
144
203
|
|
145
|
-
|
146
|
-
|
204
|
+
# File: filesystem.rb | Line: 73
|
205
|
+
# Definition: def used(fs = ?/.freeze)
|
206
|
+
LinuxStat::Filesystem.used(fs)
|
207
|
+
=> 67436576768
|
147
208
|
|
148
209
|
```
|
149
210
|
|
150
211
|
### LinuxStat::Kernel
|
151
212
|
```
|
152
|
-
|
213
|
+
# File: kernel.rb | Line: 86
|
214
|
+
# Definition: def build_date
|
215
|
+
LinuxStat::Kernel.build_date()
|
153
216
|
=> 2020-11-20 07:44:55 +0000
|
154
217
|
|
155
|
-
|
218
|
+
# File: kernel.rb | Line: 140
|
219
|
+
# Definition: def build_date_string
|
220
|
+
LinuxStat::Kernel.build_date_string()
|
156
221
|
=> "20 Nov 2020 07:44:55 +0000"
|
157
222
|
|
158
|
-
|
223
|
+
# File: kernel.rb | Line: 21
|
224
|
+
# Definition: def build_user
|
225
|
+
LinuxStat::Kernel.build_user()
|
159
226
|
=> "souravgoswami@archlinux"
|
160
227
|
|
161
|
-
|
228
|
+
# File: kernel.rb | Line: 179
|
229
|
+
# Definition: def ticks
|
230
|
+
LinuxStat::Kernel.clk_tck()
|
162
231
|
=> 100
|
163
232
|
|
164
|
-
|
233
|
+
# File: kernel.rb | Line: 33
|
234
|
+
# Definition: def compiler
|
235
|
+
LinuxStat::Kernel.compiler()
|
165
236
|
=> [:gcc, "10.2.0"]
|
166
237
|
|
167
|
-
|
238
|
+
# File: kernel.rb | Line: 55
|
239
|
+
# Definition: def compiler_version
|
240
|
+
LinuxStat::Kernel.compiler_version()
|
168
241
|
=> "10.2.0"
|
169
242
|
|
170
|
-
|
243
|
+
# File: kernel.rb | Line: 10
|
244
|
+
# Definition: def version
|
245
|
+
LinuxStat::Kernel.release()
|
171
246
|
=> "5.9.9-xanmod1-1"
|
172
247
|
|
173
|
-
|
248
|
+
# File: kernel.rb | Line: 169
|
249
|
+
# Definition: def string
|
250
|
+
LinuxStat::Kernel.string()
|
174
251
|
=> "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
252
|
|
176
|
-
|
253
|
+
# File: kernel.rb | Line: 179
|
254
|
+
# Definition: def ticks
|
255
|
+
LinuxStat::Kernel.ticks()
|
177
256
|
=> 100
|
178
257
|
|
179
|
-
|
258
|
+
# File: kernel.rb | Line: 10
|
259
|
+
# Definition: def version
|
260
|
+
LinuxStat::Kernel.version()
|
180
261
|
=> "5.9.9-xanmod1-1"
|
181
262
|
|
182
263
|
```
|
183
264
|
|
184
265
|
### LinuxStat::Memory
|
185
266
|
```
|
186
|
-
|
187
|
-
|
267
|
+
# File: memory.rb | Line: 50
|
268
|
+
# Definition: def available
|
269
|
+
LinuxStat::Memory.available()
|
270
|
+
=> 773460
|
188
271
|
|
189
|
-
|
190
|
-
|
272
|
+
# File: memory.rb | Line: 81
|
273
|
+
# Definition: def percent_available
|
274
|
+
LinuxStat::Memory.percent_available()
|
275
|
+
=> 20.16
|
191
276
|
|
192
|
-
|
193
|
-
|
277
|
+
# File: memory.rb | Line: 70
|
278
|
+
# Definition: def percent_used
|
279
|
+
LinuxStat::Memory.percent_used()
|
280
|
+
=> 79.84
|
194
281
|
|
195
|
-
|
196
|
-
|
282
|
+
# File: memory.rb | Line: 11
|
283
|
+
# Definition: def stat
|
284
|
+
LinuxStat::Memory.stat()
|
285
|
+
=> {:total=>3836236, :used=>3062776, :available=>773460, :percent_used=>79.84, :percent_available=>20.16}
|
197
286
|
|
198
|
-
|
199
|
-
|
287
|
+
# File: memory.rb | Line: 40
|
288
|
+
# Definition: def total
|
289
|
+
LinuxStat::Memory.total()
|
290
|
+
=> 3836236
|
200
291
|
|
201
|
-
|
202
|
-
|
292
|
+
# File: memory.rb | Line: 60
|
293
|
+
# Definition: def used
|
294
|
+
LinuxStat::Memory.used()
|
295
|
+
=> 3062776
|
203
296
|
|
204
297
|
```
|
205
298
|
|
206
299
|
### LinuxStat::Mounts
|
207
300
|
```
|
208
|
-
|
209
|
-
|
301
|
+
# File: mounts.rb | Line: 179
|
302
|
+
# Definition: def device_stat(dev = root)
|
303
|
+
LinuxStat::Mounts.device_stat(dev)
|
304
|
+
=> {:mountpoint=>"/", :total=>119981191168, :free=>52544614400, :available=>52544614400, :used=>67436576768, :percent_used=>56.21, :percent_free=>43.79, :percent_available=>43.79}
|
210
305
|
|
211
|
-
|
306
|
+
# File: mounts.rb | Line: 137
|
307
|
+
# Definition: def devices_stat
|
308
|
+
LinuxStat::Mounts.devices_stat()
|
212
309
|
=> {"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
310
|
|
214
|
-
|
311
|
+
# File: mounts.rb | Line: 11
|
312
|
+
# Definition: def list
|
313
|
+
LinuxStat::Mounts.list()
|
215
314
|
=> ["proc /proc proc rw,nosuid,nodev,noexec,relatime 0 0", "sys /sys sysfs rw,nosuid,nodev,noexec,relatime 0 0", "dev /dev devtmpfs rw,nosuid,relatime,size=1892904k,nr_inodes=473226,mode=755 0 0", "run /run tmpfs rw,nosuid,nodev,relatime,mode=755 0 0", "...
|
216
315
|
|
217
|
-
|
218
|
-
|
316
|
+
# File: mounts.rb | Line: 20
|
317
|
+
# Definition: def list_devices
|
318
|
+
LinuxStat::Mounts.list_devices()
|
319
|
+
=> ["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", "tra...
|
219
320
|
|
220
|
-
|
221
|
-
|
321
|
+
# File: mounts.rb | Line: 109
|
322
|
+
# Definition: def list_devices_mount_point
|
323
|
+
LinuxStat::Mounts.list_devices_mount_point()
|
324
|
+
=> {"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/blkio", "pstore"=>"/...
|
222
325
|
|
223
|
-
|
326
|
+
# File: mounts.rb | Line: 80
|
327
|
+
# Definition: def mount_point(dev = root)
|
328
|
+
LinuxStat::Mounts.mount_point(dev)
|
224
329
|
=> "/"
|
225
330
|
|
226
|
-
|
331
|
+
# File: mounts.rb | Line: 29
|
332
|
+
# Definition: def root
|
333
|
+
LinuxStat::Mounts.root()
|
227
334
|
=> "/dev/sda2"
|
228
335
|
|
229
|
-
|
336
|
+
# File: mounts.rb | Line: 38
|
337
|
+
# Definition: def root_fs
|
338
|
+
LinuxStat::Mounts.root_fs()
|
230
339
|
=> "xfs"
|
231
340
|
|
232
|
-
|
341
|
+
# File: mounts.rb | Line: 47
|
342
|
+
# Definition: def root_mount_options
|
343
|
+
LinuxStat::Mounts.root_mount_options()
|
233
344
|
=> "rw,noatime,attr2,inode64,logbufs=8,logbsize=32k,noquota"
|
234
345
|
|
235
|
-
|
236
|
-
|
346
|
+
# File: mounts.rb | Line: 56
|
347
|
+
# Definition: def tmpfs
|
348
|
+
LinuxStat::Mounts.tmpfs()
|
349
|
+
=> {"/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", "/tmp"=>"...
|
237
350
|
|
238
351
|
```
|
239
352
|
|
240
353
|
### LinuxStat::Net
|
241
354
|
```
|
242
|
-
|
355
|
+
# File: net.rb | Line: 80
|
356
|
+
# Definition: def usage(interval = 0.1)
|
357
|
+
LinuxStat::Net.current_usage(interval)
|
358
|
+
=> {:received=>0.0, :transmitted=>0.0}
|
359
|
+
|
360
|
+
# File: net.rb | Line: 10
|
361
|
+
# Definition: def ipv4_private
|
362
|
+
LinuxStat::Net.ipv4_private()
|
243
363
|
=> "192.168.0.102"
|
244
364
|
|
365
|
+
# File: net.rb | Line: 23
|
366
|
+
# Definition: def total_bytes
|
367
|
+
LinuxStat::Net.total_bytes()
|
368
|
+
=> {:received=>463746011, :transmitted=>35058283}
|
369
|
+
|
370
|
+
# File: net.rb | Line: 41
|
371
|
+
# Definition: def total_bytes_received
|
372
|
+
LinuxStat::Net.total_bytes_received()
|
373
|
+
=> 463746011
|
374
|
+
|
375
|
+
# File: net.rb | Line: 54
|
376
|
+
# Definition: def total_bytes_transmitted
|
377
|
+
LinuxStat::Net.total_bytes_transmitted()
|
378
|
+
=> 35058283
|
379
|
+
|
380
|
+
# File: net.rb | Line: 80
|
381
|
+
# Definition: def usage(interval = 0.1)
|
382
|
+
LinuxStat::Net.usage(interval)
|
383
|
+
=> {:received=>0.0, :transmitted=>0.0}
|
384
|
+
|
245
385
|
```
|
246
386
|
|
247
387
|
### LinuxStat::OS
|
248
388
|
```
|
249
|
-
|
389
|
+
# File: os.rb | Line: 97
|
390
|
+
# Definition: def bits
|
391
|
+
LinuxStat::OS.bits()
|
250
392
|
=> 64
|
251
393
|
|
252
|
-
|
394
|
+
# File: os.rb | Line: 42
|
395
|
+
# Definition: def distribution
|
396
|
+
LinuxStat::OS.distribution()
|
253
397
|
=> "Arch Linux"
|
254
398
|
|
255
|
-
|
399
|
+
# File: os.rb | Line: 81
|
400
|
+
# Definition: def hostname
|
401
|
+
LinuxStat::OS.hostname()
|
256
402
|
=> "archlinux"
|
257
403
|
|
258
|
-
|
404
|
+
# File: os.rb | Line: 30
|
405
|
+
# Definition: def lsb_release
|
406
|
+
LinuxStat::OS.lsb_release()
|
259
407
|
=> {:LSB_VERSION=>"1.4", :DISTRIB_ID=>"Arch", :DISTRIB_RELEASE=>"rolling", :DISTRIB_DESCRIPTION=>"Arch Linux"}
|
260
408
|
|
261
|
-
|
409
|
+
# File: os.rb | Line: 64
|
410
|
+
# Definition: def machine
|
411
|
+
LinuxStat::OS.machine()
|
262
412
|
=> "x86_64"
|
263
413
|
|
264
|
-
|
414
|
+
# File: os.rb | Line: 72
|
415
|
+
# Definition: def nodename
|
416
|
+
LinuxStat::OS.nodename()
|
265
417
|
=> "archlinux"
|
266
418
|
|
267
|
-
|
419
|
+
# File: os.rb | Line: 15
|
420
|
+
# Definition: def os_release
|
421
|
+
LinuxStat::OS.os_release()
|
268
422
|
=> {: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/"...
|
269
423
|
|
270
|
-
|
271
|
-
|
424
|
+
# File: os.rb | Line: 110
|
425
|
+
# Definition: def uptime
|
426
|
+
LinuxStat::OS.uptime()
|
427
|
+
=> {:hour=>5, :minute=>8, :second=>45.6}
|
428
|
+
|
429
|
+
```
|
430
|
+
|
431
|
+
### LinuxStat::PrettifyBytes
|
432
|
+
```
|
433
|
+
# File: prettify_bytes.rb | Line: 42
|
434
|
+
# Definition: def convert_binary(n)
|
435
|
+
LinuxStat::PrettifyBytes.convert_binary( = 466897525899849)
|
436
|
+
=> "424.64 tebibytes"
|
437
|
+
|
438
|
+
# File: prettify_bytes.rb | Line: 19
|
439
|
+
# Definition: def convert_decimal(n)
|
440
|
+
LinuxStat::PrettifyBytes.convert_decimal( = 126301977853880)
|
441
|
+
=> "126.30 terabytes"
|
442
|
+
|
443
|
+
# File: prettify_bytes.rb | Line: 90
|
444
|
+
# Definition: def convert_short_binary(n)
|
445
|
+
LinuxStat::PrettifyBytes.convert_short_binary( = 751373892255236)
|
446
|
+
=> "683.37 TiB"
|
447
|
+
|
448
|
+
# File: prettify_bytes.rb | Line: 65
|
449
|
+
# Definition: def convert_short_decimal(n)
|
450
|
+
LinuxStat::PrettifyBytes.convert_short_decimal( = 691728311539436)
|
451
|
+
=> "691.73 TB"
|
272
452
|
|
273
453
|
```
|
274
454
|
|
275
455
|
### LinuxStat::Process
|
276
456
|
```
|
277
|
-
|
278
|
-
|
457
|
+
# File: process.rb | Line: 19
|
458
|
+
# Definition: def count
|
459
|
+
LinuxStat::Process.count()
|
460
|
+
=> 201
|
279
461
|
|
280
|
-
|
281
|
-
|
462
|
+
# File: process.rb | Line: 71
|
463
|
+
# Definition: def idle
|
464
|
+
LinuxStat::Process.idle()
|
465
|
+
=> [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, 169, 171, 173, 174, 177, 178, 183, 184, 185, 186, 187, 188, 231, 271, 373, 383, 1001, 2553, 2554, 2555, 2556, 2557, 2558, 7770, 1...
|
282
466
|
|
283
|
-
|
284
|
-
|
467
|
+
# File: process.rb | Line: 8
|
468
|
+
# Definition: def list
|
469
|
+
LinuxStat::Process.list()
|
470
|
+
=> [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, 119, 121, 131, 134,...
|
285
471
|
|
286
|
-
|
472
|
+
# File: process.rb | Line: 25
|
473
|
+
# Definition: def names
|
474
|
+
LinuxStat::Process.names()
|
287
475
|
=> {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...
|
288
476
|
|
289
|
-
|
290
|
-
|
477
|
+
# File: process.rb | Line: 97
|
478
|
+
# Definition: def running
|
479
|
+
LinuxStat::Process.running()
|
480
|
+
=> [12385]
|
291
481
|
|
292
|
-
|
293
|
-
|
482
|
+
# File: process.rb | Line: 58
|
483
|
+
# Definition: def sleeping
|
484
|
+
LinuxStat::Process.sleeping()
|
485
|
+
=> [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, 168, 170, 189, 218, 235, 301, 305, 309, 310, 311, 314, 315, 316, 317, 331, 334, 337, 403, 407, 409, 410,...
|
294
486
|
|
295
|
-
|
487
|
+
# File: process.rb | Line: 37
|
488
|
+
# Definition: def types
|
489
|
+
LinuxStat::Process.types()
|
296
490
|
=> {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...
|
297
491
|
|
298
|
-
|
492
|
+
# File: process.rb | Line: 84
|
493
|
+
# Definition: def zombie
|
494
|
+
LinuxStat::Process.zombie()
|
299
495
|
=> []
|
300
496
|
|
301
497
|
```
|
302
498
|
|
303
499
|
### LinuxStat::ProcessInfo
|
304
500
|
```
|
305
|
-
|
306
|
-
|
501
|
+
# File: process_info.rb | Line: 54
|
502
|
+
# Definition: def cmdline(pid = $$)
|
503
|
+
LinuxStat::ProcessInfo.cmdline(pid)
|
504
|
+
=> "ruby /usr/bin/linuxstat.rb -md"
|
307
505
|
|
308
|
-
|
506
|
+
# File: process_info.rb | Line: 78
|
507
|
+
# Definition: def command_name(pid = $$)
|
508
|
+
LinuxStat::ProcessInfo.command_name(pid)
|
309
509
|
=> "ruby"
|
310
510
|
|
311
|
-
|
312
|
-
|
511
|
+
# File: process_info.rb | Line: 247
|
512
|
+
# Definition: def cpu_stat(pid: $$, sleep: ticks_to_ms)
|
513
|
+
LinuxStat::ProcessInfo.cpu_stat(pid:, sleep:)
|
514
|
+
=> {:cpu_usage=>0.0, :threads=>1, :last_executed_cpu=>0}
|
313
515
|
|
314
|
-
|
516
|
+
# File: process_info.rb | Line: 301
|
517
|
+
# Definition: def cpu_usage(pid: $$, sleep: ticks_to_ms)
|
518
|
+
LinuxStat::ProcessInfo.cpu_usage(pid:, sleep:)
|
315
519
|
=> 0.0
|
316
520
|
|
317
|
-
|
521
|
+
# File: process_info.rb | Line: 406
|
522
|
+
# Definition: def gid(pid = $$)
|
523
|
+
LinuxStat::ProcessInfo.gid(pid)
|
318
524
|
=> {:real=>1000, :effective=>1000, :saved_set=>1000, :filesystem_uid=>1000}
|
319
525
|
|
320
|
-
|
321
|
-
|
526
|
+
# File: process_info.rb | Line: 369
|
527
|
+
# Definition: def last_executed_cpu(pid = $$)
|
528
|
+
LinuxStat::ProcessInfo.last_executed_cpu(pid)
|
529
|
+
=> 0
|
322
530
|
|
323
|
-
|
324
|
-
|
531
|
+
# File: process_info.rb | Line: 114
|
532
|
+
# Definition: def mem_stat(pid = $$)
|
533
|
+
LinuxStat::ProcessInfo.mem_stat(pid)
|
534
|
+
=> {:memory=>12251.136, :virtual_memory=>83943.424, :resident_memory=>18247.68}
|
325
535
|
|
326
|
-
|
327
|
-
|
536
|
+
# File: process_info.rb | Line: 147
|
537
|
+
# Definition: def memory(pid = $$)
|
538
|
+
LinuxStat::ProcessInfo.memory(pid)
|
539
|
+
=> 12251.136
|
328
540
|
|
329
|
-
|
330
|
-
|
541
|
+
# File: process_info.rb | Line: 540
|
542
|
+
# Definition: def nice(pid = $$)
|
543
|
+
LinuxStat::ProcessInfo.nice(pid)
|
544
|
+
=> 0
|
331
545
|
|
332
|
-
|
333
|
-
|
546
|
+
# File: process_info.rb | Line: 427
|
547
|
+
# Definition: def owner(pid = $$)
|
548
|
+
LinuxStat::ProcessInfo.owner(pid)
|
549
|
+
=> "sourav"
|
334
550
|
|
335
|
-
|
551
|
+
# File: process_info.rb | Line: 197
|
552
|
+
# Definition: def resident_memory(pid = $$)
|
553
|
+
LinuxStat::ProcessInfo.resident_memory(pid)
|
554
|
+
=> 18247.68
|
555
|
+
|
556
|
+
# File: process_info.rb | Line: 497
|
557
|
+
# Definition: def running_time(pid = $$)
|
558
|
+
LinuxStat::ProcessInfo.running_time(pid)
|
559
|
+
=> 0.680000000000291
|
560
|
+
|
561
|
+
# File: process_info.rb | Line: 480
|
562
|
+
# Definition: def start_time(pid = $$)
|
563
|
+
LinuxStat::ProcessInfo.start_time(pid)
|
564
|
+
=> 2020-12-17 16:16:17 +0530
|
565
|
+
|
566
|
+
# File: process_info.rb | Line: 449
|
567
|
+
# Definition: def start_time_epoch(pid = $$)
|
568
|
+
LinuxStat::ProcessInfo.start_time_epoch(pid)
|
569
|
+
=> 1608201977
|
570
|
+
|
571
|
+
# File: process_info.rb | Line: 525
|
572
|
+
# Definition: def state(pid = $$)
|
573
|
+
LinuxStat::ProcessInfo.state(pid)
|
574
|
+
=> "R"
|
575
|
+
|
576
|
+
# File: process_info.rb | Line: 344
|
577
|
+
# Definition: def threads(pid = $$)
|
578
|
+
LinuxStat::ProcessInfo.threads(pid)
|
336
579
|
=> 1
|
337
580
|
|
338
|
-
|
581
|
+
# File: process_info.rb | Line: 23
|
582
|
+
# Definition: def total_io(pid = $$)
|
583
|
+
LinuxStat::ProcessInfo.total_io(pid)
|
339
584
|
=> {:read_bytes=>0, :write_bytes=>0}
|
340
585
|
|
341
|
-
|
586
|
+
# File: process_info.rb | Line: 382
|
587
|
+
# Definition: def uid(pid = $$)
|
588
|
+
LinuxStat::ProcessInfo.uid(pid)
|
342
589
|
=> {:real=>1000, :effective=>1000, :saved_set=>1000, :filesystem_uid=>1000}
|
343
590
|
|
344
|
-
|
345
|
-
|
591
|
+
# File: process_info.rb | Line: 172
|
592
|
+
# Definition: def virtual_memory(pid = $$)
|
593
|
+
LinuxStat::ProcessInfo.virtual_memory(pid)
|
594
|
+
=> 83943.424
|
346
595
|
|
347
596
|
```
|
348
597
|
|
349
598
|
### LinuxStat::Swap
|
350
599
|
```
|
351
|
-
|
600
|
+
# File: swap.rb | Line: 22
|
601
|
+
# Definition: def any?
|
602
|
+
LinuxStat::Swap.any?()
|
352
603
|
=> true
|
353
604
|
|
354
|
-
|
355
|
-
|
356
|
-
|
357
|
-
|
358
|
-
|
359
|
-
|
360
|
-
|
361
|
-
|
362
|
-
|
363
|
-
|
364
|
-
|
365
|
-
|
366
|
-
LinuxStat::Swap.
|
367
|
-
=>
|
368
|
-
|
369
|
-
|
605
|
+
# File: swap.rb | Line: 68
|
606
|
+
# Definition: def available
|
607
|
+
LinuxStat::Swap.available()
|
608
|
+
=> 2868220
|
609
|
+
|
610
|
+
# File: swap.rb | Line: 8
|
611
|
+
# Definition: def list
|
612
|
+
LinuxStat::Swap.list()
|
613
|
+
=> {"/dev/zram0"=>[:partition, 4194300, 1326080, -2]}
|
614
|
+
|
615
|
+
# File: swap.rb | Line: 103
|
616
|
+
# Definition: def percent_available
|
617
|
+
LinuxStat::Swap.percent_available()
|
618
|
+
=> 68.38
|
619
|
+
|
620
|
+
# File: swap.rb | Line: 89
|
621
|
+
# Definition: def percent_used
|
622
|
+
LinuxStat::Swap.percent_used()
|
623
|
+
=> 31.62
|
624
|
+
|
625
|
+
# File: swap.rb | Line: 32
|
626
|
+
# Definition: def stat
|
627
|
+
LinuxStat::Swap.stat()
|
628
|
+
=> {:total=>4194300, :used=>1326080, :available=>2868220, :percent_used=>31.62, :percent_available=>68.38}
|
629
|
+
|
630
|
+
# File: swap.rb | Line: 57
|
631
|
+
# Definition: def total
|
632
|
+
LinuxStat::Swap.total()
|
370
633
|
=> 4194300
|
371
634
|
|
372
|
-
|
373
|
-
|
635
|
+
# File: swap.rb | Line: 80
|
636
|
+
# Definition: def used
|
637
|
+
LinuxStat::Swap.used()
|
638
|
+
=> 1326080
|
374
639
|
|
375
640
|
```
|
376
641
|
|
377
642
|
### LinuxStat::Sysconf
|
378
643
|
```
|
379
|
-
LinuxStat::Sysconf.child_max
|
644
|
+
# # LinuxStat::Sysconf.child_max()
|
380
645
|
=> 2000000
|
381
646
|
|
382
|
-
LinuxStat::Sysconf.get_euid
|
647
|
+
# # LinuxStat::Sysconf.get_euid()
|
383
648
|
=> 1000
|
384
649
|
|
385
|
-
LinuxStat::Sysconf.get_gid
|
650
|
+
# # LinuxStat::Sysconf.get_gid()
|
386
651
|
=> 1000
|
387
652
|
|
388
|
-
LinuxStat::Sysconf.get_login
|
653
|
+
# # LinuxStat::Sysconf.get_login()
|
389
654
|
=> "sourav"
|
390
655
|
|
391
|
-
LinuxStat::Sysconf.get_uid
|
656
|
+
# # LinuxStat::Sysconf.get_uid()
|
392
657
|
=> 1000
|
393
658
|
|
394
|
-
LinuxStat::Sysconf.get_user
|
659
|
+
# # LinuxStat::Sysconf.get_user()
|
395
660
|
=> "sourav"
|
396
661
|
|
397
|
-
LinuxStat::Sysconf.hostname_max
|
662
|
+
# # LinuxStat::Sysconf.hostname_max()
|
398
663
|
=> 64
|
399
664
|
|
400
|
-
LinuxStat::Sysconf.login_name_max
|
665
|
+
# # LinuxStat::Sysconf.login_name_max()
|
401
666
|
=> 256
|
402
667
|
|
403
|
-
LinuxStat::Sysconf.open_max
|
404
|
-
=>
|
668
|
+
# # LinuxStat::Sysconf.open_max()
|
669
|
+
=> 8192
|
405
670
|
|
406
|
-
LinuxStat::Sysconf.
|
671
|
+
# # LinuxStat::Sysconf.pagesize()
|
407
672
|
=> 4096
|
408
673
|
|
409
|
-
LinuxStat::Sysconf.posix_version
|
674
|
+
# # LinuxStat::Sysconf.posix_version()
|
410
675
|
=> 200809
|
411
676
|
|
412
|
-
LinuxStat::Sysconf.sc_clk_tck
|
677
|
+
# # LinuxStat::Sysconf.sc_clk_tck()
|
413
678
|
=> 100
|
414
679
|
|
415
|
-
LinuxStat::Sysconf.stream_max
|
680
|
+
# # LinuxStat::Sysconf.stream_max()
|
416
681
|
=> 16
|
417
682
|
|
418
|
-
LinuxStat::Sysconf.tty_name_max
|
683
|
+
# # LinuxStat::Sysconf.tty_name_max()
|
419
684
|
=> 32
|
420
685
|
|
421
686
|
```
|
422
687
|
|
423
688
|
### LinuxStat::Uname
|
424
689
|
```
|
425
|
-
LinuxStat::Uname.machine
|
690
|
+
# # LinuxStat::Uname.machine()
|
426
691
|
=> "x86_64"
|
427
692
|
|
428
|
-
LinuxStat::Uname.nodename
|
693
|
+
# # LinuxStat::Uname.nodename()
|
429
694
|
=> "archlinux"
|
430
695
|
|
431
|
-
LinuxStat::Uname.release
|
696
|
+
# # LinuxStat::Uname.release()
|
432
697
|
=> "5.9.9-xanmod1-1"
|
433
698
|
|
434
|
-
LinuxStat::Uname.sysname
|
699
|
+
# # LinuxStat::Uname.sysname()
|
435
700
|
=> "Linux"
|
436
701
|
|
437
|
-
LinuxStat::Uname.version
|
702
|
+
# # LinuxStat::Uname.version()
|
438
703
|
=> "#1 SMP PREEMPT Fri, 20 Nov 2020 07:44:55 +0000"
|
439
704
|
|
440
705
|
```
|
441
706
|
|
442
707
|
### LinuxStat::User
|
443
708
|
```
|
444
|
-
|
709
|
+
# File: user.rb | Line: 98
|
710
|
+
# Definition: def get_user
|
711
|
+
LinuxStat::User.get_current_user()
|
445
712
|
=> "sourav"
|
446
713
|
|
447
|
-
|
714
|
+
# File: user.rb | Line: 137
|
715
|
+
# Definition: def get_euid
|
716
|
+
LinuxStat::User.get_euid()
|
448
717
|
=> 1000
|
449
718
|
|
450
|
-
|
719
|
+
# File: user.rb | Line: 129
|
720
|
+
# Definition: def get_gid
|
721
|
+
LinuxStat::User.get_gid()
|
451
722
|
=> 1000
|
452
723
|
|
453
|
-
|
724
|
+
# File: user.rb | Line: 152
|
725
|
+
# Definition: def get_login
|
726
|
+
LinuxStat::User.get_login()
|
454
727
|
=> "sourav"
|
455
728
|
|
456
|
-
|
729
|
+
# File: user.rb | Line: 121
|
730
|
+
# Definition: def get_uid
|
731
|
+
LinuxStat::User.get_uid()
|
457
732
|
=> 1000
|
458
733
|
|
459
|
-
|
734
|
+
# File: user.rb | Line: 98
|
735
|
+
# Definition: def get_user
|
736
|
+
LinuxStat::User.get_user()
|
460
737
|
=> "sourav"
|
461
738
|
|
462
|
-
|
739
|
+
# File: user.rb | Line: 215
|
740
|
+
# Definition: def gid_by_username(username = get_user)
|
741
|
+
LinuxStat::User.gid_by_username(username)
|
463
742
|
=> 1000
|
464
743
|
|
465
|
-
|
744
|
+
# File: user.rb | Line: 56
|
745
|
+
# Definition: def gids
|
746
|
+
LinuxStat::User.gids()
|
466
747
|
=> {:root=>0, :bin=>1, :daemon=>2, :mail=>12, :ftp=>11, :http=>33, :nobody=>65534, :dbus=>81, :"systemd-journal-remote"=>982, :"systemd-network"=>981, :"systemd-resolve"=>980, :"systemd-timesync"=>979, :"systemd-coredump"=>978, :uuidd=>68, :avahi=>977, :...
|
467
748
|
|
468
|
-
|
749
|
+
# File: user.rb | Line: 314
|
750
|
+
# Definition: def home_by_gid(id = get_gid)
|
751
|
+
LinuxStat::User.home_by_gid(id)
|
469
752
|
=> "/home/sourav"
|
470
753
|
|
471
|
-
|
754
|
+
# File: user.rb | Line: 266
|
755
|
+
# Definition: def home_by_username(user = get_user)
|
756
|
+
LinuxStat::User.home_by_username(user)
|
472
757
|
=> "/home/sourav"
|
473
758
|
|
474
|
-
|
759
|
+
# File: user.rb | Line: 72
|
760
|
+
# Definition: def home_directories
|
761
|
+
LinuxStat::User.home_directories()
|
475
762
|
=> {:root=>"/root", :bin=>"/", :daemon=>"/", :mail=>"/var/spool/mail", :ftp=>"/srv/ftp", :http=>"/srv/http", :nobody=>"/", :dbus=>"/", :"systemd-journal-remote"=>"/", :"systemd-network"=>"/", :"systemd-resolve"=>"/", :"systemd-timesync"=>"/", :"systemd-c...
|
476
763
|
|
477
|
-
|
764
|
+
# File: user.rb | Line: 293
|
765
|
+
# Definition: def homes_by_uid(id = get_uid)
|
766
|
+
LinuxStat::User.homes_by_uid(id)
|
478
767
|
=> ["/home/sourav"]
|
479
768
|
|
480
|
-
|
769
|
+
# File: user.rb | Line: 23
|
770
|
+
# Definition: def ids
|
771
|
+
LinuxStat::User.ids()
|
481
772
|
=> {:root=>{:uid=>0, :gid=>0}, :bin=>{:uid=>1, :gid=>1}, :daemon=>{:uid=>2, :gid=>2}, :mail=>{:uid=>8, :gid=>12}, :ftp=>{:uid=>14, :gid=>11}, :http=>{:uid=>33, :gid=>33}, :nobody=>{:uid=>65534, :gid=>65534}, :dbus=>{:uid=>81, :gid=>81}, :"systemd-journal...
|
482
773
|
|
483
|
-
|
774
|
+
# File: user.rb | Line: 11
|
775
|
+
# Definition: def list
|
776
|
+
LinuxStat::User.list()
|
484
777
|
=> ["root", "bin", "daemon", "mail", "ftp", "http", "nobody", "dbus", "systemd-journal-remote", "systemd-network", "systemd-resolve", "systemd-timesync", "systemd-coredump", "uuidd", "avahi", "colord", "git", "lxdm", "polkitd", "rtkit", "usbmux", "sourav...
|
485
778
|
|
486
|
-
|
779
|
+
# File: user.rb | Line: 244
|
780
|
+
# Definition: def uid_by_username(username = get_user)
|
781
|
+
LinuxStat::User.uid_by_username(username)
|
487
782
|
=> 1000
|
488
783
|
|
489
|
-
|
784
|
+
# File: user.rb | Line: 40
|
785
|
+
# Definition: def uids
|
786
|
+
LinuxStat::User.uids()
|
490
787
|
=> {:root=>0, :bin=>1, :daemon=>2, :mail=>8, :ftp=>14, :http=>33, :nobody=>65534, :dbus=>81, :"systemd-journal-remote"=>982, :"systemd-network"=>981, :"systemd-resolve"=>980, :"systemd-timesync"=>979, :"systemd-coredump"=>978, :uuidd=>68, :avahi=>977, :c...
|
491
788
|
|
492
|
-
|
789
|
+
# File: user.rb | Line: 187
|
790
|
+
# Definition: def username_by_gid(gid = get_gid)
|
791
|
+
LinuxStat::User.username_by_gid(gid)
|
493
792
|
=> "sourav"
|
494
793
|
|
495
|
-
|
794
|
+
# File: user.rb | Line: 169
|
795
|
+
# Definition: def usernames_by_uid(uid = get_uid)
|
796
|
+
LinuxStat::User.usernames_by_uid(uid)
|
496
797
|
=> ["sourav"]
|
497
798
|
|
498
799
|
```
|
499
800
|
|
500
801
|
---
|
501
802
|
|
502
|
-
## Note 1:
|
803
|
+
## Note 1: CPU usage, and Net usage
|
804
|
+
To calculate the current usage, we need to get two usages at a given interval, and subtract the 2nd from the 1st.
|
805
|
+
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.
|
806
|
+
That means the current speed is 9000 bytes/s or 9 kB/s.
|
807
|
+
|
808
|
+
Without the polling, it's not really possible to calculate the current usage. Although the total usage can be calculated.
|
809
|
+
A system monitor does that, too...
|
810
|
+
|
811
|
+
Thus these methods requires a polling interval:
|
812
|
+
|
813
|
+
1. LinuxStat::CPU.stat, usage, total_usage, usage.
|
814
|
+
2. LinuxStat::ProcessInfo.cpu_usage, cpu_stat.
|
815
|
+
3. LinuxStat::Net.usage, current_usage.
|
816
|
+
|
817
|
+
They sleep for a given interval and then differentiate between the data.
|
818
|
+
|
819
|
+
For more info look at the ri documentation for the above methods.
|
820
|
+
|
821
|
+
These methods can slow down your application a bit unless you implement them in a thread.
|
822
|
+
|
823
|
+
Other methods doesn't have the sleep implemented, and they just works under a millisecond.
|
824
|
+
|
825
|
+
For example:
|
826
|
+
|
827
|
+
```
|
828
|
+
LinuxStat::CPU.stat(0.1)
|
829
|
+
=> {0=>7.69, 1=>0.0, 2=>0.0, 3=>18.18, 4=>10.0}
|
830
|
+
```
|
831
|
+
This will sleep for 0.1 seconds. To be reliable, use a time like 0.05 seconds or so.
|
832
|
+
|
833
|
+
If you want to build a system monitor and don't want to wait, you have to do something like this:
|
834
|
+
|
835
|
+
```
|
836
|
+
#!/usr/bin/ruby
|
837
|
+
require 'linux_stat'
|
838
|
+
|
839
|
+
usages = []
|
840
|
+
thread = Thread.new { }
|
841
|
+
counter = 0
|
842
|
+
|
843
|
+
while true
|
844
|
+
thread = Thread.new { usages = LinuxStat::CPU.usages(0.5).values } unless thread.alive?
|
845
|
+
|
846
|
+
# clears the screen and prints the info
|
847
|
+
puts "\e[2J\e[H\e[3J"\
|
848
|
+
"#{counter += 1}\n"\
|
849
|
+
"\e[1;33mTotal CPU Usage:\e[0m #{usages[0]}%\n"\
|
850
|
+
"#{usages[1..-1].to_a.map.with_index { |x, i| "\e[1;33mCore #{i}\e[0m => #{x}%\n" }.join}"\
|
851
|
+
"Total Download: #{LinuxStat::PrettifyBytes.convert_decimal LinuxStat::Net.total_bytes_received}\n"\
|
852
|
+
"Total Upload: #{LinuxStat::PrettifyBytes.convert_decimal LinuxStat::Net.total_bytes_transmitted}"
|
853
|
+
end
|
854
|
+
```
|
855
|
+
|
856
|
+
This will not wait in every loop for 0.5 seconds, but it will not update the cpu usage in every loop either.
|
857
|
+
So what you will be seeing in the CPU usage in every 0.5 seconds interval.
|
858
|
+
|
859
|
+
You will also see the counter increases like crazy. Which means it's not getting waited for 0.5 seconds.
|
860
|
+
|
861
|
+
But the other methods doesn't have this delay, thus in this example,
|
862
|
+
you will be able see the "Total Download" and "Total Upload" in real time,
|
863
|
+
well as soon as the Linux kernel updates the data and ruby executes the loop.
|
864
|
+
|
865
|
+
Just run the linuxstat.rb command to test what method takes what time measured in microseconds.
|
866
|
+
|
867
|
+
## Note 2: Filesystem
|
503
868
|
|
504
869
|
Filesystem can take arguments. By default it's '/' or the root of the system...
|
505
870
|
|
@@ -521,7 +886,7 @@ $ irb
|
|
521
886
|
irb(main):001:0> require 'linux_stat'
|
522
887
|
=> true
|
523
888
|
|
524
|
-
irb(main):002:0> LinuxStat::Mounts.
|
889
|
+
irb(main):002:0> LinuxStat::Mounts.mount_point('/dev/sdb1')
|
525
890
|
=> "/run/media/sourav/5c2b7af7-d4c3-4ab4-a035-06d18ffc8e6f"
|
526
891
|
|
527
892
|
irb(main):003:0> thumbdrive = _
|
@@ -534,7 +899,7 @@ irb(main):005:0> LinuxStat::Filesystem.total(thumbdrive).fdiv(1024 ** 3).to_s <<
|
|
534
899
|
=> "29.305004119873047 GiB"
|
535
900
|
```
|
536
901
|
|
537
|
-
## Note
|
902
|
+
## Note 3: ProcessInfo
|
538
903
|
|
539
904
|
All the methods LinuxStat::ProcessInfo can take an argument containing the Process ID of a process.
|
540
905
|
By default it's $$ or the PID of the current process, ruby, itself.
|
@@ -586,7 +951,7 @@ irb(main):002:0> LinuxStat::ProcessInfo.memory(LinuxStat::Process.names.find { |
|
|
586
951
|
=> "467.51 MiB"
|
587
952
|
```
|
588
953
|
|
589
|
-
## Note
|
954
|
+
## Note 4: FS
|
590
955
|
|
591
956
|
LinuxStat::FS module gives you the raw info in Hash collected from statvfs.
|
592
957
|
|
@@ -611,7 +976,7 @@ irb(main):003:0> t = Time.now ; puts LinuxStat::FS.stat('/') ; Time.now - t
|
|
611
976
|
|
612
977
|
To learn more about them, just run ri and the method name. To see all available methods.
|
613
978
|
|
614
|
-
## Note
|
979
|
+
## Note 5: User
|
615
980
|
Most of the LinuxStat::User supports arguments.
|
616
981
|
|
617
982
|
For example, to get a user's home by the username:
|
@@ -693,7 +1058,7 @@ irb(main):004:0> LinuxStat::User.get_login
|
|
693
1058
|
|
694
1059
|
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.
|
695
1060
|
|
696
|
-
## Note
|
1061
|
+
## Note 6: PrettifyBytes
|
697
1062
|
Often times we need to work with KB, MB GB, TB, or KiB, MiB, GiB, TiB, etc.
|
698
1063
|
And we need some work to convert bytes to those units.
|
699
1064
|
Because LinuxStat provides a lot of data in bytes, and kilobytes, it's quite tedious to convert them all the time.
|