linux_stat 0.6.2 → 0.6.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +53 -38
- data/exe/linuxstat.rb +1 -1
- data/lib/linux_stat.rb +23 -2
- data/lib/linux_stat/net.rb +107 -1
- data/lib/linux_stat/process_info.rb +2 -5
- data/lib/linux_stat/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 05ad75bfd711c7ac7960645e2609416e868f2b425cbac94b503198db8b011aa4
|
4
|
+
data.tar.gz: f6291a5aaa6903839d7915c8e8494d88cf165dd6e82143ff0fc71dcea19628d8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f4406f12e2035652f26f9eb518bb4386e644622938d506880cc3f2899937e060b594d6067a8b4a4b66c85db24f068b13a70e59cbac4f9770cc937569e506da26
|
7
|
+
data.tar.gz: b0bbb6cd4570228bafaa2fe89d2bc6a75e67803334e907bcf6e3c3a3fb70f1333ac98da133484b37d8fe279d991ffd18cad617fa931f77c9c7150798cc2d580a
|
data/README.md
CHANGED
@@ -103,7 +103,7 @@ LinuxStat::CPU.count
|
|
103
103
|
=> 4
|
104
104
|
|
105
105
|
LinuxStat::CPU.cur_freq
|
106
|
-
=> [
|
106
|
+
=> [2000063, 2000108, 2000332, 2000028]
|
107
107
|
|
108
108
|
LinuxStat::CPU.max_freq
|
109
109
|
=> [2000000, 2000000, 2000000, 2000000]
|
@@ -112,38 +112,38 @@ LinuxStat::CPU.model
|
|
112
112
|
=> "Intel(R) Core(TM) i3-6006U CPU @ 2.00GHz"
|
113
113
|
|
114
114
|
LinuxStat::CPU.stat
|
115
|
-
=> {0=>
|
115
|
+
=> {0=>0.0, 1=>0.0, 2=>0.0, 3=>0.0, 4=>0.0}
|
116
116
|
|
117
117
|
LinuxStat::CPU.total_usage
|
118
118
|
=> 0.0
|
119
119
|
|
120
120
|
LinuxStat::CPU.usage
|
121
|
-
=>
|
121
|
+
=> 20.0
|
122
122
|
|
123
123
|
LinuxStat::CPU.usages
|
124
|
-
=> {0=>
|
124
|
+
=> {0=>20.0, 1=>0.0, 2=>0.0, 3=>50.0, 4=>100.0}
|
125
125
|
|
126
126
|
```
|
127
127
|
|
128
128
|
### LinuxStat::Filesystem
|
129
129
|
```
|
130
130
|
LinuxStat::Filesystem.available
|
131
|
-
=>
|
131
|
+
=> 33120964608
|
132
132
|
|
133
133
|
LinuxStat::Filesystem.free
|
134
|
-
=>
|
134
|
+
=> 33120964608
|
135
135
|
|
136
136
|
LinuxStat::Filesystem.stat
|
137
|
-
=> {:total=>119981191168, :free=>
|
137
|
+
=> {:total=>119981191168, :free=>33120964608, :used=>86860226560}
|
138
138
|
|
139
139
|
LinuxStat::Filesystem.stat_raw
|
140
|
-
=> {:block_size=>4096, :fragment_size=>4096, :blocks=>29292283, :block_free=>
|
140
|
+
=> {:block_size=>4096, :fragment_size=>4096, :blocks=>29292283, :block_free=>8086173, :block_avail_unpriv=>8086173, :inodes=>58612160, :free_inodes=>56567338, :filesystem_id=>2050, :mount_flags=>1024, :max_filename_length=>255}
|
141
141
|
|
142
142
|
LinuxStat::Filesystem.total
|
143
143
|
=> 119981191168
|
144
144
|
|
145
145
|
LinuxStat::Filesystem.used
|
146
|
-
=>
|
146
|
+
=> 86860226560
|
147
147
|
|
148
148
|
```
|
149
149
|
|
@@ -184,35 +184,35 @@ LinuxStat::Kernel.version
|
|
184
184
|
### LinuxStat::Memory
|
185
185
|
```
|
186
186
|
LinuxStat::Memory.available
|
187
|
-
=>
|
187
|
+
=> 579264
|
188
188
|
|
189
189
|
LinuxStat::Memory.percent_available
|
190
|
-
=>
|
190
|
+
=> 15.1
|
191
191
|
|
192
192
|
LinuxStat::Memory.percent_used
|
193
|
-
=>
|
193
|
+
=> 84.9
|
194
194
|
|
195
195
|
LinuxStat::Memory.stat
|
196
|
-
=> {:total=>
|
196
|
+
=> {:total=>3836236, :used=>3256972, :available=>579264, :percent_used=>84.9, :percent_available=>15.1}
|
197
197
|
|
198
198
|
LinuxStat::Memory.total
|
199
|
-
=>
|
199
|
+
=> 3836236
|
200
200
|
|
201
201
|
LinuxStat::Memory.used
|
202
|
-
=>
|
202
|
+
=> 3256972
|
203
203
|
|
204
204
|
```
|
205
205
|
|
206
206
|
### LinuxStat::Mounts
|
207
207
|
```
|
208
208
|
LinuxStat::Mounts.device_stat
|
209
|
-
=> {:mountpoint=>"/", :total=>119981191168, :free=>
|
209
|
+
=> {:mountpoint=>"/", :total=>119981191168, :free=>33120964608, :available=>33120964608, :used=>86860226560, :percent_used=>72.39, :percent_free=>27.61, :percent_available=>27.61}
|
210
210
|
|
211
211
|
LinuxStat::Mounts.devices_stat
|
212
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
213
|
|
214
214
|
LinuxStat::Mounts.list
|
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=
|
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
216
|
|
217
217
|
LinuxStat::Mounts.list_devices
|
218
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...
|
@@ -239,9 +239,24 @@ LinuxStat::Mounts.tmpfs
|
|
239
239
|
|
240
240
|
### LinuxStat::Net
|
241
241
|
```
|
242
|
+
LinuxStat::Net.current_usage
|
243
|
+
=> {:received=>2183400.0, :transmitted=>114860.0}
|
244
|
+
|
242
245
|
LinuxStat::Net.ipv4_private
|
243
246
|
=> "192.168.0.102"
|
244
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}
|
259
|
+
|
245
260
|
```
|
246
261
|
|
247
262
|
### LinuxStat::OS
|
@@ -268,29 +283,29 @@ LinuxStat::OS.os_release
|
|
268
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/"...
|
269
284
|
|
270
285
|
LinuxStat::OS.uptime
|
271
|
-
=> {:hour=>
|
286
|
+
=> {:hour=>7, :minute=>44, :second=>29.92}
|
272
287
|
|
273
288
|
```
|
274
289
|
|
275
290
|
### LinuxStat::Process
|
276
291
|
```
|
277
292
|
LinuxStat::Process.count
|
278
|
-
=>
|
293
|
+
=> 205
|
279
294
|
|
280
295
|
LinuxStat::Process.idle
|
281
|
-
=> [3, 4, 6, 9, 12, 23, 30, 37, 39, 49, 102, 103, 104, 106, 107, 108, 109, 110, 117, 118,
|
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...
|
282
297
|
|
283
298
|
LinuxStat::Process.list
|
284
|
-
=> [1, 2, 3, 4, 6, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 23, 24, 25, 26, 27, 28, 30, 31, 32, 33, 34, 35, 37, 38, 39, 40, 41, 42, 46, 47, 48, 49, 50, 51, 52, 102, 103, 104, 106, 107, 108, 109, 110,
|
299
|
+
=> [1, 2, 3, 4, 6, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 23, 24, 25, 26, 27, 28, 30, 31, 32, 33, 34, 35, 37, 38, 39, 40, 41, 42, 46, 47, 48, 49, 50, 51, 52, 102, 103, 104, 106, 107, 108, 109, 110, 111, 114, 115, 117, 118, 120, 122, 131, 134,...
|
285
300
|
|
286
301
|
LinuxStat::Process.names
|
287
|
-
=> {1=>"systemd", 2=>"kthreadd", 3=>"rcu_gp", 4=>"rcu_par_gp", 6=>"kworker/0:0H
|
302
|
+
=> {1=>"systemd", 2=>"kthreadd", 3=>"rcu_gp", 4=>"rcu_par_gp", 6=>"kworker/0:0H", 9=>"mm_percpu_wq", 10=>"ksoftirqd/0", 11=>"rcuc/0", 12=>"rcu_preempt", 13=>"rcub/0", 14=>"migration/0", 15=>"idle_inject/0", 16=>"cpuhp/0", 17=>"cpuhp/1", 18=>"idle_inject/...
|
288
303
|
|
289
304
|
LinuxStat::Process.running
|
290
|
-
=> [
|
305
|
+
=> [21158]
|
291
306
|
|
292
307
|
LinuxStat::Process.sleeping
|
293
|
-
=> [1, 2, 10, 11, 13, 14, 15, 16, 17, 18, 19, 20, 21, 24, 25, 26, 27, 28, 31, 32, 33, 34, 35, 38, 40, 41, 42, 46, 47, 48, 50, 51, 52,
|
308
|
+
=> [1, 2, 10, 11, 13, 14, 15, 16, 17, 18, 19, 20, 21, 24, 25, 26, 27, 28, 31, 32, 33, 34, 35, 38, 40, 41, 42, 46, 47, 48, 50, 51, 52, 111, 114, 115, 165, 167, 189, 217, 231, 302, 307, 308, 309, 310, 320, 321, 322, 323, 325, 326, 350, 353, 356, 374, 394,...
|
294
309
|
|
295
310
|
LinuxStat::Process.types
|
296
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...
|
@@ -309,7 +324,7 @@ LinuxStat::ProcessInfo.command_name
|
|
309
324
|
=> "ruby"
|
310
325
|
|
311
326
|
LinuxStat::ProcessInfo.cpu_stat
|
312
|
-
=> {:cpu_usage=>0.0, :threads=>1, :last_executed_cpu=>
|
327
|
+
=> {:cpu_usage=>0.0, :threads=>1, :last_executed_cpu=>1}
|
313
328
|
|
314
329
|
LinuxStat::ProcessInfo.cpu_usage
|
315
330
|
=> 0.0
|
@@ -318,19 +333,19 @@ LinuxStat::ProcessInfo.gid
|
|
318
333
|
=> {:real=>1000, :effective=>1000, :saved_set=>1000, :filesystem_uid=>1000}
|
319
334
|
|
320
335
|
LinuxStat::ProcessInfo.last_executed_cpu
|
321
|
-
=>
|
336
|
+
=> 1
|
322
337
|
|
323
338
|
LinuxStat::ProcessInfo.mem_stat
|
324
|
-
=> {:memory=>
|
339
|
+
=> {:memory=>10051.584, :virtual_memory=>81801.216, :resident_memory=>15986.688}
|
325
340
|
|
326
341
|
LinuxStat::ProcessInfo.memory
|
327
|
-
=>
|
342
|
+
=> 10051.584
|
328
343
|
|
329
344
|
LinuxStat::ProcessInfo.owner
|
330
345
|
=> "sourav"
|
331
346
|
|
332
347
|
LinuxStat::ProcessInfo.resident_memory
|
333
|
-
=>
|
348
|
+
=> 15986.688
|
334
349
|
|
335
350
|
LinuxStat::ProcessInfo.threads
|
336
351
|
=> 1
|
@@ -342,7 +357,7 @@ LinuxStat::ProcessInfo.uid
|
|
342
357
|
=> {:real=>1000, :effective=>1000, :saved_set=>1000, :filesystem_uid=>1000}
|
343
358
|
|
344
359
|
LinuxStat::ProcessInfo.virtual_memory
|
345
|
-
=>
|
360
|
+
=> 81801.216
|
346
361
|
|
347
362
|
```
|
348
363
|
|
@@ -352,25 +367,25 @@ LinuxStat::Swap.any?
|
|
352
367
|
=> true
|
353
368
|
|
354
369
|
LinuxStat::Swap.available
|
355
|
-
=>
|
370
|
+
=> 3383720
|
356
371
|
|
357
372
|
LinuxStat::Swap.list
|
358
|
-
=> {"/dev/zram0"=>[:partition, 4194300,
|
373
|
+
=> {"/dev/zram0"=>[:partition, 4194300, 810580, -2]}
|
359
374
|
|
360
375
|
LinuxStat::Swap.percent_available
|
361
|
-
=>
|
376
|
+
=> 80.67
|
362
377
|
|
363
378
|
LinuxStat::Swap.percent_used
|
364
|
-
=>
|
379
|
+
=> 19.33
|
365
380
|
|
366
381
|
LinuxStat::Swap.stat
|
367
|
-
=> {:total=>4194300, :used=>
|
382
|
+
=> {:total=>4194300, :used=>810580, :available=>3383720, :percent_used=>19.33, :percent_available=>80.67}
|
368
383
|
|
369
384
|
LinuxStat::Swap.total
|
370
385
|
=> 4194300
|
371
386
|
|
372
387
|
LinuxStat::Swap.used
|
373
|
-
=>
|
388
|
+
=> 810580
|
374
389
|
|
375
390
|
```
|
376
391
|
|
@@ -403,7 +418,7 @@ LinuxStat::Sysconf.login_name_max
|
|
403
418
|
LinuxStat::Sysconf.open_max
|
404
419
|
=> 1024
|
405
420
|
|
406
|
-
LinuxStat::Sysconf.
|
421
|
+
LinuxStat::Sysconf.pagesize
|
407
422
|
=> 4096
|
408
423
|
|
409
424
|
LinuxStat::Sysconf.posix_version
|
@@ -521,7 +536,7 @@ $ irb
|
|
521
536
|
irb(main):001:0> require 'linux_stat'
|
522
537
|
=> true
|
523
538
|
|
524
|
-
irb(main):002:0> LinuxStat::Mounts.
|
539
|
+
irb(main):002:0> LinuxStat::Mounts.mount_point('/dev/sdb1')
|
525
540
|
=> "/run/media/sourav/5c2b7af7-d4c3-4ab4-a035-06d18ffc8e6f"
|
526
541
|
|
527
542
|
irb(main):003:0> thumbdrive = _
|
data/exe/linuxstat.rb
CHANGED
data/lib/linux_stat.rb
CHANGED
@@ -1,8 +1,26 @@
|
|
1
|
-
#
|
1
|
+
# ----------------------------------------------------------------------------------------------------- #
|
2
|
+
# Don't edit this file unless you know what you are doing. #
|
3
|
+
# #
|
4
|
+
# A file can have reverse dependency. #
|
5
|
+
# For example, linux_stat/utsname is required before #
|
6
|
+
# linux_stat/os, which means utsname can be used by LinuxStat::OS and the files below. #
|
7
|
+
# #
|
8
|
+
# Once wrongly edited, you need to go through each method to know what #
|
9
|
+
# file is required by the module functions. Which can be very time consuming. #
|
10
|
+
# #
|
11
|
+
# If you are writng an independent module, just add them under "Independent" section #
|
12
|
+
# If you are writing a dependent module, just append that to the end of the file. #
|
13
|
+
# If you are writing something that is miscellaneous, just add it to miscellaneous section #
|
14
|
+
# ------------------------------------------------------------------------------------------------------ #
|
15
|
+
|
16
|
+
# Miscellaneous Modules
|
17
|
+
# Independed and LinuxStat's miscellaneous modules
|
2
18
|
require "linux_stat/version"
|
3
19
|
require 'linux_stat/prettify_bytes'
|
4
20
|
|
5
|
-
# Independed
|
21
|
+
# Independed Modules
|
22
|
+
# Modules that doesn't have any dependency on its own
|
23
|
+
# But might be required by other module functions in "Dependent Modules" section
|
6
24
|
require "linux_stat/battery"
|
7
25
|
require "linux_stat/bios"
|
8
26
|
require "linux_stat/cpu"
|
@@ -11,6 +29,9 @@ require "linux_stat/net"
|
|
11
29
|
require "linux_stat/process"
|
12
30
|
require "linux_stat/swap"
|
13
31
|
|
32
|
+
# Dependent Modules
|
33
|
+
# Modules that can have reverse dependency
|
34
|
+
|
14
35
|
# LinuxStat::Uname dependent modules
|
15
36
|
require 'linux_stat/utsname'
|
16
37
|
require "linux_stat/os"
|
data/lib/linux_stat/net.rb
CHANGED
@@ -1,13 +1,119 @@
|
|
1
1
|
module LinuxStat
|
2
2
|
module Net
|
3
3
|
class << self
|
4
|
+
DEV = '/proc/net/dev'.freeze
|
4
5
|
# Returns the local IP address of the system as a String.
|
5
6
|
# If the information isn't available, it will a frozen empty string.
|
6
7
|
def ipv4_private
|
7
|
-
require 'socket'
|
8
|
+
require 'socket' unless defined?(Socket)
|
8
9
|
ip = Socket.ip_address_list.find(&:ipv4_private?)
|
9
10
|
ip ? ip.ip? ? ip.ip_unpack[0].freeze : ''.freeze : ''.freeze
|
10
11
|
end
|
12
|
+
|
13
|
+
# Returns the total bytes received and transmitted as Hash.
|
14
|
+
# For example:
|
15
|
+
# {:received=>56602867, :transmitted=>6940922}
|
16
|
+
#
|
17
|
+
# But if the status isn't available it will return an empty Hash.
|
18
|
+
def total_bytes
|
19
|
+
return {} unless File.readable?(DEV)
|
20
|
+
|
21
|
+
data = IO.readlines(DEV).drop(2)
|
22
|
+
indices = find_index_of_bytes
|
23
|
+
data.reject! { |x| x.strip.start_with?('lo:') }
|
24
|
+
r, t = data.map { |x| x.split.values_at(*indices).map(&:to_i) }.transpose.map(&:sum)
|
25
|
+
|
26
|
+
{
|
27
|
+
received: r,
|
28
|
+
transmitted: t
|
29
|
+
}
|
30
|
+
end
|
31
|
+
|
32
|
+
# Returns the total bytes received as Integer.
|
33
|
+
#
|
34
|
+
# But if the status isn't available it will return nil.
|
35
|
+
def total_bytes_received
|
36
|
+
return nil unless File.readable?(DEV)
|
37
|
+
|
38
|
+
data = IO.readlines(DEV).drop(2)
|
39
|
+
index = find_index_of_bytes[0]
|
40
|
+
data.reject! { |x| x.strip.start_with?('lo:') }
|
41
|
+
data.map { |x| x.split[index].to_i }.sum
|
42
|
+
end
|
43
|
+
|
44
|
+
# Returns the total bytes transmitted as Integer.
|
45
|
+
#
|
46
|
+
# But if the status isn't available it will return nil.
|
47
|
+
def total_bytes_transmitted
|
48
|
+
return nil unless File.readable?(DEV)
|
49
|
+
|
50
|
+
data = IO.readlines(DEV).drop(2)
|
51
|
+
index = find_index_of_bytes[-1]
|
52
|
+
data.reject! { |x| x.strip.start_with?('lo:') }
|
53
|
+
data.map { |x| x.split[index].to_i }.sum
|
54
|
+
end
|
55
|
+
|
56
|
+
# usage(interval = 0.1)
|
57
|
+
# Where interval is the time between polling in seconds. The default is 0.1 seconds.
|
58
|
+
#
|
59
|
+
# The return type is a Hash, containg the current internet usage (received, transmit) in B/s.
|
60
|
+
#
|
61
|
+
# For example:
|
62
|
+
# {:received=>436060.0, :transmitted=>50350.0}
|
63
|
+
#
|
64
|
+
# If the system transmits 100 kb in the interval,
|
65
|
+
# this method will return 1000 kb/s. That is, it estimates
|
66
|
+
# the data it will transmit in one second. Thus, a good and reliable interval is 1 second
|
67
|
+
# It will return an empty Hash if the info (/proc/net/dev) isn't available.
|
68
|
+
def usage(interval = 0.1)
|
69
|
+
return {} unless File.readable?(DEV)
|
70
|
+
|
71
|
+
data = IO.readlines(DEV).drop(2)
|
72
|
+
indices = find_index_of_bytes
|
73
|
+
data.reject! { |x| x.strip.start_with?('lo:') }
|
74
|
+
r, t = data.map { |x| x.split.values_at(*indices).map(&:to_i) }.transpose.map(&:sum)
|
75
|
+
|
76
|
+
sleep(interval)
|
77
|
+
|
78
|
+
data2 = IO.readlines(DEV).drop(2)
|
79
|
+
data2.reject! { |x| x.strip.start_with?('lo:') }
|
80
|
+
r2, t2 = data2.map { |x| x.split.values_at(*indices).map(&:to_i) }.transpose.map(&:sum)
|
81
|
+
|
82
|
+
# Measure the difference
|
83
|
+
dr, dt = r2.-(r).fdiv(interval), t2.-(t).fdiv(interval)
|
84
|
+
|
85
|
+
{
|
86
|
+
received: dr,
|
87
|
+
transmitted: dt
|
88
|
+
}
|
89
|
+
end
|
90
|
+
|
91
|
+
alias current_usage usage
|
92
|
+
|
93
|
+
private
|
94
|
+
# Returns the index containing the received and transmitted bytes
|
95
|
+
def find_index_of_bytes
|
96
|
+
@@index_of_bytes ||= nil
|
97
|
+
|
98
|
+
unless @@index_of_bytes
|
99
|
+
data = IO.foreach(DEV)
|
100
|
+
|
101
|
+
r, h = data.next.split, {}
|
102
|
+
|
103
|
+
r.each_with_index { |x, i|
|
104
|
+
downcased = x.downcase
|
105
|
+
h.merge!(:r => i) if downcased.start_with?('receive')
|
106
|
+
h.merge!(:t => i) if downcased.start_with?('transmit')
|
107
|
+
}
|
108
|
+
|
109
|
+
data_0 = data.next.gsub(?|.freeze, ' %'.freeze)
|
110
|
+
@@index_of_bytes = []
|
111
|
+
data_0.split.each_with_index { |x, i| @@index_of_bytes << i if x == '%bytes'.freeze }
|
112
|
+
h[:r] > h[:t] ? @@index_of_bytes.reverse : @@index_of_bytes
|
113
|
+
else
|
114
|
+
@@index_of_bytes
|
115
|
+
end
|
116
|
+
end
|
11
117
|
end
|
12
118
|
end
|
13
119
|
end
|
@@ -86,12 +86,9 @@ module LinuxStat
|
|
86
86
|
# If the info isn't available it will return an empty Hash.
|
87
87
|
def mem_stat(pid = $$)
|
88
88
|
statm = "/proc/#{pid}/statm".freeze
|
89
|
+
return {} unless File.readable?(statm)
|
89
90
|
|
90
|
-
data =
|
91
|
-
IO.read(statm).split
|
92
|
-
else
|
93
|
-
return {}
|
94
|
-
end
|
91
|
+
data = IO.read(statm).split
|
95
92
|
|
96
93
|
_rss_anon = (data[1] && data[2]) ? data[1].to_i.-(data[2].to_i).*(pagesize).fdiv(1000) : nil
|
97
94
|
_virtual_memory = data[0] ? data[0].to_i*(pagesize).fdiv(1000) : nil
|
data/lib/linux_stat/version.rb
CHANGED