rails_performance 1.0.3 → 1.0.5

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: b27b8bf73e30b04e7ae40afca4598b348457dcd09bbf30a2ca124e16caa2cf17
4
- data.tar.gz: 36afe9bec764881de9cb6a29510903d7036ae80c8af072ea31018f8a85abbab9
3
+ metadata.gz: 437c85fdb48db55caa5da3b41a7b0344d05e27094637cca6f3e8f28f8a15d284
4
+ data.tar.gz: c4bf8df35605e2cef8de589be79cde872d1a5d5210883140855eb0cf877562d7
5
5
  SHA512:
6
- metadata.gz: f974e6a2ee2ed369a9e73bccd64ae62c150ec2e6dd9324a41f880eaefc7063d309cc597a3a78db9f10d51214cf3949d6a7e784cc5b77b74082dc583913ab6cfd
7
- data.tar.gz: 495d009f627564c2474dfecbd8b50d5b80f4b327fb5e18868443147a7327e1ca2d0ff078b5b8973583ab4aff52989a75213c6aa59d10e99a13b6562f2fd6f09a
6
+ metadata.gz: e54cd14676bde4b86de76a1cc73b482f51dfa9cd7529a658b70bec638e7f0d7eae1af22d60d00e959fbfbd4f3912cce2f6a5c545e8358c949bd0ba0c844e633e
7
+ data.tar.gz: 7c459ccf377434021fc0d2a4348e95e49ea9ef4e741cc7d768e8f9185121bf7fe36c0cd0b6475aa03fd208cb518f764467880542eb38d994baa8484810e5074f
data/README.md CHANGED
@@ -3,10 +3,11 @@
3
3
  [![Tests](https://github.com/igorkasyanchuk/rails_performance/actions/workflows/ruby.yml/badge.svg)](https://github.com/igorkasyanchuk/rails_performance/actions/workflows/ruby.yml)
4
4
  [![RailsJazz](https://github.com/igorkasyanchuk/rails_time_travel/blob/main/docs/my_other.svg?raw=true)](https://www.railsjazz.com)
5
5
  [![https://www.patreon.com/igorkasyanchuk](https://github.com/igorkasyanchuk/rails_time_travel/blob/main/docs/patron.svg?raw=true)](https://www.patreon.com/igorkasyanchuk)
6
+ [![Listed on OpenSource-Heroes.com](https://opensource-heroes.com/badge-v1.svg)](https://opensource-heroes.com/r/igorkasyanchuk/rails_performance)
6
7
 
7
8
  A self-hosted tool to monitor the performance of your Ruby on Rails application.
8
9
 
9
- This is **simple and free alternative** to the New Relic APM, Datadog or other similar services.
10
+ This is a **simple and free alternative** to the New Relic APM, Datadog or other similar services.
10
11
 
11
12
  ![Demo](docs/rails_performance.gif)
12
13
 
@@ -70,8 +71,19 @@ RailsPerformance.setup do |config|
70
71
  # for example when you have `current_user`
71
72
  # config.verify_access_proc = proc { |controller| controller.current_user && controller.current_user.admin? }
72
73
 
74
+ # store custom data for the request
75
+ # config.custom_data_proc = proc do |env|
76
+ # request = Rack::Request.new(env)
77
+ # {
78
+ # email: request.env['warden'].user&.email, # if you are using Devise for example
79
+ # user_agent: request.env['HTTP_USER_AGENT']
80
+ # }
81
+ # end
82
+
73
83
  # config home button link
74
84
  config.home_link = '/'
85
+
86
+ config.skipable_rake_tasks = ['webpacker:compile']
75
87
  end if defined?(RailsPerformance)
76
88
  ```
77
89
 
@@ -209,10 +221,11 @@ If "schema" how records are stored i Redis is changed, and this is a breacking c
209
221
  - https://github.com/PedroAugustoRamalhoDuarte
210
222
  - https://github.com/haffla
211
223
  - https://github.com/D1ceWard
224
+ - https://github.com/carl-printreleaf
212
225
 
213
226
  ## License
214
227
 
215
228
  The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
216
229
 
217
230
  [<img src="https://github.com/igorkasyanchuk/rails_time_travel/blob/main/docs/more_gems.png?raw=true"
218
- />](https://www.railsjazz.com/)
231
+ />](https://www.railsjazz.com/?utm_source=github&utm_medium=bottom&utm_campaign=rails_performance)
@@ -181,7 +181,7 @@ if(recent) {
181
181
  return;
182
182
  }
183
183
 
184
- fetch(`/rails/performance/recent.js?from_timei=${from_timei}`, {
184
+ fetch(`recent.js?from_timei=${from_timei}`, {
185
185
  headers: {
186
186
  "X-CSRF-Token": document.querySelector("[name='csrf-token']").content,
187
187
  },
@@ -20,4 +20,4 @@
20
20
  </tr>
21
21
  <% end %>
22
22
  </tbody>
23
- </table>
23
+ </table>
@@ -35,7 +35,7 @@
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 RailsPerformance.home_link, target: '_blank', class: "button is-light home_icon" do %>
38
+ <%= link_to RailsPerformance.home_link, class: "button is-light home_icon" do %>
39
39
  <%= icon('home') %>
40
40
  <% end %>
41
41
  </div>
@@ -81,6 +81,9 @@
81
81
  border-bottom: 1px solid red;
82
82
  }
83
83
 
84
+ .card-content {
85
+ overflow-x: scroll;
86
+ }
84
87
 
85
88
  table th[data-sort] {
86
89
  cursor: pointer;
@@ -92,4 +95,4 @@ table th[data-sort] {
92
95
 
93
96
  #autoupdate_label {
94
97
  cursor: pointer;
95
- }
98
+ }
data/config/routes.rb CHANGED
@@ -1,4 +1,6 @@
1
1
  RailsPerformance::Engine.routes.draw do
2
+ devise_for :users
3
+
2
4
  get '/' => 'rails_performance#index', as: :rails_performance
3
5
 
4
6
  get '/requests' => 'rails_performance#requests', as: :rails_performance_requests
@@ -22,4 +24,4 @@ Rails.application.routes.draw do
22
24
  # already added
23
25
  # this code exist here because engine not includes routing automatically
24
26
  end
25
- end
27
+ end
@@ -21,6 +21,15 @@ RailsPerformance.setup do |config|
21
21
  # You can ignore endpoints with Rails standard notation controller#action
22
22
  # config.ignored_endpoints = ['HomeController#contact']
23
23
 
24
+ # store custom data for the request
25
+ # config.custom_data_proc = proc do |env|
26
+ # request = Rack::Request.new(env)
27
+ # {
28
+ # email: request.env['warden'].user&.email, # if you are using Devise for example
29
+ # user_agent: request.env['HTTP_USER_AGENT']
30
+ # }
31
+ # end
32
+
24
33
  # config home button link
25
34
  config.home_link = '/'
26
35
  end if defined?(RailsPerformance)
@@ -13,13 +13,15 @@ module RailsPerformance
13
13
  status = 'error'
14
14
  raise(ex)
15
15
  ensure
16
- RailsPerformance::Models::RakeRecord.new(
17
- task: RailsPerformance::Gems::RakeExt.find_task_name(*args),
18
- datetime: now.strftime(RailsPerformance::FORMAT),
19
- datetimei: now.to_i,
20
- duration: (Time.now - now) * 1000,
21
- status: status,
22
- ).save
16
+ if !RailsPerformance.skipable_rake_tasks.include?(self.name)
17
+ RailsPerformance::Models::RakeRecord.new(
18
+ task: RailsPerformance::Gems::RakeExt.find_task_name(*args),
19
+ datetime: now.strftime(RailsPerformance::FORMAT),
20
+ datetimei: now.to_i,
21
+ duration: (Time.now - now) * 1000,
22
+ status: status,
23
+ ).save
24
+ end
23
25
  end
24
26
  end
25
27
 
@@ -2,7 +2,7 @@ module RailsPerformance
2
2
  module Models
3
3
  class RequestRecord < BaseRecord
4
4
  attr_accessor :controller, :action, :format, :status, :datetime, :datetimei, :method, :path, :request_id, :json
5
- attr_accessor :view_runtime, :db_runtime, :duration, :http_referer
5
+ attr_accessor :view_runtime, :db_runtime, :duration, :http_referer, :custom_data
6
6
  attr_accessor :exception, :exception_object
7
7
 
8
8
  def RequestRecord.find_by(request_id:)
@@ -25,7 +25,7 @@ module RailsPerformance
25
25
  # path|/|
26
26
  # request_id|454545454545454545|
27
27
  # END|1.0.0
28
- # = {"view_runtime":null,"db_runtime":0,"duration":27.329741000000002,"http_referer":null,"exception":"ZeroDivisionError divided by 0","backtrace":["/root/projects/rails_performance/test/dummy/app/controllers/account/site_controller.rb:17:in `/'","/root/projects/rails_performance/test/dummy/app/controllers/account/site_controller.rb:17:in `crash'","/usr/local/rvm/gems/ruby-2.6.3/gems/actionpack-6.1.3.1/lib/action_controller/metal/basic_implicit_render.rb:6:in `send_action'"]}
28
+ # = {"view_runtime":null,"db_runtime":0,"duration":27.329741000000002,"http_referer":null,"custom_data":null,"exception":"ZeroDivisionError divided by 0","backtrace":["/root/projects/rails_performance/test/dummy/app/controllers/account/site_controller.rb:17:in `/'","/root/projects/rails_performance/test/dummy/app/controllers/account/site_controller.rb:17:in `crash'","/usr/local/rvm/gems/ruby-2.6.3/gems/actionpack-6.1.3.1/lib/action_controller/metal/basic_implicit_render.rb:6:in `send_action'"]}
29
29
  # value = JSON
30
30
  def RequestRecord.from_db(key, value)
31
31
  items = key.split("|")
@@ -44,26 +44,27 @@ module RailsPerformance
44
44
  )
45
45
  end
46
46
 
47
- def initialize(controller:, action:, format:, status:, datetime:, datetimei:, method:, path:, request_id:, view_runtime: nil, db_runtime: nil, duration: nil, http_referer: nil, exception: nil, exception_object: nil, json: '{}')
48
- @controller = controller
49
- @action = action
50
- @format = format
51
- @status = status
52
- @datetime = datetime
53
- @datetimei = datetimei.to_i
54
- @method = method
55
- @path = path
56
- @request_id = request_id
47
+ def initialize(controller:, action:, format:, status:, datetime:, datetimei:, method:, path:, request_id:, view_runtime: nil, db_runtime: nil, duration: nil, http_referer: nil, custom_data: nil, exception: nil, exception_object: nil, json: '{}')
48
+ @controller = controller
49
+ @action = action
50
+ @format = format
51
+ @status = status
52
+ @datetime = datetime
53
+ @datetimei = datetimei.to_i
54
+ @method = method
55
+ @path = path
56
+ @request_id = request_id
57
57
 
58
58
  @view_runtime = view_runtime
59
59
  @db_runtime = db_runtime
60
60
  @duration = duration
61
61
  @http_referer = http_referer
62
+ @custom_data = custom_data
62
63
 
63
64
  @exception = Array.wrap(exception).compact.join(" ")
64
65
  @exception_object = exception_object
65
66
 
66
- @json = json
67
+ @json = json
67
68
  end
68
69
 
69
70
  def controller_action
@@ -74,6 +75,7 @@ module RailsPerformance
74
75
  "#{controller}##{action}|#{format}"
75
76
  end
76
77
 
78
+ # show on UI in the right panel
77
79
  def record_hash
78
80
  {
79
81
  controller: self.controller,
@@ -89,8 +91,14 @@ module RailsPerformance
89
91
  db_runtime: self.value['db_runtime'],
90
92
  view_runtime: self.value['view_runtime'],
91
93
  exception: self.value['exception'],
92
- backtrace: self.value['backtrace']
93
- }
94
+ backtrace: self.value['backtrace'],
95
+ http_referer: self.value['http_referer']
96
+ }.tap do |h|
97
+ custom_data = JSON.parse(self.value['custom_data']) rescue nil
98
+ if custom_data.is_a?(Hash)
99
+ h.merge!(custom_data)
100
+ end
101
+ end
94
102
  end
95
103
 
96
104
  def save
@@ -100,6 +108,7 @@ module RailsPerformance
100
108
  db_runtime: db_runtime,
101
109
  duration: duration,
102
110
  http_referer: http_referer,
111
+ custom_data: custom_data.to_json
103
112
  }
104
113
  value[:exception] = exception if exception.present?
105
114
  value[:backtrace] = exception_object.backtrace.take(3) if exception_object
@@ -108,4 +117,4 @@ module RailsPerformance
108
117
 
109
118
  end
110
119
  end
111
- end
120
+ end
@@ -53,6 +53,13 @@ module RailsPerformance
53
53
  # capture referer from where this page was opened
54
54
  record.http_referer = env["HTTP_REFERER"] if record.status == 404
55
55
 
56
+ # we can add custom data, for example Http User-Agent
57
+ # or even devise current_user
58
+ if RailsPerformance.custom_data_proc
59
+ # just to be sure it won't break format how we store in redis
60
+ record.custom_data = RailsPerformance.custom_data_proc.call(env)
61
+ end
62
+
56
63
  # store for section "recent requests"
57
64
  # store request information (regular rails request)
58
65
  record.save
@@ -66,4 +73,4 @@ module RailsPerformance
66
73
 
67
74
  end
68
75
  end
69
- end
76
+ end
@@ -1,4 +1,4 @@
1
1
  module RailsPerformance
2
- VERSION = '1.0.3'
2
+ VERSION = '1.0.5'
3
3
  SCHEMA = '1.0.1'
4
- end
4
+ end
@@ -73,12 +73,20 @@ module RailsPerformance
73
73
  mattr_accessor :home_link
74
74
  @@home_link = '/'
75
75
 
76
+ # skip performance tracking for these rake tasks
77
+ mattr_accessor :skipable_rake_tasks
78
+ @@skipable_rake_tasks = []
79
+
80
+ # add custom payload to the request
81
+ mattr_accessor :custom_data_proc
82
+ @@custom_data_proc = []
83
+
76
84
  def RailsPerformance.setup
77
85
  yield(self)
78
86
  end
79
87
 
80
88
  def RailsPerformance.log(message)
81
- return
89
+ return unless RailsPerformance.debug
82
90
 
83
91
  if ::Rails.logger
84
92
  # puts(message)
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.3
4
+ version: 1.0.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Igor Kasyanchuk
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-05-14 00:00:00.000000000 Z
11
+ date: 2023-04-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -192,6 +192,20 @@ dependencies:
192
192
  - - ">="
193
193
  - !ruby/object:Gem::Version
194
194
  version: '0'
195
+ - !ruby/object:Gem::Dependency
196
+ name: sprockets-rails
197
+ requirement: !ruby/object:Gem::Requirement
198
+ requirements:
199
+ - - ">="
200
+ - !ruby/object:Gem::Version
201
+ version: '0'
202
+ type: :development
203
+ prerelease: false
204
+ version_requirements: !ruby/object:Gem::Requirement
205
+ requirements:
206
+ - - ">="
207
+ - !ruby/object:Gem::Version
208
+ version: '0'
195
209
  description: 3rd party dependency-free solution how to monitor performance of your
196
210
  Rails applications.
197
211
  email:
@@ -301,7 +315,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
301
315
  - !ruby/object:Gem::Version
302
316
  version: '0'
303
317
  requirements: []
304
- rubygems_version: 3.2.3
318
+ rubygems_version: 3.3.7
305
319
  signing_key:
306
320
  specification_version: 4
307
321
  summary: Simple Rails Performance tracker. Alternative to the NewRelic, Datadog or