proceso-rails 0.2.1 → 0.2.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/proceso/middleware.rb +8 -10
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ca1730839e3a56e64a0fa39483d1df2f31b70a60
|
4
|
+
data.tar.gz: e63dbca299acbaae43df058395c602b6bfc11465
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6744cae6d910fc86dda8837cf86fe48ed9ef1180c1e6dfc4a64d3e291af8839287162b522215c813a93e4216a68d75e45bff4ba53e9a19ecdd148450dc89a5a1
|
7
|
+
data.tar.gz: 95ddbc9ad62aea0c3dee489aa49718eb7a4ef7b95c63ad5449f897cf2f21aa1fa109679e93337695096d51cfbc8bfe3b124c9a4008c2db8c745e5fb579ad5c4a
|
data/lib/proceso/middleware.rb
CHANGED
@@ -1,3 +1,4 @@
|
|
1
|
+
require 'proceso/version'
|
1
2
|
require 'rack'
|
2
3
|
|
3
4
|
module Proceso
|
@@ -23,7 +24,7 @@ module Proceso
|
|
23
24
|
end
|
24
25
|
|
25
26
|
def logger
|
26
|
-
|
27
|
+
@logger ||= begin
|
27
28
|
Rails.configuration.logger || ActiveSupport::Logger.new(STDOUT)
|
28
29
|
end
|
29
30
|
end
|
@@ -47,10 +48,11 @@ module Proceso
|
|
47
48
|
end
|
48
49
|
|
49
50
|
def capture_process_usage(env)
|
50
|
-
|
51
|
+
request = Rack::Request.new(env)
|
52
|
+
mem_1, cpu_1 = build_process_payload
|
51
53
|
response = yield
|
52
|
-
mem_2, cpu_2
|
53
|
-
process_payload =
|
54
|
+
mem_2, cpu_2 = build_process_payload
|
55
|
+
process_payload = calculate_process_usage(request, mem_1, mem_2, cpu_1, cpu_2)
|
54
56
|
notifier.instrument(SUBSCRIPTION, process_payload)
|
55
57
|
response
|
56
58
|
end
|
@@ -58,20 +60,16 @@ module Proceso
|
|
58
60
|
def build_process_payload
|
59
61
|
mem = process.mem_size
|
60
62
|
cpu = process.user_cpu_times
|
61
|
-
|
62
|
-
[mem, cpu, resp]
|
63
|
+
[mem, cpu]
|
63
64
|
end
|
64
65
|
|
65
|
-
def
|
66
|
+
def calculate_process_usage(req, m1, m2, c1, c2)
|
66
67
|
mem_used = m2 - m1
|
67
68
|
cpu_used = c2 - c2
|
68
|
-
resp_time = r2 - r1
|
69
|
-
req = Rack::Request.new(env)
|
70
69
|
{
|
71
70
|
pid: process.pid,
|
72
71
|
mem_used: mem_used,
|
73
72
|
cpu_used: cpu_used,
|
74
|
-
resp_time: resp_time,
|
75
73
|
request: req
|
76
74
|
}
|
77
75
|
end
|