rails_performance 0.0.1.2 → 0.0.1.3
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.
- checksums.yaml +4 -4
- data/app/controllers/rails_performance_controller.rb +6 -8
- data/app/helpers/rails_performance_helper.rb +17 -0
- data/app/views/rails_performance/_css.html.erb +8 -0
- data/app/views/rails_performance/index.html.erb +7 -3
- data/lib/rails_performance.rb +1 -0
- data/lib/rails_performance/data_source.rb +10 -5
- data/lib/rails_performance/engine.rb +2 -2
- data/lib/rails_performance/{metrics_listener.rb → metrics_collector.rb} +2 -4
- data/lib/rails_performance/middleware.rb +12 -0
- data/lib/rails_performance/query_builder.rb +17 -0
- data/lib/rails_performance/throughput_report.rb +4 -1
- data/lib/rails_performance/utils.rb +3 -2
- data/lib/rails_performance/version.rb +1 -1
- metadata +4 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 57398ce57cc6e6707959d81156ffb0b48f8b32f55e25657f1f0a714c89c1bc2c
|
4
|
+
data.tar.gz: 1250f710f15e028d1c8ed187cd6e1e9849ad8e0d440cb6eb6bd5eb67ec09d491
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a1d3edeb648e2cd152e479c03c4d52e6c697963ba8c677f42bceb6fa373896cd353f24e0f0bababed286cd323b71db265a98fccaa9ea5f425eb46027b7873e04
|
7
|
+
data.tar.gz: 74936554df31a3672f68985ff68f640f33faa4a798a2f7a53bcb2169eebcea6bf62a65ab3863771936013a166313a8f04cd5d564678481786cdaf1807bee1580
|
@@ -1,15 +1,13 @@
|
|
1
1
|
class RailsPerformanceController < ActionController::Base
|
2
2
|
|
3
3
|
def index
|
4
|
-
@datasource = RailsPerformance::DataSource.new(
|
5
|
-
q: {
|
6
|
-
# controller: "HomeController",
|
7
|
-
# action: "about"
|
8
|
-
})
|
4
|
+
@datasource = RailsPerformance::DataSource.new(RailsPerformance::QueryBuilder.compose_from(params))
|
9
5
|
|
10
|
-
@
|
11
|
-
@
|
12
|
-
|
6
|
+
@throughput_report = RailsPerformance::ThroughputReport.new(@datasource.db)
|
7
|
+
@throughput_report_data = @throughput_report.data
|
8
|
+
|
9
|
+
@global_report = RailsPerformance::RequestsReport.new(@datasource.db, group: :controller_action_format, sort: :db_runtime_slowest)
|
10
|
+
@global_report_data = @global_report.data
|
13
11
|
end
|
14
12
|
|
15
13
|
# def RailsPerformanceController.x
|
@@ -5,4 +5,21 @@ module RailsPerformanceHelper
|
|
5
5
|
|
6
6
|
value.nan? ? nil : value.round(2)
|
7
7
|
end
|
8
|
+
|
9
|
+
def statistics_link(title, report, group)
|
10
|
+
options = case report.group
|
11
|
+
when :controller_action_format
|
12
|
+
ca = group.split("|")
|
13
|
+
c, a = ca[0].split("#")
|
14
|
+
{
|
15
|
+
controller_eq: c,
|
16
|
+
action_eq: a,
|
17
|
+
format_eq: ca[1]
|
18
|
+
}
|
19
|
+
else
|
20
|
+
{}
|
21
|
+
end
|
22
|
+
|
23
|
+
link_to title, rails_performance_path(options)
|
24
|
+
end
|
8
25
|
end
|
@@ -2,6 +2,10 @@
|
|
2
2
|
|
3
3
|
<title>Number of Requests to the Application</title>
|
4
4
|
|
5
|
+
<% unless @datasource.default? %>
|
6
|
+
<%= link_to raw("← Back"), rails_performance_path, class: "back_link" %>
|
7
|
+
<% end %>
|
8
|
+
|
5
9
|
<br/>
|
6
10
|
<br/>
|
7
11
|
<br/>
|
@@ -38,10 +42,10 @@
|
|
38
42
|
</tr>
|
39
43
|
</thead>
|
40
44
|
<tbody>
|
41
|
-
<% @
|
45
|
+
<% @global_report_data.each do |e| %>
|
42
46
|
<% groups = e[:group].split("|") %>
|
43
47
|
<tr>
|
44
|
-
<td><%= groups[0] %></td>
|
48
|
+
<td><%= statistics_link groups[0], @global_report, e[:group] %></td>
|
45
49
|
<td><%= groups[1]&.upcase %></td>
|
46
50
|
<td><%= e[:count] %></td>
|
47
51
|
<td><%= round_it e[:duration_average] %></td>
|
@@ -64,7 +68,7 @@
|
|
64
68
|
<%= render '/rails_performance/js' %>
|
65
69
|
|
66
70
|
<script>
|
67
|
-
var data = <%= raw @
|
71
|
+
var data = <%= raw @throughput_report_data.to_json %>;
|
68
72
|
showRequestsChart('chart', data);
|
69
73
|
</script>
|
70
74
|
|
data/lib/rails_performance.rb
CHANGED
@@ -5,26 +5,31 @@ module RailsPerformance
|
|
5
5
|
def initialize(q: {})
|
6
6
|
q[:on] ||= Date.today
|
7
7
|
@q = q
|
8
|
+
|
9
|
+
#puts " [DataSource Q] --> #{@q.inspect}\n\n"
|
8
10
|
end
|
9
11
|
|
10
|
-
def
|
12
|
+
def db
|
11
13
|
result = RP::Collection.new
|
12
14
|
RP::Utils.days.times do |e|
|
13
|
-
RP::DataSource.new(q: { on: e.days.ago.to_date }).add_to(result)
|
15
|
+
RP::DataSource.new(q: self.q.merge({ on: e.days.ago.to_date })).add_to(result)
|
14
16
|
end
|
15
17
|
result
|
16
18
|
end
|
17
19
|
|
18
|
-
def
|
20
|
+
def default?
|
21
|
+
@q.keys == [:on]
|
22
|
+
end
|
23
|
+
|
24
|
+
def add_to(storage = RP::Collection.new)
|
19
25
|
store do |record|
|
20
26
|
storage.add(record)
|
21
27
|
end
|
22
28
|
storage
|
23
29
|
end
|
24
|
-
alias :add_to :db
|
25
30
|
|
26
31
|
def store
|
27
|
-
|
32
|
+
# puts "\n\n [REDIS QUERY] --> #{query}\n\n"
|
28
33
|
|
29
34
|
keys = RP.redis.keys(query)
|
30
35
|
return [] if keys.blank?
|
@@ -1,6 +1,6 @@
|
|
1
1
|
require_relative './middleware.rb'
|
2
2
|
require_relative './collection.rb'
|
3
|
-
require_relative './
|
3
|
+
require_relative './metrics_collector.rb'
|
4
4
|
|
5
5
|
module RailsPerformance
|
6
6
|
class Engine < ::Rails::Engine
|
@@ -11,7 +11,7 @@ module RailsPerformance
|
|
11
11
|
initializer :configure_metrics, after: :initialize_logger do
|
12
12
|
ActiveSupport::Notifications.subscribe(
|
13
13
|
"process_action.action_controller",
|
14
|
-
RailsPerformance::
|
14
|
+
RailsPerformance::MetricsCollector.new
|
15
15
|
)
|
16
16
|
end
|
17
17
|
|
@@ -1,5 +1,5 @@
|
|
1
1
|
module RailsPerformance
|
2
|
-
class
|
2
|
+
class MetricsCollector
|
3
3
|
FORMAT = "%Y%m%dT%H%M"
|
4
4
|
|
5
5
|
# payload
|
@@ -19,14 +19,12 @@ module RailsPerformance
|
|
19
19
|
def call(event_name, started, finished, event_id, payload)
|
20
20
|
event = ActiveSupport::Notifications::Event.new(event_name, started, finished, event_id, payload)
|
21
21
|
|
22
|
-
#finished = Time.now - rand(180).minutes
|
23
|
-
|
24
22
|
record = {
|
25
23
|
controller: event.payload[:controller],
|
26
24
|
action: event.payload[:action],
|
27
25
|
format: event.payload[:format],
|
28
26
|
status: event.payload[:status],
|
29
|
-
datetime: finished.strftime(FORMAT),
|
27
|
+
datetime: finished.strftime(RailsPerformance::MetricsCollector::FORMAT),
|
30
28
|
datetimei: finished.to_i,
|
31
29
|
method: event.payload[:method],
|
32
30
|
path: event.payload[:path],
|
@@ -9,7 +9,19 @@ module RailsPerformance
|
|
9
9
|
|
10
10
|
if record = Thread.current["RP_request_info"]
|
11
11
|
record[:status] ||= @status
|
12
|
+
|
13
|
+
# rand(100).times do |e|
|
14
|
+
# finished = Time.now - rand(2000).minutes
|
15
|
+
# record[:datetime] = finished.strftime(RailsPerformance::MetricsCollector::FORMAT)
|
16
|
+
# record[:datetimei] = finished.to_i
|
17
|
+
# record[:duration] = rand(record[:duration].to_f * 2)
|
18
|
+
# record[:db_runtime] = rand(record[:db_runtime].to_f * 2)
|
19
|
+
# record[:view_runtime] = rand(record[:view_runtime].to_f * 2)
|
20
|
+
# RP::Utils.log_in_redis(record)
|
21
|
+
# end
|
22
|
+
|
12
23
|
RP::Utils.log_in_redis(record)
|
24
|
+
|
13
25
|
Thread.current["RP_request_info"] = nil
|
14
26
|
end
|
15
27
|
|
@@ -0,0 +1,17 @@
|
|
1
|
+
module RailsPerformance
|
2
|
+
class QueryBuilder
|
3
|
+
|
4
|
+
def QueryBuilder.compose_from(params)
|
5
|
+
result = {}
|
6
|
+
|
7
|
+
result[:controller] = params[:controller_eq]
|
8
|
+
result[:action] = params[:action_eq]
|
9
|
+
result[:format] = params[:format_eq]
|
10
|
+
|
11
|
+
result.delete_if {|k, v| v.nil?}
|
12
|
+
|
13
|
+
{ q: result }
|
14
|
+
end
|
15
|
+
|
16
|
+
end
|
17
|
+
end
|
@@ -12,6 +12,9 @@ module RailsPerformance
|
|
12
12
|
@data = []
|
13
13
|
offset = Time.current.utc_offset
|
14
14
|
|
15
|
+
# puts "current: #{current}"
|
16
|
+
# puts "stop: #{stop}"
|
17
|
+
|
15
18
|
# read current values
|
16
19
|
db.group_by(group).values.each do |(k, v)|
|
17
20
|
all[k] = v.count
|
@@ -19,7 +22,7 @@ module RailsPerformance
|
|
19
22
|
|
20
23
|
# add blank columns
|
21
24
|
while current <= stop
|
22
|
-
views = all[current.strftime(
|
25
|
+
views = all[current.strftime(MetricsCollector::FORMAT)] || 0
|
23
26
|
@data << [(current.to_i + offset) * 1000, views.to_i]
|
24
27
|
current += 1.minute
|
25
28
|
end
|
@@ -16,11 +16,12 @@ module RailsPerformance
|
|
16
16
|
value = e.slice(:view_runtime, :db_runtime, :duration)
|
17
17
|
key = "performance|controller|#{e[:controller]}|action|#{e[:action]}|format|#{e[:format]}|status|#{e[:status]}|datetime|#{e[:datetime]}|datetimei|#{e[:datetimei]}|method|#{e[:method]}|path|#{e[:path]}|END"
|
18
18
|
|
19
|
-
#puts " [SAVE] key ---> #{key}\n"
|
20
|
-
#puts " value ---> #{value.to_json}\n\n"
|
19
|
+
# puts " [SAVE] key ---> #{key}\n"
|
20
|
+
# puts " value ---> #{value.to_json}\n\n"
|
21
21
|
|
22
22
|
RP.redis.set(key, value.to_json)
|
23
23
|
RP.redis.expire(key, RP.duration.to_i)
|
24
|
+
|
24
25
|
true
|
25
26
|
end
|
26
27
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rails_performance
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.1.
|
4
|
+
version: 0.0.1.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Igor Kasyanchuk
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-01-
|
11
|
+
date: 2020-01-26 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -102,8 +102,9 @@ files:
|
|
102
102
|
- lib/rails_performance/collection.rb
|
103
103
|
- lib/rails_performance/data_source.rb
|
104
104
|
- lib/rails_performance/engine.rb
|
105
|
-
- lib/rails_performance/
|
105
|
+
- lib/rails_performance/metrics_collector.rb
|
106
106
|
- lib/rails_performance/middleware.rb
|
107
|
+
- lib/rails_performance/query_builder.rb
|
107
108
|
- lib/rails_performance/record.rb
|
108
109
|
- lib/rails_performance/requests_report.rb
|
109
110
|
- lib/rails_performance/throughput_report.rb
|