rails_performance 0.0.1.2 → 0.0.1.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 68f35c4eec4521b60ad740040da1a980e517f951444f52563dedf1f9e5958c8a
4
- data.tar.gz: 0b384d8bda35a86b7fbc384b2834829eb2f8bd92edf01d974bd75d139748f749
3
+ metadata.gz: 57398ce57cc6e6707959d81156ffb0b48f8b32f55e25657f1f0a714c89c1bc2c
4
+ data.tar.gz: 1250f710f15e028d1c8ed187cd6e1e9849ad8e0d440cb6eb6bd5eb67ec09d491
5
5
  SHA512:
6
- metadata.gz: ad282e2024c5eadf23eade5c6b02dc31255f8bd1fe34b9b03c2557f5a5d2a1ab640f9b23d13d2e2c0dbf081b6fd4cec2b6ac34bacf6e722e81b8c2de69b5c321
7
- data.tar.gz: 3ef27d25873473bfd87369356ecbd28d57471ce27240513f01d0a546c80ab8790c983b0ad9e9ecc61bddfe0b9c9a64dad8dd274981890dd2e34e69b697724664
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
- @data = RailsPerformance::ThroughputReport.new(@datasource.db).data
11
- @global = RailsPerformance::RequestsReport.new(@datasource.db, group: :controller_action_format, sort: :db_runtime_slowest).data
12
- #@full = RailsPerformance::FullReport.new.data(:controller_action).sort{|a, b| b[:count] <=> a[:count]}
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
@@ -102,5 +102,13 @@
102
102
  color: white;
103
103
  background-color: #282e38;
104
104
  }
105
+ table a {
106
+ color: white;
107
+ }
108
+
109
+ .back_link {
110
+ color: white;
111
+ font-size: 20px;
112
+ }
105
113
 
106
114
  </style>
@@ -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("&larr; 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
- <% @global.each do |e| %>
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 @data.to_json %>;
71
+ var data = <%= raw @throughput_report_data.to_json %>;
68
72
  showRequestsChart('chart', data);
69
73
  </script>
70
74
 
@@ -1,5 +1,6 @@
1
1
  require "redis"
2
2
  require "redis-namespace"
3
+ require_relative "rails_performance/query_builder.rb"
3
4
  require_relative "rails_performance/middleware.rb"
4
5
  require_relative "rails_performance/data_source.rb"
5
6
  require_relative "rails_performance/record.rb"
@@ -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 DataSource.all
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 db(storage = RP::Collection.new)
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
- #puts "\n\n [REDIS] --> #{query}\n\n"
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 './metrics_listener.rb'
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::MetricsListener.new
14
+ RailsPerformance::MetricsCollector.new
15
15
  )
16
16
  end
17
17
 
@@ -1,5 +1,5 @@
1
1
  module RailsPerformance
2
- class MetricsListener
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(MetricsListener::FORMAT)] || 0
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
 
@@ -1,3 +1,3 @@
1
1
  module RailsPerformance
2
- VERSION = '0.0.1.2'
2
+ VERSION = '0.0.1.3'
3
3
  end
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.2
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-25 00:00:00.000000000 Z
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/metrics_listener.rb
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