x_runtime 0.1.0 → 0.2.0
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.
- data/Gemfile +0 -1
- data/Gemfile.lock +1 -5
- data/README.markdown +7 -1
- data/VERSION +1 -1
- data/lib/x_runtime/middleware.rb +8 -11
- data/lib/x_runtime/portal.rb +12 -0
- data/lib/x_runtime.rb +7 -6
- data/test/server.rb +10 -1
- data/x_runtime.gemspec +69 -0
- metadata +4 -18
data/Gemfile
CHANGED
data/Gemfile.lock
CHANGED
@@ -1,16 +1,13 @@
|
|
1
1
|
GEM
|
2
2
|
remote: http://ruby.taobao.org/
|
3
3
|
specs:
|
4
|
-
active_support (3.0.0)
|
5
|
-
activesupport (= 3.0.0)
|
6
|
-
activesupport (3.0.0)
|
7
4
|
git (1.2.5)
|
8
5
|
jeweler (1.8.4)
|
9
6
|
bundler (~> 1.0)
|
10
7
|
git (>= 1.2.5)
|
11
8
|
rake
|
12
9
|
rdoc
|
13
|
-
json (1.7.
|
10
|
+
json (1.7.5)
|
14
11
|
rack (1.4.1)
|
15
12
|
rake (0.9.2.2)
|
16
13
|
rdoc (3.12)
|
@@ -21,7 +18,6 @@ PLATFORMS
|
|
21
18
|
ruby
|
22
19
|
|
23
20
|
DEPENDENCIES
|
24
|
-
active_support
|
25
21
|
jeweler
|
26
22
|
rack
|
27
23
|
rake
|
data/README.markdown
CHANGED
@@ -26,7 +26,13 @@ XRuntime是一个Rack的middleware,配合Redis用来分析Http Server每个URI
|
|
26
26
|
2. redis对象
|
27
27
|
|
28
28
|
可以指定XRuntime使用的Redis的key前缀或者叫命名空间:
|
29
|
-
`XRuntime::NameSpace = "RuntimeEx::Threshold"`
|
29
|
+
`XRuntime::NameSpace = "RuntimeEx::Threshold"`
|
30
|
+
|
31
|
+
[http://localhost:4567/xruntime](/xruntime)支持Http basic auth验证:
|
32
|
+
|
33
|
+
use Rack::XRuntime, 100, Redis.connect(:url => "redis://localhost:6380/") do |name, password|
|
34
|
+
name == "cui" and password == "hello"
|
35
|
+
end
|
30
36
|
|
31
37
|
### Sinatra
|
32
38
|
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.
|
1
|
+
0.2.0
|
data/lib/x_runtime/middleware.rb
CHANGED
@@ -1,30 +1,28 @@
|
|
1
1
|
module XRuntime
|
2
2
|
class Middleware
|
3
3
|
# threshold => ms
|
4
|
-
def initialize(app, threshold, redis)
|
4
|
+
def initialize(app, threshold, redis, &auth)
|
5
5
|
@app = app
|
6
6
|
@threshold = threshold.to_f
|
7
7
|
@redis = redis
|
8
|
+
@portal = Portal.new(ds)
|
9
|
+
@portal = Rack::Auth::Basic.new(@portal, &auth) if block_given?
|
8
10
|
end
|
9
11
|
|
10
12
|
def ds
|
11
|
-
|
13
|
+
@ds ||= DataSet.new(redis_key, script)
|
12
14
|
end
|
13
15
|
|
14
16
|
def script
|
15
|
-
|
17
|
+
@script ||= Script.new(@redis)
|
16
18
|
end
|
17
19
|
|
18
20
|
def call(env)
|
19
|
-
status, headers, body = nil
|
20
|
-
|
21
21
|
if env['REQUEST_PATH'] == "/xruntime"
|
22
|
-
|
22
|
+
call_portal(env)
|
23
23
|
else
|
24
|
-
|
24
|
+
call_app(env)
|
25
25
|
end
|
26
|
-
|
27
|
-
[status, headers, body]
|
28
26
|
end
|
29
27
|
|
30
28
|
def call_app(env)
|
@@ -40,8 +38,7 @@ module XRuntime
|
|
40
38
|
end
|
41
39
|
|
42
40
|
def call_portal(env)
|
43
|
-
@
|
44
|
-
[200, {}, [Template.new(ds, :limit => (@req.params["limit"] ? @req.params["limit"].to_i : 20), :offset => @req.params["offset"].to_i).render]]
|
41
|
+
@portal.call(env)
|
45
42
|
end
|
46
43
|
|
47
44
|
def logredis(cost,uri)
|
@@ -0,0 +1,12 @@
|
|
1
|
+
module XRuntime
|
2
|
+
class Portal
|
3
|
+
def initialize(ds)
|
4
|
+
@ds = ds
|
5
|
+
end
|
6
|
+
|
7
|
+
def call(env)
|
8
|
+
@req = Rack::Request.new(env)
|
9
|
+
[200, {}, [Template.new(@ds, :limit => (@req.params["limit"] ? @req.params["limit"].to_i : 20), :offset => @req.params["offset"].to_i).render]]
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
data/lib/x_runtime.rb
CHANGED
@@ -10,14 +10,15 @@ $:.unshift(File.dirname(__FILE__))
|
|
10
10
|
|
11
11
|
module XRuntime
|
12
12
|
NameSpace = "RuntimeEx::Threshold"
|
13
|
+
|
14
|
+
autoload :Middleware, "x_runtime/middleware"
|
15
|
+
autoload :DataSet, "x_runtime/data_set"
|
16
|
+
autoload :Script, "x_runtime/script"
|
17
|
+
autoload :Portal, "x_runtime/portal"
|
18
|
+
autoload :Template, "x_runtime/template"
|
19
|
+
autoload :Utils, "x_runtime/utils"
|
13
20
|
end
|
14
21
|
|
15
|
-
XRuntime.autoload :Middleware, "x_runtime/middleware"
|
16
|
-
XRuntime.autoload :DataSet, "x_runtime/data_set"
|
17
|
-
XRuntime.autoload :Script, "x_runtime/script"
|
18
|
-
XRuntime.autoload :Template, "x_runtime/template"
|
19
|
-
XRuntime.autoload :Utils, "x_runtime/utils"
|
20
|
-
|
21
22
|
module Rack
|
22
23
|
XRuntime = XRuntime::Middleware
|
23
24
|
end
|
data/test/server.rb
CHANGED
@@ -2,8 +2,17 @@ require "sinatra"
|
|
2
2
|
require_relative "../lib/x_runtime"
|
3
3
|
|
4
4
|
# redis-server version must > 2.6.0 for lua script.
|
5
|
+
|
5
6
|
# use XRuntime::Middleware, 10, Redis.connect(:url => "redis://localhost:6380/")
|
6
|
-
|
7
|
+
|
8
|
+
# XRuntime::Middleware is same as Rack::XRuntime
|
9
|
+
|
10
|
+
# use Rack::XRuntime, 10, Redis.connect(:url => "redis://localhost:6380/")
|
11
|
+
|
12
|
+
# Use with basic auth
|
13
|
+
use Rack::XRuntime, 10, Redis.connect(:url => "redis://localhost:6380/") do |name, password|
|
14
|
+
name == "cui" and password == "hello"
|
15
|
+
end
|
7
16
|
|
8
17
|
get /.*/ do
|
9
18
|
# sleep(1)
|
data/x_runtime.gemspec
ADDED
@@ -0,0 +1,69 @@
|
|
1
|
+
# Generated by jeweler
|
2
|
+
# DO NOT EDIT THIS FILE DIRECTLY
|
3
|
+
# Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
|
4
|
+
# -*- encoding: utf-8 -*-
|
5
|
+
|
6
|
+
Gem::Specification.new do |s|
|
7
|
+
s.name = "x_runtime"
|
8
|
+
s.version = "0.2.0"
|
9
|
+
|
10
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
|
+
s.authors = ["\u{5d14}\u{5ce5}"]
|
12
|
+
s.date = "2012-08-20"
|
13
|
+
s.description = "\u{7531}\u{4e8e}\u{4f7f}\u{7528}\u{5230}Redis\u{7684}lua script,\u{6240}\u{4ee5}\u{9700}\u{8981}\u{4f60}\u{7684}Redis\u{670d}\u{52a1}\u{652f}\u{6301},redis-server\u{7248}\u{672c}>2.6.x,redis(ruby gem)>3.0.1."
|
14
|
+
s.email = "zheng.cuizh@gmail.com"
|
15
|
+
s.extra_rdoc_files = [
|
16
|
+
"LICENSE.txt",
|
17
|
+
"README.markdown"
|
18
|
+
]
|
19
|
+
s.files = [
|
20
|
+
"Gemfile",
|
21
|
+
"Gemfile.lock",
|
22
|
+
"LICENSE.txt",
|
23
|
+
"README.markdown",
|
24
|
+
"Rakefile",
|
25
|
+
"VERSION",
|
26
|
+
"lib/x_runtime.rb",
|
27
|
+
"lib/x_runtime/array.rb",
|
28
|
+
"lib/x_runtime/data_set.rb",
|
29
|
+
"lib/x_runtime/middleware.rb",
|
30
|
+
"lib/x_runtime/portal.rb",
|
31
|
+
"lib/x_runtime/redis.lua",
|
32
|
+
"lib/x_runtime/script.rb",
|
33
|
+
"lib/x_runtime/template.erb",
|
34
|
+
"lib/x_runtime/template.rb",
|
35
|
+
"lib/x_runtime/utils.rb",
|
36
|
+
"test/client.rb",
|
37
|
+
"test/helper.rb",
|
38
|
+
"test/server.rb",
|
39
|
+
"test/test_x_runtime.rb",
|
40
|
+
"x_runtime.gemspec"
|
41
|
+
]
|
42
|
+
s.homepage = "http://github.com/charlescui/x_runtime"
|
43
|
+
s.licenses = ["MIT"]
|
44
|
+
s.require_paths = ["lib"]
|
45
|
+
s.rubygems_version = "1.8.24"
|
46
|
+
s.summary = "XRuntime\u{662f}\u{4e00}\u{4e2a}Rack\u{7684}middleware,\u{914d}\u{5408}Redis\u{7528}\u{6765}\u{5206}\u{6790}Http Server\u{6bcf}\u{4e2a}URI\u{8bf7}\u{6c42}\u{65f6}\u{957f}"
|
47
|
+
|
48
|
+
if s.respond_to? :specification_version then
|
49
|
+
s.specification_version = 3
|
50
|
+
|
51
|
+
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
52
|
+
s.add_runtime_dependency(%q<rack>, [">= 0"])
|
53
|
+
s.add_runtime_dependency(%q<rake>, [">= 0"])
|
54
|
+
s.add_runtime_dependency(%q<jeweler>, [">= 0"])
|
55
|
+
s.add_runtime_dependency(%q<redis>, ["~> 3.0.1"])
|
56
|
+
else
|
57
|
+
s.add_dependency(%q<rack>, [">= 0"])
|
58
|
+
s.add_dependency(%q<rake>, [">= 0"])
|
59
|
+
s.add_dependency(%q<jeweler>, [">= 0"])
|
60
|
+
s.add_dependency(%q<redis>, ["~> 3.0.1"])
|
61
|
+
end
|
62
|
+
else
|
63
|
+
s.add_dependency(%q<rack>, [">= 0"])
|
64
|
+
s.add_dependency(%q<rake>, [">= 0"])
|
65
|
+
s.add_dependency(%q<jeweler>, [">= 0"])
|
66
|
+
s.add_dependency(%q<redis>, ["~> 3.0.1"])
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: x_runtime
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -59,22 +59,6 @@ dependencies:
|
|
59
59
|
- - ! '>='
|
60
60
|
- !ruby/object:Gem::Version
|
61
61
|
version: '0'
|
62
|
-
- !ruby/object:Gem::Dependency
|
63
|
-
name: active_support
|
64
|
-
requirement: !ruby/object:Gem::Requirement
|
65
|
-
none: false
|
66
|
-
requirements:
|
67
|
-
- - ! '>='
|
68
|
-
- !ruby/object:Gem::Version
|
69
|
-
version: '0'
|
70
|
-
type: :runtime
|
71
|
-
prerelease: false
|
72
|
-
version_requirements: !ruby/object:Gem::Requirement
|
73
|
-
none: false
|
74
|
-
requirements:
|
75
|
-
- - ! '>='
|
76
|
-
- !ruby/object:Gem::Version
|
77
|
-
version: '0'
|
78
62
|
- !ruby/object:Gem::Dependency
|
79
63
|
name: redis
|
80
64
|
requirement: !ruby/object:Gem::Requirement
|
@@ -110,6 +94,7 @@ files:
|
|
110
94
|
- lib/x_runtime/array.rb
|
111
95
|
- lib/x_runtime/data_set.rb
|
112
96
|
- lib/x_runtime/middleware.rb
|
97
|
+
- lib/x_runtime/portal.rb
|
113
98
|
- lib/x_runtime/redis.lua
|
114
99
|
- lib/x_runtime/script.rb
|
115
100
|
- lib/x_runtime/template.erb
|
@@ -119,6 +104,7 @@ files:
|
|
119
104
|
- test/helper.rb
|
120
105
|
- test/server.rb
|
121
106
|
- test/test_x_runtime.rb
|
107
|
+
- x_runtime.gemspec
|
122
108
|
homepage: http://github.com/charlescui/x_runtime
|
123
109
|
licenses:
|
124
110
|
- MIT
|
@@ -134,7 +120,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
134
120
|
version: '0'
|
135
121
|
segments:
|
136
122
|
- 0
|
137
|
-
hash:
|
123
|
+
hash: 3835881030075432585
|
138
124
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
139
125
|
none: false
|
140
126
|
requirements:
|