process-metrics 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +12 -0
- data/.rspec +3 -0
- data/.travis.yml +22 -0
- data/Gemfile +4 -0
- data/Gemfile.lock +73 -0
- data/README.md +127 -0
- data/Rakefile +6 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/lib/process/metrics.rb +22 -0
- data/lib/process/metrics/general.rb +132 -0
- data/lib/process/metrics/memory.rb +78 -0
- data/lib/process/metrics/version.rb +27 -0
- data/process-metrics.gemspec +30 -0
- metadata +116 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 408d8c161d78bec40dbec084cbfa7d145a9fb9cddde7ee0eb6bf8b6c0cb407a8
|
4
|
+
data.tar.gz: 81a6c24105ef52d4c486e0e54c7bca0714eb1c0fb012b4bef8009ce1f18e5c56
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: ff31a9c60ecb9dc2f06520b3aa043a481be9a6b0529e93343ea6a580167b6dff8eeae68d45ea3604c4db48dc393bc2cebe6b499e1c7926fafcb4d175bac82293
|
7
|
+
data.tar.gz: ce6f3420c752a642d9da9b18ffeb6691f1172406595b5c051e32590b6f1b64d772785041464b42084549ab1ee41117599168a480cce5ee6b429d60f578c3c9a0
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
language: ruby
|
2
|
+
dist: xenial
|
3
|
+
cache: bundler
|
4
|
+
|
5
|
+
matrix:
|
6
|
+
include:
|
7
|
+
- rvm: 2.4
|
8
|
+
- rvm: 2.5
|
9
|
+
- rvm: 2.6
|
10
|
+
- rvm: 2.6
|
11
|
+
env: COVERAGE=PartialSummary,Coveralls
|
12
|
+
- rvm: 2.7
|
13
|
+
- rvm: truffleruby
|
14
|
+
- rvm: jruby-head
|
15
|
+
- rvm: ruby-head
|
16
|
+
- rvm: 2.7
|
17
|
+
os: osx
|
18
|
+
allow_failures:
|
19
|
+
- rvm: truffleruby
|
20
|
+
- rvm: ruby-head
|
21
|
+
- rvm: jruby-head
|
22
|
+
- rvm: truffleruby
|
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,73 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
process-metrics (0.1.0)
|
5
|
+
|
6
|
+
GEM
|
7
|
+
remote: https://rubygems.org/
|
8
|
+
specs:
|
9
|
+
ast (2.4.0)
|
10
|
+
async (1.24.1)
|
11
|
+
console (~> 1.0)
|
12
|
+
nio4r (~> 2.3)
|
13
|
+
timers (~> 4.1)
|
14
|
+
async-http (0.50.0)
|
15
|
+
async (~> 1.23)
|
16
|
+
async-io (~> 1.27.0)
|
17
|
+
async-pool (~> 0.2)
|
18
|
+
protocol-http (~> 0.13.0)
|
19
|
+
protocol-http1 (~> 0.10.0)
|
20
|
+
protocol-http2 (~> 0.10.0)
|
21
|
+
async-io (1.27.1)
|
22
|
+
async (~> 1.14)
|
23
|
+
async-pool (0.2.0)
|
24
|
+
async (~> 1.8)
|
25
|
+
async-rest (0.12.1)
|
26
|
+
async-http (~> 0.42)
|
27
|
+
protocol-http (~> 0.7)
|
28
|
+
console (1.7.0)
|
29
|
+
covered (0.13.1)
|
30
|
+
async-rest
|
31
|
+
console (~> 1.0)
|
32
|
+
msgpack
|
33
|
+
parser
|
34
|
+
diff-lcs (1.3)
|
35
|
+
msgpack (1.3.1)
|
36
|
+
nio4r (2.5.2)
|
37
|
+
parser (2.7.0.0)
|
38
|
+
ast (~> 2.4.0)
|
39
|
+
protocol-hpack (1.4.1)
|
40
|
+
protocol-http (0.13.0)
|
41
|
+
protocol-http1 (0.10.0)
|
42
|
+
protocol-http (~> 0.13)
|
43
|
+
protocol-http2 (0.10.4)
|
44
|
+
protocol-hpack (~> 1.4)
|
45
|
+
protocol-http (~> 0.2)
|
46
|
+
rake (12.3.3)
|
47
|
+
rspec (3.9.0)
|
48
|
+
rspec-core (~> 3.9.0)
|
49
|
+
rspec-expectations (~> 3.9.0)
|
50
|
+
rspec-mocks (~> 3.9.0)
|
51
|
+
rspec-core (3.9.1)
|
52
|
+
rspec-support (~> 3.9.1)
|
53
|
+
rspec-expectations (3.9.0)
|
54
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
55
|
+
rspec-support (~> 3.9.0)
|
56
|
+
rspec-mocks (3.9.0)
|
57
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
58
|
+
rspec-support (~> 3.9.0)
|
59
|
+
rspec-support (3.9.1)
|
60
|
+
timers (4.3.0)
|
61
|
+
|
62
|
+
PLATFORMS
|
63
|
+
ruby
|
64
|
+
|
65
|
+
DEPENDENCIES
|
66
|
+
bundler
|
67
|
+
covered
|
68
|
+
process-metrics!
|
69
|
+
rake (~> 12.0)
|
70
|
+
rspec (~> 3.8)
|
71
|
+
|
72
|
+
BUNDLED WITH
|
73
|
+
2.1.2
|
data/README.md
ADDED
@@ -0,0 +1,127 @@
|
|
1
|
+
# Process::Metrics
|
2
|
+
|
3
|
+
Extract performance and memory metrics from running processes.
|
4
|
+
|
5
|
+
[![Build Status](https://travis-ci.com/socketry/process-metrics.svg)](https://travis-ci.com/socketry/process-metrics)
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
|
9
|
+
To add it to your current project:
|
10
|
+
|
11
|
+
bundle add process-metrics
|
12
|
+
|
13
|
+
## Usage
|
14
|
+
|
15
|
+
Memory is measured in kilobytes and time is measured in seconds.
|
16
|
+
|
17
|
+
### Capturing for specific PID
|
18
|
+
|
19
|
+
```ruby
|
20
|
+
#!/usr/bin/env ruby
|
21
|
+
|
22
|
+
require 'process/metrics'
|
23
|
+
|
24
|
+
metrics = Process::Metrics.capture(pid: Process.pid)
|
25
|
+
|
26
|
+
pp metrics
|
27
|
+
# [{:pid=>68536,
|
28
|
+
# :ppid=>46295,
|
29
|
+
# :pgid=>68536,
|
30
|
+
# :pcpu=>0.0,
|
31
|
+
# :time=>0,
|
32
|
+
# :vsz=>94516,
|
33
|
+
# :rss=>29688,
|
34
|
+
# :etime=>41057,
|
35
|
+
# :command=>
|
36
|
+
# "/home/samuel/.rbenv/versions/2.7.0/bin/ruby /home/samuel/.rbenv/versions/2.7.0/bin/falcon-host ./falcon.rb",
|
37
|
+
# :memory=>
|
38
|
+
# {:total=>94520,
|
39
|
+
# :rss=>29696,
|
40
|
+
# :pss=>8912,
|
41
|
+
# :shared_clean=>9528,
|
42
|
+
# :shared_dirty=>14588,
|
43
|
+
# :private_clean=>924,
|
44
|
+
# :private_dirty=>4656,
|
45
|
+
# :referenced=>29696,
|
46
|
+
# :anonymous=>19244,
|
47
|
+
# :swap=>0,
|
48
|
+
# :swap_pss=>0,
|
49
|
+
# :maps=>294}},
|
50
|
+
# {:pid=>68558,
|
51
|
+
# :ppid=>68536,
|
52
|
+
# :pgid=>68558,
|
53
|
+
# :pcpu=>0.0,
|
54
|
+
# :time=>0,
|
55
|
+
# :vsz=>94516,
|
56
|
+
# :rss=>23612,
|
57
|
+
# :etime=>41057,
|
58
|
+
# :command=>"supervisor",
|
59
|
+
# :memory=>
|
60
|
+
# {:total=>94520,
|
61
|
+
# :rss=>23612,
|
62
|
+
# :pss=>7551,
|
63
|
+
# :shared_clean=>4416,
|
64
|
+
# :shared_dirty=>14448,
|
65
|
+
# :private_clean=>0,
|
66
|
+
# :private_dirty=>4748,
|
67
|
+
# :referenced=>11184,
|
68
|
+
# :anonymous=>19196,
|
69
|
+
# :swap=>0,
|
70
|
+
# :swap_pss=>0,
|
71
|
+
# :maps=>294}},
|
72
|
+
# {:pid=>68559,
|
73
|
+
# :ppid=>68536,
|
74
|
+
# :pgid=>68558,
|
75
|
+
# :pcpu=>0.0,
|
76
|
+
# :time=>0,
|
77
|
+
# :vsz=>95000,
|
78
|
+
# :rss=>25136,
|
79
|
+
# :etime=>41057,
|
80
|
+
# :command=>"Falcon Host for hello.localhost",
|
81
|
+
# :memory=>
|
82
|
+
# {:total=>95004,
|
83
|
+
# :rss=>25136,
|
84
|
+
# :pss=>9308,
|
85
|
+
# :shared_clean=>5504,
|
86
|
+
# :shared_dirty=>11784,
|
87
|
+
# :private_clean=>0,
|
88
|
+
# :private_dirty=>7848,
|
89
|
+
# :referenced=>17596,
|
90
|
+
# :anonymous=>19632,
|
91
|
+
# :swap=>0,
|
92
|
+
# :swap_pss=>0,
|
93
|
+
# :maps=>295}},
|
94
|
+
# ... snip ...
|
95
|
+
```
|
96
|
+
|
97
|
+
## Contributing
|
98
|
+
|
99
|
+
1. Fork it
|
100
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
101
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
102
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
103
|
+
5. Create new Pull Request
|
104
|
+
|
105
|
+
## License
|
106
|
+
|
107
|
+
Released under the MIT license.
|
108
|
+
|
109
|
+
Copyright, 2019, by [Samuel G. D. Williams](https://www.codeotaku.com).
|
110
|
+
|
111
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
112
|
+
of this software and associated documentation files (the "Software"), to deal
|
113
|
+
in the Software without restriction, including without limitation the rights
|
114
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
115
|
+
copies of the Software, and to permit persons to whom the Software is
|
116
|
+
furnished to do so, subject to the following conditions:
|
117
|
+
|
118
|
+
The above copyright notice and this permission notice shall be included in
|
119
|
+
all copies or substantial portions of the Software.
|
120
|
+
|
121
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
122
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
123
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
124
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
125
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
126
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
127
|
+
THE SOFTWARE.
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "process/metrics"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start(__FILE__)
|
data/bin/setup
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
# Copyright, 2019, by Samuel G. D. Williams. <https://www.codeotaku.com>
|
2
|
+
#
|
3
|
+
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
4
|
+
# of this software and associated documentation files (the "Software"), to deal
|
5
|
+
# in the Software without restriction, including without limitation the rights
|
6
|
+
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
7
|
+
# copies of the Software, and to permit persons to whom the Software is
|
8
|
+
# furnished to do so, subject to the following conditions:
|
9
|
+
#
|
10
|
+
# The above copyright notice and this permission notice shall be included in
|
11
|
+
# all copies or substantial portions of the Software.
|
12
|
+
#
|
13
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
14
|
+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
15
|
+
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
16
|
+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
17
|
+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
18
|
+
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
19
|
+
# THE SOFTWARE.
|
20
|
+
|
21
|
+
require_relative "metrics/version"
|
22
|
+
require_relative "metrics/general"
|
@@ -0,0 +1,132 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# Copyright, 2019, by Samuel G. D. Williams. <https://www.codeotaku.com>
|
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.
|
22
|
+
|
23
|
+
require_relative 'memory'
|
24
|
+
require 'set'
|
25
|
+
|
26
|
+
module Process
|
27
|
+
module Metrics
|
28
|
+
PS = "ps"
|
29
|
+
|
30
|
+
# According to the linux manual page specifications.
|
31
|
+
def self.duration(value)
|
32
|
+
if /((?<days>\d\d)\-)?((?<hours>\d\d):)?(?<minutes>\d\d):(?<seconds>\d\d)?/ =~ value
|
33
|
+
(((days&.to_i || 0) * 24 + (hours&.to_i || 0)) * 60 + (minutes&.to_i || 0)) * 60 + seconds&.to_i
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
# pid: Process Identifier
|
38
|
+
# pmem: Percentage Memory used.
|
39
|
+
# pcpu: Percentage Processor used.
|
40
|
+
# time: The process time used (executing on CPU).
|
41
|
+
# vsz: Virtual Size in kilobytes
|
42
|
+
# rss: Resident Set Size in kilobytes
|
43
|
+
# etime: The process elapsed time.
|
44
|
+
# command: The name of the process.
|
45
|
+
FIELDS = {
|
46
|
+
pid: ->(value){value.to_i},
|
47
|
+
ppid: ->(value){value.to_i},
|
48
|
+
pgid: ->(value){value.to_i},
|
49
|
+
pcpu: ->(value){value.to_f},
|
50
|
+
time: self.method(:duration),
|
51
|
+
vsz: ->(value){value.to_i},
|
52
|
+
rss: ->(value){value.to_i},
|
53
|
+
etime: self.method(:duration),
|
54
|
+
command: ->(value){value},
|
55
|
+
}
|
56
|
+
|
57
|
+
def self.set(ids)
|
58
|
+
Set.new(Array(ids))
|
59
|
+
end
|
60
|
+
|
61
|
+
def self.expand_children(children, hierarchy, pids)
|
62
|
+
children.each do |pid|
|
63
|
+
self.expand(pid, hierarchy, pids)
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
def self.expand(pid, hierarchy, pids)
|
68
|
+
unless pids.include?(pid)
|
69
|
+
pids << pid
|
70
|
+
|
71
|
+
if children = hierarchy.fetch(pid, nil)
|
72
|
+
self.expand_children(children, hierarchy, pids)
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
def self.capture(pid: nil, ppid: nil, ps: PS, fields: FIELDS)
|
78
|
+
input, output = IO.pipe
|
79
|
+
|
80
|
+
arguments = [ps]
|
81
|
+
|
82
|
+
if pid && ppid.nil?
|
83
|
+
arguments.push("-p", Array(pid).join(','))
|
84
|
+
else
|
85
|
+
arguments.push("ax")
|
86
|
+
end
|
87
|
+
|
88
|
+
arguments.push("-o", fields.keys.join(','))
|
89
|
+
|
90
|
+
child_pid = Process.spawn(*arguments, out: output, pgroup: true)
|
91
|
+
|
92
|
+
output.close
|
93
|
+
|
94
|
+
header, *lines = input.readlines.map(&:strip)
|
95
|
+
|
96
|
+
processes = lines.map do |line|
|
97
|
+
fields.
|
98
|
+
zip(line.split(/\s+/, fields.size)).
|
99
|
+
map{|(key, type), value| [key, type.call(value)]}.
|
100
|
+
to_h
|
101
|
+
end
|
102
|
+
|
103
|
+
if ppid
|
104
|
+
pids = Set.new
|
105
|
+
hierarchy = Hash.new{|h,k| h[k] = []}
|
106
|
+
|
107
|
+
processes.each do |process|
|
108
|
+
hierarchy[process[:ppid]] << process[:pid]
|
109
|
+
end
|
110
|
+
|
111
|
+
self.expand_children(Array(pid), hierarchy, pids)
|
112
|
+
self.expand_children(Array(ppid), hierarchy, pids)
|
113
|
+
|
114
|
+
processes.select! do |process|
|
115
|
+
pids.include?(process[:pid])
|
116
|
+
end
|
117
|
+
end
|
118
|
+
|
119
|
+
if Memory.supported?
|
120
|
+
processes.each do |process|
|
121
|
+
if pid = process[:pid]
|
122
|
+
process[:memory] = Memory.capture(Array(process[:pid]))
|
123
|
+
end
|
124
|
+
end
|
125
|
+
end
|
126
|
+
|
127
|
+
return processes
|
128
|
+
ensure
|
129
|
+
Process.wait(child_pid) if child_pid
|
130
|
+
end
|
131
|
+
end
|
132
|
+
end
|
@@ -0,0 +1,78 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# Copyright, 2019, by Samuel G. D. Williams. <https://www.codeotaku.com>
|
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.
|
22
|
+
|
23
|
+
module Process
|
24
|
+
module Metrics
|
25
|
+
module Memory
|
26
|
+
if File.readable?('/proc/self/smaps')
|
27
|
+
def self.supported?
|
28
|
+
true
|
29
|
+
end
|
30
|
+
|
31
|
+
MAP = {
|
32
|
+
"Size" => :total,
|
33
|
+
"Rss" => :rss,
|
34
|
+
"Pss" => :pss,
|
35
|
+
"Shared_Clean" => :shared_clean,
|
36
|
+
"Shared_Dirty" => :shared_dirty,
|
37
|
+
"Private_Clean" => :private_clean,
|
38
|
+
"Private_Dirty" => :private_dirty,
|
39
|
+
"Referenced" => :referenced,
|
40
|
+
"Anonymous" => :anonymous,
|
41
|
+
"Swap" => :swap,
|
42
|
+
"SwapPss" => :swap_pss,
|
43
|
+
}
|
44
|
+
|
45
|
+
def self.capture(pids)
|
46
|
+
usage = Hash.new{|h,k| h[k] = 0}
|
47
|
+
|
48
|
+
pids.each do |pid|
|
49
|
+
if lines = File.readlines("/proc/#{pid}/smaps")
|
50
|
+
lines.each do |line|
|
51
|
+
# The format of this is fixed according to:
|
52
|
+
# https://github.com/torvalds/linux/blob/351c8a09b00b5c51c8f58b016fffe51f87e2d820/fs/proc/task_mmu.c#L804-L814
|
53
|
+
if /(?<name>.*?):\s+(?<value>\d+) kB/ =~ line
|
54
|
+
if key = MAP[name]
|
55
|
+
usage[key] += value.to_i
|
56
|
+
end
|
57
|
+
elsif /VmFlags:\s+(?<flags>.*)/ =~ line
|
58
|
+
# It should be possible to extract the number of fibers and each fiber's memory usage.
|
59
|
+
# flags = flags.split(/\s+/)
|
60
|
+
usage[:maps] += 1
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
return usage.freeze
|
67
|
+
end
|
68
|
+
else
|
69
|
+
def self.supported?
|
70
|
+
false
|
71
|
+
end
|
72
|
+
|
73
|
+
def self.capture(pids)
|
74
|
+
end
|
75
|
+
end
|
76
|
+
end
|
77
|
+
end
|
78
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# Copyright, 2019, by Samuel G. D. Williams. <https://www.codeotaku.com>
|
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.
|
22
|
+
|
23
|
+
module Process
|
24
|
+
module Metrics
|
25
|
+
VERSION = "0.1.0"
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
require_relative 'lib/process/metrics/version'
|
2
|
+
|
3
|
+
Gem::Specification.new do |spec|
|
4
|
+
spec.name = "process-metrics"
|
5
|
+
spec.version = Process::Metrics::VERSION
|
6
|
+
spec.authors = ["Samuel Williams"]
|
7
|
+
spec.email = ["samuel.williams@oriontransfer.co.nz"]
|
8
|
+
|
9
|
+
spec.summary = "Provide detailed OS-specific process metrics."
|
10
|
+
spec.homepage = "https://github.com/socketry/process-metrics"
|
11
|
+
spec.license = "MIT"
|
12
|
+
|
13
|
+
spec.required_ruby_version = Gem::Requirement.new(">= 2.3.0")
|
14
|
+
|
15
|
+
spec.metadata["funding_uri"] = "https://github.com/sponsors/ioquatix"
|
16
|
+
|
17
|
+
# Specify which files should be added to the gem when it is released.
|
18
|
+
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
19
|
+
spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
|
20
|
+
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
21
|
+
end
|
22
|
+
|
23
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
24
|
+
spec.require_paths = ["lib"]
|
25
|
+
|
26
|
+
spec.add_development_dependency "covered"
|
27
|
+
spec.add_development_dependency "bundler"
|
28
|
+
spec.add_development_dependency "rake", "~> 12.0"
|
29
|
+
spec.add_development_dependency "rspec", "~> 3.8"
|
30
|
+
end
|
metadata
ADDED
@@ -0,0 +1,116 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: process-metrics
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Samuel Williams
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2019-12-30 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: covered
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: bundler
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rake
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '12.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '12.0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rspec
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '3.8'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '3.8'
|
69
|
+
description:
|
70
|
+
email:
|
71
|
+
- samuel.williams@oriontransfer.co.nz
|
72
|
+
executables:
|
73
|
+
- console
|
74
|
+
- setup
|
75
|
+
extensions: []
|
76
|
+
extra_rdoc_files: []
|
77
|
+
files:
|
78
|
+
- ".gitignore"
|
79
|
+
- ".rspec"
|
80
|
+
- ".travis.yml"
|
81
|
+
- Gemfile
|
82
|
+
- Gemfile.lock
|
83
|
+
- README.md
|
84
|
+
- Rakefile
|
85
|
+
- bin/console
|
86
|
+
- bin/setup
|
87
|
+
- lib/process/metrics.rb
|
88
|
+
- lib/process/metrics/general.rb
|
89
|
+
- lib/process/metrics/memory.rb
|
90
|
+
- lib/process/metrics/version.rb
|
91
|
+
- process-metrics.gemspec
|
92
|
+
homepage: https://github.com/socketry/process-metrics
|
93
|
+
licenses:
|
94
|
+
- MIT
|
95
|
+
metadata:
|
96
|
+
funding_uri: https://github.com/sponsors/ioquatix
|
97
|
+
post_install_message:
|
98
|
+
rdoc_options: []
|
99
|
+
require_paths:
|
100
|
+
- lib
|
101
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
102
|
+
requirements:
|
103
|
+
- - ">="
|
104
|
+
- !ruby/object:Gem::Version
|
105
|
+
version: 2.3.0
|
106
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - ">="
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '0'
|
111
|
+
requirements: []
|
112
|
+
rubygems_version: 3.1.2
|
113
|
+
signing_key:
|
114
|
+
specification_version: 4
|
115
|
+
summary: Provide detailed OS-specific process metrics.
|
116
|
+
test_files: []
|