rack-reqorder 0.2.0 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +20 -2
- data/Rakefile +2 -8
- data/lib/rack/reqorder.rb +21 -0
- data/lib/rack/reqorder/logger.rb +77 -9
- data/lib/rack/reqorder/models/app_exception.rb +12 -3
- data/lib/rack/reqorder/models/app_fault.rb +20 -0
- data/lib/rack/reqorder/models/http_request.rb +12 -3
- data/lib/rack/reqorder/models/http_response.rb +8 -2
- data/lib/rack/reqorder/models/route_path.rb +40 -0
- data/lib/rack/reqorder/models/statistic.rb +31 -0
- data/lib/rack/reqorder/monitor.rb +60 -7
- data/lib/rack/reqorder/monitor/entities.rb +68 -2
- data/lib/rack/reqorder/tasks/routes.rake +10 -0
- data/lib/rack/reqorder/version.rb +1 -1
- data/rack-reqorder.gemspec +2 -0
- metadata +35 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 980b4a8e4de9b3696b27754a43753a7ee813b0e2
|
4
|
+
data.tar.gz: fcbfdaa4bf6ed3fb96923dd41b610642231275a7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0ba82134c8dfec0aaf62df4df6e2b3562db24624cf4f1e1a27c0d5c6dac7b7351aa824b5678b57f6f207df2deaeb8b924a754c8f730e88f81c7322a0cc165ad3
|
7
|
+
data.tar.gz: 64e885c60ed26a5951bf50102034a4c73701a104f6da0e80525900bd8e38192ee76def5fd0163b2b13213c39d591088d205ec88952542708f8f6e788e239a7b4
|
data/README.md
CHANGED
@@ -1,6 +1,14 @@
|
|
1
1
|
# Rack::Reqorder
|
2
2
|
|
3
|
-
Simple gem
|
3
|
+
Simple gem for monitoring Rack apps. Uses MongoDB. It can be used in combination
|
4
|
+
with [rack-reqorder-monitor](https://github.com/kollegorna/rack-reqorder-monitor).
|
5
|
+
|
6
|
+
## Introduction
|
7
|
+
Simple gem that sits on top of Rack and records request/response statistics
|
8
|
+
as well as monitors for exceptions. It saves everything in MongoDB and exposes
|
9
|
+
a simple API for retrieving these data.
|
10
|
+
|
11
|
+
The API is very robust, built with the help of [mongoid_hash_query](https://github.com/kollegorna/mongoid_hash_query).
|
4
12
|
|
5
13
|
## Installation
|
6
14
|
|
@@ -30,8 +38,18 @@ end
|
|
30
38
|
|
31
39
|
Rack::Reqorder.boot!
|
32
40
|
|
33
|
-
Rails.application.config.middleware.
|
41
|
+
Rails.application.config.middleware.insert_after(ActionDispatch::DebugExceptions , Rack::Reqorder::Logger)
|
42
|
+
|
43
|
+
#rack-cors also needed
|
44
|
+
Rails.application.config.middleware.insert_before 0, "Rack::Cors" do
|
45
|
+
allow do
|
46
|
+
origins '*'
|
47
|
+
resource '*', :headers => :any, :methods => [:get, :post, :options]
|
48
|
+
end
|
49
|
+
end
|
34
50
|
```
|
51
|
+
Please note that you can configure origins and resource depending on how you
|
52
|
+
mount the rack-monitor engine and where you deploy your front-end.
|
35
53
|
|
36
54
|
## Development
|
37
55
|
|
data/Rakefile
CHANGED
@@ -1,12 +1,6 @@
|
|
1
1
|
require "bundler/gem_tasks"
|
2
2
|
require 'rack/reqorder/api/api'
|
3
3
|
|
4
|
-
|
5
|
-
|
6
|
-
task :routes do
|
7
|
-
Rack::Reqorder::Api.routes.each do |route|
|
8
|
-
puts route
|
9
|
-
end
|
10
|
-
end
|
11
|
-
end
|
4
|
+
Dir.glob('lib/tasks/*.rake').each {|r| import r}
|
5
|
+
|
12
6
|
|
data/lib/rack/reqorder.rb
CHANGED
@@ -24,6 +24,22 @@ module Rack
|
|
24
24
|
)
|
25
25
|
end
|
26
26
|
|
27
|
+
def self.paths
|
28
|
+
return @paths unless @paths.blank?
|
29
|
+
@paths = {}
|
30
|
+
Rails.application.routes.routes.routes.each do |route|
|
31
|
+
@paths[route.defaults] = route.path.spec.left.to_s
|
32
|
+
end
|
33
|
+
|
34
|
+
return @paths
|
35
|
+
end
|
36
|
+
|
37
|
+
def self.recognise_path(path_uri, options = {})
|
38
|
+
res = Rack::Reqorder.paths[Rails.application.routes.recognize_path(path_uri, options)
|
39
|
+
.select{|key, value| [:action, :controller].include?(key)}
|
40
|
+
]
|
41
|
+
end
|
42
|
+
|
27
43
|
class Configuration
|
28
44
|
attr_accessor :mongoid_yml, :environment
|
29
45
|
|
@@ -52,9 +68,14 @@ Kaminari.configure do |config|
|
|
52
68
|
# config.param_name = :page
|
53
69
|
end
|
54
70
|
|
71
|
+
require 'rack/reqorder/models/statistic'
|
55
72
|
require 'rack/reqorder/models/http_request'
|
73
|
+
require 'rack/reqorder/models/route_path'
|
56
74
|
require 'rack/reqorder/models/http_response'
|
75
|
+
require 'rack/reqorder/models/app_fault'
|
57
76
|
require 'rack/reqorder/models/app_exception'
|
58
77
|
require 'rack/reqorder/services/backtrace_cleaner'
|
59
78
|
require 'rack/reqorder/logger'
|
60
79
|
require 'rack/reqorder/monitor'
|
80
|
+
|
81
|
+
load 'rack/reqorder/tasks/routes.rake'
|
data/lib/rack/reqorder/logger.rb
CHANGED
@@ -7,16 +7,23 @@ module Rack::Reqorder
|
|
7
7
|
end
|
8
8
|
|
9
9
|
def call(environment)
|
10
|
-
http_request = save_http_request(environment)
|
10
|
+
#http_request = save_http_request(environment)
|
11
11
|
|
12
|
+
start = Time.now.to_f
|
12
13
|
begin
|
13
14
|
status, headers, body = @app.call(environment)
|
14
15
|
rescue => exception
|
15
|
-
log_exception(exception,
|
16
|
+
log_exception(exception, environment)
|
16
17
|
raise exception
|
17
18
|
end
|
19
|
+
response_time = Time.now.to_f - start
|
18
20
|
|
19
|
-
save_http_response(body, status, headers, http_request)
|
21
|
+
#save_http_response(body, status, headers, http_request)
|
22
|
+
save_statistics(
|
23
|
+
rack_request: Rack::Request.new(environment),
|
24
|
+
rack_response: Rack::Response.new(body, status, headers),
|
25
|
+
response_time: response_time
|
26
|
+
)
|
20
27
|
|
21
28
|
return [status, headers, body]
|
22
29
|
end
|
@@ -35,10 +42,48 @@ module Rack::Reqorder
|
|
35
42
|
]
|
36
43
|
end
|
37
44
|
|
45
|
+
def save_statistics(rack_request:, rack_response:, response_time:)
|
46
|
+
route_path = RoutePath.find_or_create_by({
|
47
|
+
route: Rack::Reqorder.recognise_path(rack_request.path),
|
48
|
+
http_method: rack_request.request_method
|
49
|
+
})
|
50
|
+
|
51
|
+
[:all.to_s, DateTime.now.hour.to_s].each do |key|
|
52
|
+
statistic = route_path.send("statistic_#{key}".to_sym)
|
53
|
+
|
54
|
+
if statistic.nil?
|
55
|
+
statistic = route_path.send("create_statistic_#{key}")
|
56
|
+
end
|
57
|
+
|
58
|
+
statistic.inc({
|
59
|
+
statuses_2xx: (rack_response.status < 300 && rack_response.status >= 200)? 1: 0,
|
60
|
+
statuses_3xx: (rack_response.status < 400 && rack_response.status >= 300)? 1: 0,
|
61
|
+
statuses_4xx: (rack_response.status < 500 && rack_response.status >= 400)? 1: 0,
|
62
|
+
statuses_401: (rack_response.status == 401) ? 1 : 0,
|
63
|
+
statuses_404: (rack_response.status == 404) ? 1 : 0,
|
64
|
+
statuses_422: (rack_response.status == 422) ? 1 : 0,
|
65
|
+
statuses_5xx: (rack_response.status < 600 && rack_response.status >= 500)? 1: 0,
|
66
|
+
http_requests_count: 1,
|
67
|
+
xhr_count: rack_request.xhr? ? 1 : 0,
|
68
|
+
ssl_count: rack_request.ssl? ? 1 : 0,
|
69
|
+
})
|
70
|
+
|
71
|
+
statistic.recalculate_average!(response_time)
|
72
|
+
|
73
|
+
route_path.save!
|
74
|
+
route_path.send("statistic_#{key}".to_sym).save!
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
38
78
|
def save_http_request(environment)
|
39
79
|
request = Rack::Request.new(environment)
|
40
80
|
|
41
|
-
|
81
|
+
route_path = RoutePath.find_or_create_by({
|
82
|
+
route: Rack::Reqorder.recognise_path(request.path),
|
83
|
+
http_method: request.request_method
|
84
|
+
})
|
85
|
+
|
86
|
+
HttpRequest.create({
|
42
87
|
ip: request.ip,
|
43
88
|
url: request.url,
|
44
89
|
scheme: request.scheme,
|
@@ -50,8 +95,9 @@ module Rack::Reqorder
|
|
50
95
|
headers: extract_all_headers(request),
|
51
96
|
params: request.params,
|
52
97
|
ssl: request.ssl?,
|
53
|
-
xhr: request.xhr
|
54
|
-
|
98
|
+
xhr: request.xhr?,
|
99
|
+
route_path: route_path
|
100
|
+
})
|
55
101
|
end
|
56
102
|
|
57
103
|
def save_http_response(body, status, headers, http_request)
|
@@ -65,22 +111,44 @@ module Rack::Reqorder
|
|
65
111
|
)
|
66
112
|
end
|
67
113
|
|
68
|
-
def log_exception(exception,
|
114
|
+
def log_exception(exception, environment)
|
115
|
+
http_request = save_http_request(environment)
|
116
|
+
|
69
117
|
bc = BacktraceCleaner.new
|
70
118
|
bc.add_filter { |line| line.gsub(Rails.root.to_s, '') }
|
71
119
|
bc.add_silencer { |line| line =~ /gems/ }
|
72
120
|
|
73
121
|
application_trace = bc.clean(exception.backtrace)
|
74
122
|
|
75
|
-
path
|
123
|
+
path = line = nil
|
124
|
+
|
125
|
+
if not application_trace.blank?
|
126
|
+
path, line, _ = application_trace.first.split(':')
|
127
|
+
else
|
128
|
+
path, line, _ = exception.backtrace.first.split(':')
|
129
|
+
end
|
130
|
+
|
131
|
+
|
132
|
+
app_fault = AppFault.find_or_create_by(
|
133
|
+
e_class: exception.class,
|
134
|
+
line: line.to_i,
|
135
|
+
filepath: path[1..-1]
|
136
|
+
)
|
76
137
|
|
77
138
|
AppException.create(
|
139
|
+
e_class: exception.class,
|
78
140
|
message: exception.message,
|
79
141
|
application_trace: application_trace,
|
80
142
|
full_trace: exception.backtrace,
|
81
143
|
line: line.to_i,
|
82
|
-
|
144
|
+
filepath: path[1..-1],
|
83
145
|
source_extract: source_fragment(path[1..-1], line.to_i),
|
146
|
+
app_fault: app_fault,
|
147
|
+
http_request: http_request
|
148
|
+
)
|
149
|
+
|
150
|
+
HttpResponse.create(
|
151
|
+
status: 500,
|
84
152
|
http_request: http_request
|
85
153
|
)
|
86
154
|
end
|
@@ -4,16 +4,25 @@ module Rack::Reqorder::Models
|
|
4
4
|
class AppException
|
5
5
|
include ::Mongoid::Document
|
6
6
|
include ::Kaminari::MongoidExtension::Document
|
7
|
+
include ::Mongoid::Timestamps
|
7
8
|
|
9
|
+
field :e_class, type: String
|
8
10
|
field :message, type: String
|
9
11
|
field :application_trace, type: Array
|
10
12
|
#field :framework_trace, type: Array
|
11
13
|
field :full_trace, type: Array
|
12
14
|
field :line, type: Integer
|
13
|
-
field :
|
15
|
+
field :filepath, type: String
|
14
16
|
field :source_extract, type: Hash
|
15
|
-
field :created_at, type: Time, default: ->{ Time.now }
|
16
17
|
|
17
|
-
belongs_to :http_request
|
18
|
+
belongs_to :http_request, dependent: :nullify
|
19
|
+
belongs_to :app_fault, dependent: :nullify
|
20
|
+
|
21
|
+
after_save :update_count
|
22
|
+
|
23
|
+
private
|
24
|
+
def update_count
|
25
|
+
self.app_fault.update_count!
|
26
|
+
end
|
18
27
|
end
|
19
28
|
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
module Rack::Reqorder::Models
|
2
|
+
class AppFault
|
3
|
+
include ::Mongoid::Document
|
4
|
+
include ::Kaminari::MongoidExtension::Document
|
5
|
+
include ::Mongoid::Timestamps
|
6
|
+
|
7
|
+
field :e_class, type: String
|
8
|
+
field :line, type: Integer
|
9
|
+
field :filepath, type: String
|
10
|
+
|
11
|
+
field :app_exceptions_count, type: Integer, default: 0
|
12
|
+
|
13
|
+
has_many :app_exceptions, dependent: :destroy
|
14
|
+
|
15
|
+
def update_count!
|
16
|
+
self.app_exceptions_count = self.app_exceptions.count
|
17
|
+
self.save!
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -2,6 +2,7 @@ module Rack::Reqorder::Models
|
|
2
2
|
class HttpRequest
|
3
3
|
include ::Mongoid::Document
|
4
4
|
include ::Kaminari::MongoidExtension::Document
|
5
|
+
include ::Mongoid::Timestamps
|
5
6
|
|
6
7
|
field :ip, type: String
|
7
8
|
field :url, type: String
|
@@ -13,12 +14,20 @@ module Rack::Reqorder::Models
|
|
13
14
|
field :http_method, type: String
|
14
15
|
field :headers, type: Hash
|
15
16
|
field :params, type: Hash
|
17
|
+
field :param_keys, type: Array
|
16
18
|
field :ssl, type: Boolean
|
17
19
|
field :xhr, type: Boolean
|
18
|
-
field :
|
20
|
+
field :response_time, type: Float
|
19
21
|
|
20
|
-
has_one :http_response
|
21
|
-
has_one :app_exception
|
22
|
+
has_one :http_response, dependent: :destroy
|
23
|
+
has_one :app_exception, dependent: :destroy
|
22
24
|
|
25
|
+
belongs_to :route_path, dependent: :nullify
|
26
|
+
|
27
|
+
before_create :add_param_keys
|
28
|
+
private
|
29
|
+
def add_param_keys
|
30
|
+
self.param_keys = self.params.keys
|
31
|
+
end
|
23
32
|
end
|
24
33
|
end
|
@@ -2,20 +2,26 @@ module Rack::Reqorder::Models
|
|
2
2
|
class HttpResponse
|
3
3
|
include ::Mongoid::Document
|
4
4
|
include ::Kaminari::MongoidExtension::Document
|
5
|
+
include ::Mongoid::Timestamps
|
5
6
|
|
6
7
|
field :headers, type: Hash
|
7
8
|
field :status, type: Integer
|
8
9
|
#field :body, type: String
|
9
|
-
field :created_at, type: Time, default: ->{ Time.now }, pre_processed: true
|
10
10
|
field :response_time, type: Float
|
11
11
|
|
12
|
-
belongs_to :http_request
|
12
|
+
belongs_to :http_request, dependent: :nullify
|
13
13
|
|
14
14
|
before_create :set_response_time
|
15
|
+
after_create :set_response_time_to_request
|
15
16
|
|
16
17
|
private
|
17
18
|
def set_response_time
|
18
19
|
self.response_time = self.created_at - self.http_request.created_at
|
19
20
|
end
|
21
|
+
|
22
|
+
def set_response_time_to_request
|
23
|
+
self.http_request.response_time = self.response_time
|
24
|
+
self.http_request.save!
|
25
|
+
end
|
20
26
|
end
|
21
27
|
end
|
@@ -0,0 +1,40 @@
|
|
1
|
+
module Rack::Reqorder::Models
|
2
|
+
class RoutePath
|
3
|
+
include ::Mongoid::Document
|
4
|
+
include ::Kaminari::MongoidExtension::Document
|
5
|
+
include ::Mongoid::Timestamps
|
6
|
+
|
7
|
+
field :route, type: String
|
8
|
+
field :http_method, type: String
|
9
|
+
|
10
|
+
has_many :http_requests, dependent: :destroy
|
11
|
+
|
12
|
+
embeds_one :statistic_0, class_name: 'Rack::Reqorder::Models::Statistic'
|
13
|
+
embeds_one :statistic_1, class_name: 'Rack::Reqorder::Models::Statistic'
|
14
|
+
embeds_one :statistic_2, class_name: 'Rack::Reqorder::Models::Statistic'
|
15
|
+
embeds_one :statistic_3, class_name: 'Rack::Reqorder::Models::Statistic'
|
16
|
+
embeds_one :statistic_4, class_name: 'Rack::Reqorder::Models::Statistic'
|
17
|
+
embeds_one :statistic_5, class_name: 'Rack::Reqorder::Models::Statistic'
|
18
|
+
embeds_one :statistic_6, class_name: 'Rack::Reqorder::Models::Statistic'
|
19
|
+
embeds_one :statistic_7, class_name: 'Rack::Reqorder::Models::Statistic'
|
20
|
+
embeds_one :statistic_8, class_name: 'Rack::Reqorder::Models::Statistic'
|
21
|
+
embeds_one :statistic_9, class_name: 'Rack::Reqorder::Models::Statistic'
|
22
|
+
embeds_one :statistic_10, class_name: 'Rack::Reqorder::Models::Statistic'
|
23
|
+
embeds_one :statistic_11, class_name: 'Rack::Reqorder::Models::Statistic'
|
24
|
+
embeds_one :statistic_12, class_name: 'Rack::Reqorder::Models::Statistic'
|
25
|
+
embeds_one :statistic_13, class_name: 'Rack::Reqorder::Models::Statistic'
|
26
|
+
embeds_one :statistic_14, class_name: 'Rack::Reqorder::Models::Statistic'
|
27
|
+
embeds_one :statistic_15, class_name: 'Rack::Reqorder::Models::Statistic'
|
28
|
+
embeds_one :statistic_16, class_name: 'Rack::Reqorder::Models::Statistic'
|
29
|
+
embeds_one :statistic_17, class_name: 'Rack::Reqorder::Models::Statistic'
|
30
|
+
embeds_one :statistic_18, class_name: 'Rack::Reqorder::Models::Statistic'
|
31
|
+
embeds_one :statistic_19, class_name: 'Rack::Reqorder::Models::Statistic'
|
32
|
+
embeds_one :statistic_20, class_name: 'Rack::Reqorder::Models::Statistic'
|
33
|
+
embeds_one :statistic_21, class_name: 'Rack::Reqorder::Models::Statistic'
|
34
|
+
embeds_one :statistic_22, class_name: 'Rack::Reqorder::Models::Statistic'
|
35
|
+
embeds_one :statistic_23, class_name: 'Rack::Reqorder::Models::Statistic'
|
36
|
+
embeds_one :statistic_24, class_name: 'Rack::Reqorder::Models::Statistic'
|
37
|
+
|
38
|
+
embeds_one :statistic_all, class_name: 'Rack::Reqorder::Models::Statistic'
|
39
|
+
end
|
40
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
module Rack::Reqorder::Models
|
2
|
+
class Statistic
|
3
|
+
include ::Mongoid::Document
|
4
|
+
include ::Kaminari::MongoidExtension::Document
|
5
|
+
include ::Mongoid::Timestamps
|
6
|
+
|
7
|
+
field :http_requests_count, type: Integer, default: 0
|
8
|
+
#field :sum
|
9
|
+
#field :square_sum
|
10
|
+
#field :sd_response_time
|
11
|
+
field :avg_response_time, type: Float, default: 0
|
12
|
+
field :statuses_2xx, type: Integer, default: 0
|
13
|
+
field :statuses_3xx, type: Integer, default: 0
|
14
|
+
field :statuses_4xx, type: Integer, default: 0
|
15
|
+
field :statuses_401, type: Integer, default: 0
|
16
|
+
field :statuses_404, type: Integer, default: 0
|
17
|
+
field :statuses_422, type: Integer, default: 0
|
18
|
+
field :statuses_5xx, type: Integer, default: 0
|
19
|
+
|
20
|
+
field :xhr_count, type: Integer, default: 0
|
21
|
+
field :ssl_count, type: Integer, default: 0
|
22
|
+
|
23
|
+
embedded_in :route_path
|
24
|
+
|
25
|
+
def recalculate_average!(response_time)
|
26
|
+
self.avg_response_time = (
|
27
|
+
response_time + (self.http_requests_count-1)*self.avg_response_time
|
28
|
+
)/self.http_requests_count
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
@@ -22,6 +22,30 @@ module Rack::Reqorder::Monitor
|
|
22
22
|
format :json
|
23
23
|
prefix :api
|
24
24
|
|
25
|
+
#collection routes
|
26
|
+
resource :route_paths do
|
27
|
+
get do
|
28
|
+
route_paths = apply_filters(RoutePath.all, params)
|
29
|
+
|
30
|
+
meta_aggregations = aggregations(route_paths, params)
|
31
|
+
|
32
|
+
route_paths = paginate(route_paths, params)
|
33
|
+
|
34
|
+
present_with_meta(
|
35
|
+
route_paths,
|
36
|
+
present(route_paths, with: RoutePathEntity),
|
37
|
+
meta_aggregations
|
38
|
+
)
|
39
|
+
end
|
40
|
+
|
41
|
+
#element routes
|
42
|
+
route_param :id do
|
43
|
+
get do
|
44
|
+
present(RoutePath.find(params[:id]), with: RoutePathEntity)
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
25
49
|
#collection routes
|
26
50
|
resource :requests do
|
27
51
|
get do
|
@@ -53,7 +77,7 @@ module Rack::Reqorder::Monitor
|
|
53
77
|
|
54
78
|
responses = apply_filters(responses, params)
|
55
79
|
|
56
|
-
meta_aggregations = aggregations(
|
80
|
+
meta_aggregations = aggregations(responses, params)
|
57
81
|
|
58
82
|
responses = paginate(responses, params)
|
59
83
|
|
@@ -72,6 +96,32 @@ module Rack::Reqorder::Monitor
|
|
72
96
|
end
|
73
97
|
end
|
74
98
|
|
99
|
+
#collection routes
|
100
|
+
resource :faults do
|
101
|
+
get do
|
102
|
+
faults = AppFault.all
|
103
|
+
|
104
|
+
faults = apply_filters(faults, params)
|
105
|
+
|
106
|
+
meta_aggregations = aggregations(faults, params)
|
107
|
+
|
108
|
+
faults = paginate(faults, params)
|
109
|
+
|
110
|
+
present_with_meta(
|
111
|
+
faults,
|
112
|
+
present(faults, with: FaultEntity),
|
113
|
+
meta_aggregations
|
114
|
+
)
|
115
|
+
end
|
116
|
+
|
117
|
+
#element routes
|
118
|
+
route_param :id do
|
119
|
+
get do
|
120
|
+
present(AppFault.find(params[:id]), with: FaultEntity)
|
121
|
+
end
|
122
|
+
end
|
123
|
+
end
|
124
|
+
|
75
125
|
#collection routes
|
76
126
|
resource :exceptions do
|
77
127
|
get do
|
@@ -101,18 +151,21 @@ module Rack::Reqorder::Monitor
|
|
101
151
|
helpers do
|
102
152
|
def present_with_meta(object, hash, extra_meta)
|
103
153
|
hash[:meta] = {
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
154
|
+
currentPage: object.current_page,
|
155
|
+
nextPage: object.next_page,
|
156
|
+
prevPage: object.prev_page,
|
157
|
+
totalPages: object.total_pages,
|
158
|
+
totalCount: object.total_count
|
109
159
|
}.merge(extra_meta)
|
110
160
|
|
111
161
|
return hash
|
112
162
|
end
|
113
163
|
|
114
164
|
def paginate(object, params)
|
115
|
-
return object.
|
165
|
+
return object.
|
166
|
+
page(params[:page] || 1).
|
167
|
+
per(params[:per_page] || 30).
|
168
|
+
skip(params[:skip] || 0)
|
116
169
|
end
|
117
170
|
end
|
118
171
|
|
@@ -5,7 +5,47 @@ module Rack::Reqorder::Monitor
|
|
5
5
|
format_with(:to_string) { |foo| foo.to_s }
|
6
6
|
format_with(:iso_timestamp) { |dt| dt.utc.iso8601 if dt }
|
7
7
|
|
8
|
-
format_with(:association_id) {|a| a.id.to_s if a}
|
8
|
+
format_with(:association_id) {|a| a.id.to_s if a }
|
9
|
+
format_with(:association_ids) {|a| a.map{|i| i.to_s if i} if a }
|
10
|
+
end
|
11
|
+
|
12
|
+
class StatisticEntity < BaseEntity
|
13
|
+
root :statistics, :statistic
|
14
|
+
|
15
|
+
expose :http_requests_count
|
16
|
+
expose :avg_response_time
|
17
|
+
expose :statuses_2xx
|
18
|
+
expose :statuses_3xx
|
19
|
+
expose :statuses_4xx
|
20
|
+
expose :statuses_401
|
21
|
+
expose :statuses_404
|
22
|
+
expose :statuses_422
|
23
|
+
expose :statuses_5xx
|
24
|
+
|
25
|
+
expose :xhr_count
|
26
|
+
expose :ssl_count
|
27
|
+
|
28
|
+
with_options(format_with: :iso_timestamp) do
|
29
|
+
expose :created_at
|
30
|
+
expose :updated_at
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
class RoutePathEntity < BaseEntity
|
35
|
+
root :route_paths, :route_path
|
36
|
+
|
37
|
+
expose :route
|
38
|
+
expose :http_method
|
39
|
+
expose :statistic_all, using: StatisticEntity
|
40
|
+
|
41
|
+
1.upto(24) do |num|
|
42
|
+
expose "statistic_#{num}", using: StatisticEntity
|
43
|
+
end
|
44
|
+
|
45
|
+
with_options(format_with: :iso_timestamp) do
|
46
|
+
expose :created_at
|
47
|
+
expose :updated_at
|
48
|
+
end
|
9
49
|
end
|
10
50
|
|
11
51
|
class RequestEntity < BaseEntity
|
@@ -21,11 +61,14 @@ module Rack::Reqorder::Monitor
|
|
21
61
|
expose :http_method
|
22
62
|
expose :headers
|
23
63
|
expose :params
|
64
|
+
expose :param_keys
|
24
65
|
expose :ssl
|
25
66
|
expose :xhr
|
67
|
+
expose :response_time
|
26
68
|
|
27
69
|
with_options(format_with: :iso_timestamp) do
|
28
70
|
expose :created_at
|
71
|
+
expose :updated_at
|
29
72
|
end
|
30
73
|
|
31
74
|
with_options(format_with: :association_id) do
|
@@ -43,6 +86,7 @@ module Rack::Reqorder::Monitor
|
|
43
86
|
|
44
87
|
with_options(format_with: :iso_timestamp) do
|
45
88
|
expose :created_at
|
89
|
+
expose :updated_at
|
46
90
|
end
|
47
91
|
|
48
92
|
with_options(format_with: :association_id) do
|
@@ -50,6 +94,26 @@ module Rack::Reqorder::Monitor
|
|
50
94
|
end
|
51
95
|
end
|
52
96
|
|
97
|
+
class FaultEntity < BaseEntity
|
98
|
+
root :faults, :fault
|
99
|
+
|
100
|
+
expose :e_class
|
101
|
+
expose :line
|
102
|
+
expose :filepath
|
103
|
+
expose :app_exceptions_count, as: :exceptions_count
|
104
|
+
expose :message do |fault, options|
|
105
|
+
fault.app_exceptions.try(:first).try(:message)
|
106
|
+
end
|
107
|
+
|
108
|
+
expose :app_exception_ids, as: :exception_ids do |fault, options|
|
109
|
+
fault.app_exception_ids.map(&:to_s).first(100)
|
110
|
+
end
|
111
|
+
|
112
|
+
with_options(format_with: :iso_timestamp) do
|
113
|
+
expose :created_at
|
114
|
+
expose :updated_at
|
115
|
+
end
|
116
|
+
end
|
53
117
|
|
54
118
|
class ExceptionEntity < BaseEntity
|
55
119
|
root :exceptions, :exception
|
@@ -58,15 +122,17 @@ module Rack::Reqorder::Monitor
|
|
58
122
|
expose :application_trace
|
59
123
|
expose :full_trace
|
60
124
|
expose :line
|
61
|
-
expose :
|
125
|
+
expose :filepath
|
62
126
|
expose :source_extract
|
63
127
|
|
64
128
|
with_options(format_with: :iso_timestamp) do
|
65
129
|
expose :created_at
|
130
|
+
expose :updated_at
|
66
131
|
end
|
67
132
|
|
68
133
|
with_options(format_with: :association_id) do
|
69
134
|
expose :http_request, as: :request_id
|
135
|
+
expose :app_fault, as: :fault_id
|
70
136
|
end
|
71
137
|
|
72
138
|
end
|
data/rack-reqorder.gemspec
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rack-reqorder
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Filippos Vasilakis
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-07-27 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -108,6 +108,34 @@ dependencies:
|
|
108
108
|
- - ">="
|
109
109
|
- !ruby/object:Gem::Version
|
110
110
|
version: '0'
|
111
|
+
- !ruby/object:Gem::Dependency
|
112
|
+
name: rack-cors
|
113
|
+
requirement: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - ">="
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: '0'
|
118
|
+
type: :runtime
|
119
|
+
prerelease: false
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
requirements:
|
122
|
+
- - ">="
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: '0'
|
125
|
+
- !ruby/object:Gem::Dependency
|
126
|
+
name: mongoid_hash_query
|
127
|
+
requirement: !ruby/object:Gem::Requirement
|
128
|
+
requirements:
|
129
|
+
- - "~>"
|
130
|
+
- !ruby/object:Gem::Version
|
131
|
+
version: 0.2.4
|
132
|
+
type: :runtime
|
133
|
+
prerelease: false
|
134
|
+
version_requirements: !ruby/object:Gem::Requirement
|
135
|
+
requirements:
|
136
|
+
- - "~>"
|
137
|
+
- !ruby/object:Gem::Version
|
138
|
+
version: 0.2.4
|
111
139
|
description: Request recorder and analyzer for rack apps
|
112
140
|
email:
|
113
141
|
- vasilakisfil@gmail.com
|
@@ -129,11 +157,15 @@ files:
|
|
129
157
|
- lib/rack/reqorder/config.ru
|
130
158
|
- lib/rack/reqorder/logger.rb
|
131
159
|
- lib/rack/reqorder/models/app_exception.rb
|
160
|
+
- lib/rack/reqorder/models/app_fault.rb
|
132
161
|
- lib/rack/reqorder/models/http_request.rb
|
133
162
|
- lib/rack/reqorder/models/http_response.rb
|
163
|
+
- lib/rack/reqorder/models/route_path.rb
|
164
|
+
- lib/rack/reqorder/models/statistic.rb
|
134
165
|
- lib/rack/reqorder/monitor.rb
|
135
166
|
- lib/rack/reqorder/monitor/entities.rb
|
136
167
|
- lib/rack/reqorder/services/backtrace_cleaner.rb
|
168
|
+
- lib/rack/reqorder/tasks/routes.rake
|
137
169
|
- lib/rack/reqorder/version.rb
|
138
170
|
- rack-reqorder.gemspec
|
139
171
|
homepage: ''
|
@@ -156,7 +188,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
156
188
|
version: '0'
|
157
189
|
requirements: []
|
158
190
|
rubyforge_project:
|
159
|
-
rubygems_version: 2.4.
|
191
|
+
rubygems_version: 2.4.5
|
160
192
|
signing_key:
|
161
193
|
specification_version: 4
|
162
194
|
summary: Request recorder and analyzer for rack apps
|