rails_performance 1.0.0 → 1.0.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: 5da13053dd45132a995aa83cd0a1514bf44bd0ca9acdac19898f2d23674171c8
4
- data.tar.gz: de1e1dee044deed998dcaf3cc863301f7c3f4c732adb06efa98427f6797a79db
3
+ metadata.gz: b27b8bf73e30b04e7ae40afca4598b348457dcd09bbf30a2ca124e16caa2cf17
4
+ data.tar.gz: 36afe9bec764881de9cb6a29510903d7036ae80c8af072ea31018f8a85abbab9
5
5
  SHA512:
6
- metadata.gz: 4ed1e54a27941fba93ec958dce9eee09c926350e2906be2e91ff1458f751ed6bd37b29732f8ca0629137bd189796c3dc5e9f0eddab332e06512f76db1b6235a6
7
- data.tar.gz: 49e036a7f777488c4c8cd90e0927b3969d2d5dd0d057ebdb8aa2b9e759a233ba0cd4652a2bcc0374517d101fa2f0ccbf12d6d856546b09f7ebfe9db51404a6f2
6
+ metadata.gz: f974e6a2ee2ed369a9e73bccd64ae62c150ec2e6dd9324a41f880eaefc7063d309cc597a3a78db9f10d51214cf3949d6a7e784cc5b77b74082dc583913ab6cfd
7
+ data.tar.gz: 495d009f627564c2474dfecbd8b50d5b80f4b327fb5e18868443147a7327e1ca2d0ff078b5b8973583ab4aff52989a75213c6aa59d10e99a13b6562f2fd6f09a
data/README.md CHANGED
@@ -12,6 +12,7 @@ This is **simple and free alternative** to the New Relic APM, Datadog or other s
12
12
 
13
13
  It allows you to track:
14
14
 
15
+ - real-time monitoring on the Recent tab
15
16
  - throughput report (see amount of RPM (requests per minute))
16
17
  - an average response time
17
18
  - the slowest controllers & actions
@@ -68,6 +69,9 @@ RailsPerformance.setup do |config|
68
69
  config.verify_access_proc = proc { |controller| true }
69
70
  # for example when you have `current_user`
70
71
  # config.verify_access_proc = proc { |controller| controller.current_user && controller.current_user.admin? }
72
+
73
+ # config home button link
74
+ config.home_link = '/'
71
75
  end if defined?(RailsPerformance)
72
76
  ```
73
77
 
@@ -119,7 +123,13 @@ Rails.application.routes.draw do
119
123
  end
120
124
  ```
121
125
 
126
+ ### Custom events
122
127
 
128
+ ```ruby
129
+ RailsPerformance.measure("some label", "some namespace") do
130
+ # your code
131
+ end
132
+ ```
123
133
 
124
134
  ## How it works
125
135
 
@@ -198,6 +208,7 @@ If "schema" how records are stored i Redis is changed, and this is a breacking c
198
208
  - https://github.com/jules2689
199
209
  - https://github.com/PedroAugustoRamalhoDuarte
200
210
  - https://github.com/haffla
211
+ - https://github.com/D1ceWard
201
212
 
202
213
  ## License
203
214
 
@@ -4,6 +4,8 @@ module RailsPerformance
4
4
  class RailsPerformanceController < RailsPerformance::BaseController
5
5
  include RailsPerformance::ApplicationHelper
6
6
 
7
+ protect_from_forgery except: :recent
8
+
7
9
  if RailsPerformance.enabled
8
10
  def index
9
11
  @datasource = RailsPerformance::DataSource.new(**prepare_query, type: :requests)
@@ -51,7 +53,12 @@ module RailsPerformance
51
53
  def recent
52
54
  @datasource = RailsPerformance::DataSource.new(**prepare_query, type: :requests)
53
55
  db = @datasource.db
54
- @data = RailsPerformance::Reports::RecentRequestsReport.new(db).data
56
+ @data = RailsPerformance::Reports::RecentRequestsReport.new(db).data(params[:from_timei])
57
+
58
+ respond_to do |page|
59
+ page.html
60
+ page.js
61
+ end
55
62
  end
56
63
 
57
64
  def sidekiq
@@ -12,3 +12,4 @@
12
12
  <%= insert_js_file 'app.js' %>
13
13
  <%= insert_js_file 'panel.js' %>
14
14
  <%= insert_js_file 'table.js' %>
15
+ <%= insert_js_file 'navbar.js' %>
@@ -165,4 +165,30 @@ function showRTChart(div, data) {
165
165
  }
166
166
  }]
167
167
  });
168
- };
168
+ };
169
+
170
+ const recent = document.getElementById("recent")
171
+ const autoupdate = document.getElementById("autoupdate")
172
+
173
+ if(recent) {
174
+ const tbody = recent.querySelector("tbody")
175
+
176
+ setInterval(() => {
177
+ tr = tbody.children[0];
178
+ from_timei = tr.getAttribute("from_timei") || ''
179
+
180
+ if (!autoupdate.checked) {
181
+ return;
182
+ }
183
+
184
+ fetch(`/rails/performance/recent.js?from_timei=${from_timei}`, {
185
+ headers: {
186
+ "X-CSRF-Token": document.querySelector("[name='csrf-token']").content,
187
+ },
188
+ })
189
+ .then(res => res.text())
190
+ .then(html => {
191
+ tbody.innerHTML = html + tbody.innerHTML;
192
+ })
193
+ }, 3000);
194
+ }
@@ -0,0 +1,8 @@
1
+ $(document).ready(function() {
2
+ // Check for click events on the navbar burger icon
3
+ $(".navbar-burger").click(function() {
4
+ // Toggle the "is-active" class on both the "navbar-burger" and the "navbar-menu"
5
+ $(".navbar-burger").toggleClass("is-active");
6
+ $(".navbar-menu").toggleClass("is-active");
7
+ });
8
+ });
@@ -0,0 +1,25 @@
1
+ <tr from_timei="<%= e[:datetimei] %>">
2
+ <td>
3
+ <% if e[:request_id].present? %>
4
+ <%= link_to rails_performance.rails_performance_trace_path(id: e[:request_id]), remote: true do %>
5
+ <span class="stats_icon_max"><%= icon 'activity' %></span>
6
+ <% end %>
7
+ <% end %>
8
+ </td>
9
+ <td><%= format_datetime e[:datetime] %></td>
10
+ <td><%= link_to e[:controller] + '#' + e[:action], rails_performance.rails_performance_summary_path({controller_eq: e[:controller], action_eq: e[:action]}), remote: true %></td>
11
+ <td><%= e[:method] %></td>
12
+ <td><%= e[:format] %></td>
13
+ <td><%= link_to_path(e) %></td>
14
+ <td><%= status_tag e[:status] %></td>
15
+ <td class="nowrap"><%= ms e[:duration] %></td>
16
+ <td class="nowrap"><%= ms e[:view_runtime] %></td>
17
+ <td class="nowrap"><%= ms e[:db_runtime] %></td>
18
+ <td>
19
+ <% if e[:request_id].present? %>
20
+ <%= link_to rails_performance.rails_performance_trace_path(id: e[:request_id]), remote: true do %>
21
+ <span class="stats_icon_max"><%= icon 'activity' %></span>
22
+ <% end %>
23
+ <% end %>
24
+ </td>
25
+ </tr>
@@ -2,9 +2,19 @@
2
2
 
3
3
  <div class="card">
4
4
  <div class="card-content">
5
- <h2 class="subtitle">Recent Requests (last <%= RailsPerformance::Reports::RecentRequestsReport::TIME_WINDOW / 60 %> minutes)<h2>
5
+ <div class="columns">
6
+ <div class="column">
7
+ <h2 class="subtitle">Recent Requests (last <%= RailsPerformance::Reports::RecentRequestsReport::TIME_WINDOW / 60 %> minutes)<h2>
8
+ </div>
9
+ <div class="column right-text is-size-5 has-text-right">
10
+ <label id="autoupdate_label">
11
+ <input id="autoupdate" type="checkbox" checked/>
12
+ Auto-update
13
+ </label>
14
+ </div>
15
+ </div>
6
16
 
7
- <table class="table is-fullwidth is-hoverable is-narrow">
17
+ <table id="recent" class="table is-fullwidth is-hoverable is-narrow">
8
18
  <thead>
9
19
  <tr>
10
20
  <th data-sort="string"></th>
@@ -27,33 +37,10 @@
27
37
  </tr>
28
38
  <% end %>
29
39
  <% @data.each do |e| %>
30
- <tr>
31
- <td>
32
- <% if e[:request_id].present? %>
33
- <%= link_to rails_performance.rails_performance_trace_path(id: e[:request_id]), remote: true do %>
34
- <span class="stats_icon_max"><%= icon 'activity' %></span>
35
- <% end %>
36
- <% end %>
37
- </td>
38
- <td><%= format_datetime e[:datetime] %></td>
39
- <td><%= link_to e[:controller] + '#' + e[:action], rails_performance.rails_performance_summary_path({controller_eq: e[:controller], action_eq: e[:action]}), remote: true %></td>
40
- <td><%= e[:method] %></td>
41
- <td><%= e[:format] %></td>
42
- <td><%= link_to_path(e) %></td>
43
- <td><%= status_tag e[:status] %></td>
44
- <td class="nowrap"><%= ms e[:duration] %></td>
45
- <td class="nowrap"><%= ms e[:view_runtime] %></td>
46
- <td class="nowrap"><%= ms e[:db_runtime] %></td>
47
- <td>
48
- <% if e[:request_id].present? %>
49
- <%= link_to rails_performance.rails_performance_trace_path(id: e[:request_id]), remote: true do %>
50
- <span class="stats_icon_max"><%= icon 'activity' %></span>
51
- <% end %>
52
- <% end %>
53
- </td>
54
- </tr>
40
+ <%= render 'recent_row', e: e %>
55
41
  <% end %>
56
42
  </tbody>
57
43
  </table>
58
44
  </div>
59
45
  </div>
46
+
@@ -0,0 +1,3 @@
1
+ <% @data.each do |e| %>
2
+ <%= render 'recent_row', e: e %>
3
+ <% end %>
@@ -35,11 +35,11 @@
35
35
  <div class="navbar-item">
36
36
  <div class="buttons">
37
37
  <%#= link_to 'Export to CSV', '#', target: '_blank', class: "button is-primary" %>
38
- <%= link_to '/', target: '_blank', class: "button is-light home_icon" do %>
38
+ <%= link_to RailsPerformance.home_link, target: '_blank', class: "button is-light home_icon" do %>
39
39
  <%= icon('home') %>
40
40
  <% end %>
41
41
  </div>
42
42
  </div>
43
43
  </div>
44
44
  </div>
45
- </nav>
45
+ </nav>
@@ -88,4 +88,8 @@ table th[data-sort] {
88
88
 
89
89
  .very-small-text {
90
90
  font-size: 8px;
91
+ }
92
+
93
+ #autoupdate_label {
94
+ cursor: pointer;
91
95
  }
@@ -17,7 +17,10 @@ RailsPerformance.setup do |config|
17
17
  config.verify_access_proc = proc { |controller| true }
18
18
  # for example when you have `current_user`
19
19
  # config.verify_access_proc = proc { |controller| controller.current_user && controller.current_user.admin? }
20
-
20
+
21
21
  # You can ignore endpoints with Rails standard notation controller#action
22
22
  # config.ignored_endpoints = ['HomeController#contact']
23
+
24
+ # config home button link
25
+ config.home_link = '/'
23
26
  end if defined?(RailsPerformance)
@@ -56,11 +56,11 @@ module RailsPerformance
56
56
 
57
57
  ActionView::LogSubscriber.send :prepend, RailsPerformance::Extensions::View
58
58
  ActiveRecord::LogSubscriber.send :prepend, RailsPerformance::Extensions::Db
59
- end
60
59
 
61
- if defined?(::Rake::Task)
62
- require_relative './gems/rake_ext.rb'
63
- RailsPerformance::Gems::RakeExt.init
60
+ if defined?(::Rake::Task)
61
+ require_relative './gems/rake_ext.rb'
62
+ RailsPerformance::Gems::RakeExt.init
63
+ end
64
64
  end
65
65
  end
66
66
  end
@@ -7,11 +7,11 @@ module RailsPerformance
7
7
  @sort ||= :datetimei
8
8
  end
9
9
 
10
- def data
11
- time_agoi = TIME_WINDOW.ago.to_i
10
+ def data(from_timei = nil)
11
+ time_agoi = [TIME_WINDOW.ago.to_i, from_timei.to_i].reject(&:blank?).max
12
12
  db.data
13
13
  .collect{|e| e.record_hash}
14
- .select{|e| e if e[sort] >= time_agoi}
14
+ .select{|e| e if e[sort] > time_agoi}
15
15
  .sort{|a, b| b[sort] <=> a[sort]}
16
16
  end
17
17
  end
@@ -1,4 +1,4 @@
1
1
  module RailsPerformance
2
- VERSION = '1.0.0'
2
+ VERSION = '1.0.3'
3
3
  SCHEMA = '1.0.1'
4
4
  end
@@ -69,6 +69,10 @@ module RailsPerformance
69
69
  mattr_accessor :skip
70
70
  @@skip = false
71
71
 
72
+ # config home button link
73
+ mattr_accessor :home_link
74
+ @@home_link = '/'
75
+
72
76
  def RailsPerformance.setup
73
77
  yield(self)
74
78
  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: 1.0.0
4
+ version: 1.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Igor Kasyanchuk
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-04-26 00:00:00.000000000 Z
11
+ date: 2022-05-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -164,6 +164,34 @@ dependencies:
164
164
  - - ">="
165
165
  - !ruby/object:Gem::Version
166
166
  version: '0'
167
+ - !ruby/object:Gem::Dependency
168
+ name: wrapped_print
169
+ requirement: !ruby/object:Gem::Requirement
170
+ requirements:
171
+ - - ">="
172
+ - !ruby/object:Gem::Version
173
+ version: '0'
174
+ type: :development
175
+ prerelease: false
176
+ version_requirements: !ruby/object:Gem::Requirement
177
+ requirements:
178
+ - - ">="
179
+ - !ruby/object:Gem::Version
180
+ version: '0'
181
+ - !ruby/object:Gem::Dependency
182
+ name: puma
183
+ requirement: !ruby/object:Gem::Requirement
184
+ requirements:
185
+ - - ">="
186
+ - !ruby/object:Gem::Version
187
+ version: '0'
188
+ type: :development
189
+ prerelease: false
190
+ version_requirements: !ruby/object:Gem::Requirement
191
+ requirements:
192
+ - - ">="
193
+ - !ruby/object:Gem::Version
194
+ version: '0'
167
195
  description: 3rd party dependency-free solution how to monitor performance of your
168
196
  Rails applications.
169
197
  email:
@@ -192,11 +220,13 @@ files:
192
220
  - app/views/rails_performance/javascripts/_javascripts.html.erb
193
221
  - app/views/rails_performance/javascripts/app.js
194
222
  - app/views/rails_performance/javascripts/jquery-3.4.1.min.js
223
+ - app/views/rails_performance/javascripts/navbar.js
195
224
  - app/views/rails_performance/javascripts/panel.js
196
225
  - app/views/rails_performance/javascripts/rails.js
197
226
  - app/views/rails_performance/javascripts/stupidtable.min.js
198
227
  - app/views/rails_performance/javascripts/table.js
199
228
  - app/views/rails_performance/layouts/rails_performance.html.erb
229
+ - app/views/rails_performance/rails_performance/_recent_row.html.erb
200
230
  - app/views/rails_performance/rails_performance/_summary.html.erb
201
231
  - app/views/rails_performance/rails_performance/_trace.html.erb
202
232
  - app/views/rails_performance/rails_performance/crashes.html.erb
@@ -206,6 +236,7 @@ files:
206
236
  - app/views/rails_performance/rails_performance/index.html.erb
207
237
  - app/views/rails_performance/rails_performance/rake.html.erb
208
238
  - app/views/rails_performance/rails_performance/recent.html.erb
239
+ - app/views/rails_performance/rails_performance/recent.js.erb
209
240
  - app/views/rails_performance/rails_performance/requests.html.erb
210
241
  - app/views/rails_performance/rails_performance/sidekiq.html.erb
211
242
  - app/views/rails_performance/rails_performance/summary.js.erb
@@ -255,7 +286,7 @@ homepage: https://github.com/igorkasyanchuk/rails_performance
255
286
  licenses:
256
287
  - MIT
257
288
  metadata: {}
258
- post_install_message:
289
+ post_install_message:
259
290
  rdoc_options: []
260
291
  require_paths:
261
292
  - lib
@@ -270,8 +301,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
270
301
  - !ruby/object:Gem::Version
271
302
  version: '0'
272
303
  requirements: []
273
- rubygems_version: 3.0.3
274
- signing_key:
304
+ rubygems_version: 3.2.3
305
+ signing_key:
275
306
  specification_version: 4
276
307
  summary: Simple Rails Performance tracker. Alternative to the NewRelic, Datadog or
277
308
  other services.