x_runtime 0.4.0 → 0.4.1
Sign up to get free protection for your applications and to get access to all the features.
- data/README.markdown +11 -5
- data/VERSION +1 -1
- data/lib/x_runtime/middleware.rb +3 -2
- data/lib/x_runtime/server.rb +2 -2
- data/test/server.ru +4 -2
- data/x_runtime.gemspec +1 -1
- metadata +2 -2
data/README.markdown
CHANGED
@@ -40,14 +40,18 @@ XRuntime是一个Rack的middleware,配合Redis用来分析Http Server每个URI
|
|
40
40
|
|
41
41
|
收集数据 `config.ru`:
|
42
42
|
|
43
|
-
|
43
|
+
``` ruby
|
44
|
+
use Rack::XRuntime, 10, Redis.connect(:url => "redis://localhost:6379/") do |name, password|
|
45
|
+
name == "cui" and password == "hello"
|
46
|
+
end
|
47
|
+
```
|
44
48
|
|
45
49
|
查看数据 `config.ru`:
|
46
50
|
|
47
51
|
``` ruby
|
48
52
|
run Rack::URLMap.new \
|
49
53
|
"/" => Server.new,
|
50
|
-
"/xruntime" => XRuntime::Server.new
|
54
|
+
"/xruntime" => XRuntime::Server.new
|
51
55
|
```
|
52
56
|
|
53
57
|
### Rails3
|
@@ -55,13 +59,15 @@ run Rack::URLMap.new \
|
|
55
59
|
收集数据 `config/environment.rb`:
|
56
60
|
|
57
61
|
``` ruby
|
58
|
-
config.middleware.insert_after Rack::Runtime, Rack::XRuntime, 100, Redis.connect(:url => "redis://localhost:6380/")
|
62
|
+
config.middleware.insert_after Rack::Runtime, Rack::XRuntime, 100, Redis.connect(:url => "redis://localhost:6380/") do |name, password|
|
63
|
+
name == "cui" and password == "hello"
|
64
|
+
end
|
59
65
|
```
|
60
66
|
|
61
|
-
查看数据 `config/
|
67
|
+
查看数据 `config/routes.rb`:
|
62
68
|
|
63
69
|
``` ruby
|
64
|
-
mount Rack::XRuntime
|
70
|
+
mount Rack::XRuntime, :at => "/xruntime"
|
65
71
|
```
|
66
72
|
|
67
73
|
### Test
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.4.
|
1
|
+
0.4.1
|
data/lib/x_runtime/middleware.rb
CHANGED
@@ -1,11 +1,12 @@
|
|
1
1
|
module XRuntime
|
2
2
|
class Middleware
|
3
|
-
|
3
|
+
attr_accessor :auth
|
4
4
|
# threshold => ms
|
5
|
-
def initialize(app, threshold, redis)
|
5
|
+
def initialize(app, threshold, redis, &auth)
|
6
6
|
@app = app
|
7
7
|
@threshold = threshold.to_f
|
8
8
|
@redis = redis
|
9
|
+
@auth = auth
|
9
10
|
XRuntime.middleware = self
|
10
11
|
end
|
11
12
|
|
data/lib/x_runtime/server.rb
CHANGED
@@ -1,11 +1,11 @@
|
|
1
1
|
module XRuntime
|
2
2
|
class Server
|
3
|
-
def initialize(app=nil
|
3
|
+
def initialize(app=nil)
|
4
4
|
@server = lambda {|env|
|
5
5
|
@req = Rack::Request.new(env)
|
6
6
|
[200, {'Content-Type' => 'text/html'}, [Template.new(XRuntime.middleware.ds, :limit => (@req.params["limit"] ? @req.params["limit"].to_i : 20), :offset => @req.params["offset"].to_i).render]]
|
7
7
|
}
|
8
|
-
@server = Rack::Auth::Basic.new(@server, &auth) if auth
|
8
|
+
@server = Rack::Auth::Basic.new(@server, &XRuntime.middleware.auth) if XRuntime.middleware.auth
|
9
9
|
end
|
10
10
|
|
11
11
|
def call(env)
|
data/test/server.ru
CHANGED
@@ -8,7 +8,9 @@ require "#{File.dirname(__FILE__)}/../lib/x_runtime"
|
|
8
8
|
class Server < Sinatra::Base
|
9
9
|
# use XRuntime::Middleware, 10, Redis.connect(:url => "redis://localhost:6380/")
|
10
10
|
# XRuntime::Middleware is same as Rack::XRuntime
|
11
|
-
use Rack::XRuntime, 10, Redis.connect(:url => "redis://localhost:6379/")
|
11
|
+
use Rack::XRuntime, 10, Redis.connect(:url => "redis://localhost:6379/") do |name, password|
|
12
|
+
name == "cui" and password == "hello"
|
13
|
+
end
|
12
14
|
|
13
15
|
get /.*/ do
|
14
16
|
# sleep(1)
|
@@ -20,4 +22,4 @@ end
|
|
20
22
|
# Use with basic auth
|
21
23
|
run Rack::URLMap.new \
|
22
24
|
"/" => Server.new,
|
23
|
-
"/xruntime" => XRuntime::Server.new
|
25
|
+
"/xruntime" => XRuntime::Server.new
|
data/x_runtime.gemspec
CHANGED
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.
|
4
|
+
version: 0.4.1
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -135,7 +135,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
135
135
|
version: '0'
|
136
136
|
segments:
|
137
137
|
- 0
|
138
|
-
hash:
|
138
|
+
hash: -2051941527554950884
|
139
139
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
140
140
|
none: false
|
141
141
|
requirements:
|