corn 0.4.4 → 0.4.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -7
- data/lib/corn/post.rb +8 -4
- data/lib/corn/rack/request_env.rb +37 -0
- data/lib/corn/rack/slow_request_profiler.rb +10 -8
- metadata +53 -48
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
|
-
---
|
2
|
-
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
5
|
-
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 07429dba6e4008f4bcb1eff01f06684408a24a36
|
4
|
+
data.tar.gz: ef59195398f1c04a798ec93ba534fbe8894f6df0
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 5408556f99f1bc880d2843348044a4b8d281569d0d5b558e4cf57ea2c63fc2babdf86e792acf126a73043a4c9e04f3b816a95664b413674fd280b21fd1024c75
|
7
|
+
data.tar.gz: 7c21f7658fd447eae5c46fd42ab5bff705a536571051f59ac92c33d6b65b2e0311344ef1e018fc9ea0e9386ea1768f03e67626c3ca2c3d461bec33d158416df0
|
data/lib/corn/post.rb
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
require 'net/http'
|
2
2
|
require 'net/https'
|
3
3
|
require 'thread'
|
4
|
+
require 'time'
|
4
5
|
|
5
6
|
module Corn
|
6
7
|
class Post
|
@@ -26,14 +27,17 @@ module Corn
|
|
26
27
|
end
|
27
28
|
end
|
28
29
|
|
29
|
-
def enqueue(
|
30
|
-
@queue <<
|
30
|
+
def enqueue(*args)
|
31
|
+
@queue << args
|
31
32
|
end
|
32
33
|
|
33
|
-
def http_post(data, name)
|
34
|
+
def http_post(data, name, start_time)
|
34
35
|
uri = URI.parse(submit_url)
|
35
36
|
req = Net::HTTP::Post.new(uri.path)
|
36
|
-
req.set_form_data("data" => data,
|
37
|
+
req.set_form_data("data" => data,
|
38
|
+
'client_id' => Corn.client_id,
|
39
|
+
'name' => name,
|
40
|
+
'start_time' => start_time.iso8601)
|
37
41
|
|
38
42
|
http = Net::HTTP.new(uri.host, uri.port)
|
39
43
|
if uri.scheme == 'https'
|
@@ -0,0 +1,37 @@
|
|
1
|
+
module Corn
|
2
|
+
module Rack
|
3
|
+
class RequestEnv
|
4
|
+
def initialize(threshold)
|
5
|
+
@threshold = threshold
|
6
|
+
end
|
7
|
+
|
8
|
+
def record(env, &block)
|
9
|
+
Thread.current['corn_path_info'] = env['PATH_INFO']
|
10
|
+
Thread.current['corn_http_host'] = env['HTTP_HOST']
|
11
|
+
Thread.current['corn_start_time'] = Time.now
|
12
|
+
yield
|
13
|
+
ensure
|
14
|
+
Thread.current['corn_path_info'] = nil
|
15
|
+
Thread.current['corn_http_host'] = nil
|
16
|
+
Thread.current['corn_start_time'] = nil
|
17
|
+
end
|
18
|
+
|
19
|
+
def start_time
|
20
|
+
Thread.current['corn_start_time']
|
21
|
+
end
|
22
|
+
|
23
|
+
def time
|
24
|
+
Time.now - start_time
|
25
|
+
end
|
26
|
+
|
27
|
+
def slow_request?
|
28
|
+
time > @threshold
|
29
|
+
end
|
30
|
+
|
31
|
+
def report_name
|
32
|
+
File.join(*[Thread.current['corn_http_host'],
|
33
|
+
Thread.current['corn_path_info']].compact)
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
@@ -1,28 +1,30 @@
|
|
1
1
|
require 'corn/post'
|
2
|
+
require 'corn/rack/request_env'
|
2
3
|
require 'sampling_prof'
|
3
4
|
|
4
5
|
module Corn
|
5
6
|
module Rack
|
6
7
|
class SlowRequestProfiler
|
7
8
|
def initialize(app,
|
8
|
-
|
9
|
+
slow_request_threshold=5,
|
9
10
|
sampling_interval=0.1)
|
10
11
|
@app = app
|
11
12
|
@post = Post.new
|
13
|
+
@request_env = RequestEnv.new(slow_request_threshold)
|
12
14
|
@prof = SamplingProf.new(sampling_interval) do |data|
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
15
|
+
if @request_env.slow_request?
|
16
|
+
@post.enqueue(data,
|
17
|
+
@request_env.report_name,
|
18
|
+
@request_env.start_time)
|
17
19
|
end
|
18
20
|
end
|
19
21
|
at_exit { terminate }
|
20
22
|
end
|
21
23
|
|
22
24
|
def call(env)
|
23
|
-
|
24
|
-
|
25
|
-
|
25
|
+
@request_env.record(env) do
|
26
|
+
@prof.profile { @app.call(env) }
|
27
|
+
end
|
26
28
|
end
|
27
29
|
|
28
30
|
def terminate
|
metadata
CHANGED
@@ -1,65 +1,70 @@
|
|
1
|
-
--- !ruby/object:Gem::Specification
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
2
|
name: corn
|
3
|
-
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.4.
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.4.5
|
5
5
|
platform: ruby
|
6
|
-
authors:
|
7
|
-
- Xiao Li
|
8
|
-
autorequire:
|
6
|
+
authors:
|
7
|
+
- Xiao Li
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
version: '0.4'
|
25
|
-
prerelease: false
|
26
|
-
type: :runtime
|
11
|
+
|
12
|
+
date: 2014-06-18 00:00:00 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: sampling_prof
|
16
|
+
prerelease: false
|
17
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
18
|
+
requirements:
|
19
|
+
- - ">="
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: "0.4"
|
22
|
+
type: :runtime
|
23
|
+
version_requirements: *id001
|
27
24
|
description: |
|
28
25
|
Corn collects your application's profiling data by sampling_prof gem, and submits the result to server, so that you can merge multiple server's profiling data and do analysis together.
|
29
|
-
|
30
|
-
|
26
|
+
|
27
|
+
email:
|
28
|
+
- swing1979@gmail.com
|
31
29
|
executables: []
|
30
|
+
|
32
31
|
extensions: []
|
32
|
+
|
33
33
|
extra_rdoc_files: []
|
34
|
-
|
35
|
-
|
36
|
-
-
|
37
|
-
- lib/corn
|
38
|
-
- lib/corn/
|
39
|
-
- lib/corn/
|
40
|
-
- lib/corn/rack
|
34
|
+
|
35
|
+
files:
|
36
|
+
- README.md
|
37
|
+
- lib/corn.rb
|
38
|
+
- lib/corn/config.rb
|
39
|
+
- lib/corn/post.rb
|
40
|
+
- lib/corn/rack.rb
|
41
|
+
- lib/corn/rack/request_env.rb
|
42
|
+
- lib/corn/rack/slow_request_profiler.rb
|
41
43
|
homepage: https://github.com/xli/corn
|
42
|
-
licenses:
|
43
|
-
- MIT
|
44
|
+
licenses:
|
45
|
+
- MIT
|
44
46
|
metadata: {}
|
45
|
-
|
47
|
+
|
48
|
+
post_install_message:
|
46
49
|
rdoc_options: []
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
50
|
+
|
51
|
+
require_paths:
|
52
|
+
- lib
|
53
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
54
|
+
requirements:
|
55
|
+
- &id002
|
56
|
+
- ">="
|
57
|
+
- !ruby/object:Gem::Version
|
58
|
+
version: "0"
|
59
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
60
|
+
requirements:
|
61
|
+
- *id002
|
59
62
|
requirements: []
|
60
|
-
|
63
|
+
|
64
|
+
rubyforge_project:
|
61
65
|
rubygems_version: 2.1.9
|
62
|
-
signing_key:
|
66
|
+
signing_key:
|
63
67
|
specification_version: 4
|
64
68
|
summary: Corn submits profiling data to Corn server.
|
65
69
|
test_files: []
|
70
|
+
|