rails_performance 1.4.0.alpha3 → 1.4.0.alpha4
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/README.md +13 -1
- data/app/helpers/rails_performance/rails_performance_helper.rb +0 -4
- data/app/views/rails_performance/javascripts/app.js +6 -0
- data/app/views/rails_performance/layouts/rails_performance.html.erb +3 -0
- data/lib/rails_performance/data_source.rb +1 -1
- data/lib/rails_performance/extensions/resources_monitor.rb +1 -3
- data/lib/rails_performance/gems/custom_ext.rb +2 -2
- data/lib/rails_performance/gems/delayed_job_ext.rb +2 -2
- data/lib/rails_performance/gems/grape_ext.rb +1 -1
- data/lib/rails_performance/gems/rake_ext.rb +2 -2
- data/lib/rails_performance/gems/sidekiq_ext.rb +2 -2
- data/lib/rails_performance/instrument/metrics_collector.rb +2 -0
- data/lib/rails_performance/models/base_record.rb +1 -15
- data/lib/rails_performance/models/custom_record.rb +1 -1
- data/lib/rails_performance/models/delayed_job_record.rb +1 -1
- data/lib/rails_performance/models/grape_record.rb +1 -1
- data/lib/rails_performance/models/rake_record.rb +1 -1
- data/lib/rails_performance/models/request_record.rb +1 -1
- data/lib/rails_performance/models/resource_record.rb +1 -1
- data/lib/rails_performance/models/sidekiq_record.rb +1 -1
- data/lib/rails_performance/rails/middleware.rb +2 -2
- data/lib/rails_performance/reports/base_report.rb +8 -7
- data/lib/rails_performance/reports/resources_report.rb +0 -7
- data/lib/rails_performance/thread/current_request.rb +1 -1
- data/lib/rails_performance/utils.rb +9 -1
- data/lib/rails_performance/version.rb +2 -2
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9ef083c7a88c7f7f263c3e5fe97049c589889e19494736b839de788c97e88aea
|
4
|
+
data.tar.gz: 361e9148f1ee28ebebb0e22a3c3dd6b9cf9ab440a4d2a594d534d6824ba300f3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d5d56892de5cc66ce1b324b4cc00f021bd582b4cda43d11e36e1a0506ff38f82448ade9785a17662d575867236b424a5a165506753b872012514895370f58c72
|
7
|
+
data.tar.gz: 7fa77548d06a0c157fd5f7ceb46578e91e6d3a6ce239df3701c5abb74dab25eb5aaa53e849fc8fcae2aca6a013d5e83eda80d3d70289f99f6450331d58e6e984
|
data/README.md
CHANGED
@@ -175,7 +175,9 @@ You need to configure `config.custom_data_proc`. And you can capture current_use
|
|
175
175
|

|
176
176
|
|
177
177
|
|
178
|
-
###
|
178
|
+
### Server Monitoring
|
179
|
+
|
180
|
+

|
179
181
|
|
180
182
|
You can monitor system resources (CPU, memory, disk) by adding a gem to your Gemfile:
|
181
183
|
|
@@ -197,6 +199,14 @@ Basically using this code:
|
|
197
199
|
end
|
198
200
|
```
|
199
201
|
|
202
|
+
For Kamal for example:
|
203
|
+
|
204
|
+
```yaml
|
205
|
+
env:
|
206
|
+
clear:
|
207
|
+
RAILS_PERFORMANCE_SERVER_ID: "server"
|
208
|
+
```
|
209
|
+
|
200
210
|
You can also specifify custom "context" and "role" for monitoring, by changing the env variables:
|
201
211
|
|
202
212
|
```ruby
|
@@ -260,6 +270,8 @@ After this:
|
|
260
270
|
- rails s
|
261
271
|
- rake test
|
262
272
|
|
273
|
+
If you need quickly clear Redis data, you can use `rails runner 'RailsPerformance.redis.flushdb'`.
|
274
|
+
|
263
275
|
Like a regular web development.
|
264
276
|
|
265
277
|
Please note that to simplify integration with other apps all CSS/JS are bundled inside, and delivered in body of the request. This is to avoid integration with assets pipeline or webpacker.
|
@@ -6,6 +6,9 @@
|
|
6
6
|
<title>Rails Performance</title>
|
7
7
|
<%= csrf_meta_tags %>
|
8
8
|
<%= csp_meta_tag if ::Rails::VERSION::STRING.to_f >= 5.2 %>
|
9
|
+
<script>
|
10
|
+
window.APP_TIME_ZONE = '<%= Rails.application.config.time_zone.presence || 'UTC' %>';
|
11
|
+
</script>
|
9
12
|
<%= render '/rails_performance/stylesheets/stylesheets' %>
|
10
13
|
<link rel="shortcut icon" href="/favicon.ico">
|
11
14
|
</head>
|
@@ -21,7 +21,7 @@ module RailsPerformance
|
|
21
21
|
|
22
22
|
def db
|
23
23
|
result = RailsPerformance::Models::Collection.new
|
24
|
-
now =
|
24
|
+
now = RailsPerformance::Utils.time
|
25
25
|
(0..(RailsPerformance::Utils.days)).to_a.reverse_each do |e|
|
26
26
|
RailsPerformance::DataSource.new(q: q.merge({on: (now - e.days).to_date}), type: type).add_to(result)
|
27
27
|
end
|
@@ -18,7 +18,6 @@ module RailsPerformance
|
|
18
18
|
@mutex.synchronize do
|
19
19
|
return if @thread
|
20
20
|
|
21
|
-
# puts "Starting monitoring for #{context} - #{role}"
|
22
21
|
@thread = Thread.new do
|
23
22
|
loop do
|
24
23
|
run
|
@@ -35,7 +34,6 @@ module RailsPerformance
|
|
35
34
|
@mutex.synchronize do
|
36
35
|
return unless @thread
|
37
36
|
|
38
|
-
# puts "Stopping monitoring"
|
39
37
|
@thread.kill
|
40
38
|
@thread = nil
|
41
39
|
end
|
@@ -83,7 +81,7 @@ module RailsPerformance
|
|
83
81
|
def store_data(data)
|
84
82
|
::Rails.logger.info("Server: #{server_id}, Context: #{context}, Role: #{role}, data: #{data}")
|
85
83
|
|
86
|
-
now =
|
84
|
+
now = RailsPerformance::Utils.time
|
87
85
|
now = now.change(sec: 0, usec: 0)
|
88
86
|
RailsPerformance::Models::ResourceRecord.new(
|
89
87
|
server: server_id,
|
@@ -8,7 +8,7 @@ module RailsPerformance
|
|
8
8
|
return yield unless RailsPerformance.include_custom_events
|
9
9
|
|
10
10
|
begin
|
11
|
-
now =
|
11
|
+
now = RailsPerformance::Utils.time
|
12
12
|
status = "success"
|
13
13
|
result = yield
|
14
14
|
result
|
@@ -20,7 +20,7 @@ module RailsPerformance
|
|
20
20
|
tag_name: tag_name,
|
21
21
|
namespace_name: namespace_name,
|
22
22
|
status: status,
|
23
|
-
duration: (
|
23
|
+
duration: (RailsPerformance::Utils.time - now) * 1000,
|
24
24
|
datetime: now.strftime(RailsPerformance::FORMAT),
|
25
25
|
datetimei: now.to_i
|
26
26
|
).save
|
@@ -4,7 +4,7 @@ module RailsPerformance
|
|
4
4
|
class Plugin < ::Delayed::Plugin
|
5
5
|
callbacks do |lifecycle|
|
6
6
|
lifecycle.around(:invoke_job) do |job, *args, &block|
|
7
|
-
now =
|
7
|
+
now = RailsPerformance::Utils.time
|
8
8
|
block.call(job, *args)
|
9
9
|
status = "success"
|
10
10
|
rescue Exception => error # rubocop:disable Lint/RescueException
|
@@ -14,7 +14,7 @@ module RailsPerformance
|
|
14
14
|
meta_data = RailsPerformance::Gems::DelayedJobExt::Plugin.meta(job.payload_object)
|
15
15
|
record = RailsPerformance::Models::DelayedJobRecord.new(
|
16
16
|
jid: job.id,
|
17
|
-
duration: (
|
17
|
+
duration: (RailsPerformance::Utils.time - now) * 1000,
|
18
18
|
datetime: now.strftime(RailsPerformance::FORMAT),
|
19
19
|
datetimei: now.to_i,
|
20
20
|
source_type: meta_data[0],
|
@@ -6,7 +6,7 @@ module RailsPerformance
|
|
6
6
|
# TODO change to set
|
7
7
|
CurrentRequest.current.ignore.add(:performance)
|
8
8
|
|
9
|
-
now =
|
9
|
+
now = RailsPerformance::Utils.time
|
10
10
|
CurrentRequest.current.data ||= {}
|
11
11
|
CurrentRequest.current.record ||= RailsPerformance::Models::GrapeRecord.new(request_id: CurrentRequest.current.request_id)
|
12
12
|
CurrentRequest.current.record.datetimei ||= now.to_i
|
@@ -4,7 +4,7 @@ module RailsPerformance
|
|
4
4
|
def self.init
|
5
5
|
::Rake::Task.class_eval do
|
6
6
|
def invoke_with_rails_performance(*args)
|
7
|
-
now =
|
7
|
+
now = RailsPerformance::Utils.time
|
8
8
|
status = "success"
|
9
9
|
invoke_without_new_rails_performance(*args)
|
10
10
|
rescue Exception => ex # rubocop:disable Lint/RescueException
|
@@ -18,7 +18,7 @@ module RailsPerformance
|
|
18
18
|
task: task_info,
|
19
19
|
datetime: now.strftime(RailsPerformance::FORMAT),
|
20
20
|
datetimei: now.to_i,
|
21
|
-
duration: (
|
21
|
+
duration: (RailsPerformance::Utils.time - now) * 1000,
|
22
22
|
status: status
|
23
23
|
).save
|
24
24
|
end
|
@@ -5,7 +5,7 @@ module RailsPerformance
|
|
5
5
|
end
|
6
6
|
|
7
7
|
def call(worker, msg, queue)
|
8
|
-
now =
|
8
|
+
now = RailsPerformance::Utils.time
|
9
9
|
record = RailsPerformance::Models::SidekiqRecord.new(
|
10
10
|
enqueued_ati: msg["enqueued_at"].to_i,
|
11
11
|
datetimei: msg["created_at"].to_i,
|
@@ -25,7 +25,7 @@ module RailsPerformance
|
|
25
25
|
raise ex
|
26
26
|
ensure
|
27
27
|
# store in ms instead of seconds
|
28
|
-
record.duration = (
|
28
|
+
record.duration = (RailsPerformance::Utils.time - now) * 1000
|
29
29
|
record.save
|
30
30
|
end
|
31
31
|
end
|
@@ -25,6 +25,8 @@ module RailsPerformance
|
|
25
25
|
return if RailsPerformance.ignored_endpoints.include? "#{event.payload[:controller]}##{event.payload[:action]}"
|
26
26
|
return if RailsPerformance.ignored_paths.any? { |p| event.payload[:path].start_with?(p) }
|
27
27
|
|
28
|
+
finished = finished.utc
|
29
|
+
|
28
30
|
record = {
|
29
31
|
controller: event.payload[:controller],
|
30
32
|
action: event.payload[:action],
|
@@ -1,18 +1,6 @@
|
|
1
1
|
module RailsPerformance
|
2
2
|
module Models
|
3
3
|
class BaseRecord
|
4
|
-
def self.from_db(key, value)
|
5
|
-
raise "implement me"
|
6
|
-
end
|
7
|
-
|
8
|
-
def save
|
9
|
-
raise "implement me"
|
10
|
-
end
|
11
|
-
|
12
|
-
def record_hash
|
13
|
-
raise "implement me"
|
14
|
-
end
|
15
|
-
|
16
4
|
def value
|
17
5
|
@value ||= JSON.parse(@json || "{}")
|
18
6
|
end
|
@@ -24,9 +12,7 @@ module RailsPerformance
|
|
24
12
|
private
|
25
13
|
|
26
14
|
def ms(e)
|
27
|
-
if e
|
28
|
-
e.to_f.round(1).to_s + " ms"
|
29
|
-
end
|
15
|
+
e.to_f.round(1).to_s + " ms" if e
|
30
16
|
end
|
31
17
|
end
|
32
18
|
end
|
@@ -94,7 +94,7 @@ module RailsPerformance
|
|
94
94
|
method: method,
|
95
95
|
path: path,
|
96
96
|
request_id: request_id,
|
97
|
-
datetime:
|
97
|
+
datetime: RailsPerformance::Utils.from_datetimei(datetimei.to_i),
|
98
98
|
datetimei: datetimei,
|
99
99
|
duration: value["duration"],
|
100
100
|
db_runtime: value["db_runtime"],
|
@@ -31,7 +31,7 @@ module RailsPerformance
|
|
31
31
|
role: role,
|
32
32
|
context: context,
|
33
33
|
datetime: datetime,
|
34
|
-
datetimei:
|
34
|
+
datetimei: RailsPerformance::Utils.from_datetimei(datetimei.to_i),
|
35
35
|
cpu: value["cpu"],
|
36
36
|
memory: value["memory"],
|
37
37
|
disk: value["disk"]
|
@@ -41,7 +41,7 @@ module RailsPerformance
|
|
41
41
|
def call!(env)
|
42
42
|
@status, @headers, @response = @app.call(env)
|
43
43
|
|
44
|
-
# t =
|
44
|
+
# t = RailsPerformance::Utils.time
|
45
45
|
if !RailsPerformance.skip
|
46
46
|
if !CurrentRequest.current.ignore.include?(:performance) # grape is executed first, and than ignore regular future storage of "controller"-like request
|
47
47
|
if (data = CurrentRequest.current.data)
|
@@ -66,7 +66,7 @@ module RailsPerformance
|
|
66
66
|
end
|
67
67
|
end
|
68
68
|
end
|
69
|
-
# puts "==> store performance data: #{(
|
69
|
+
# puts "==> store performance data: #{(RailsPerformance::Utils.time - t).round(3)}ms"
|
70
70
|
|
71
71
|
[@status, @headers, @response]
|
72
72
|
end
|
@@ -30,11 +30,12 @@ module RailsPerformance
|
|
30
30
|
end
|
31
31
|
end
|
32
32
|
|
33
|
+
# TODO: simplify this method, and combine with nullify_data
|
33
34
|
def calculate_data
|
34
|
-
now =
|
35
|
+
now = RailsPerformance::Utils.time
|
35
36
|
now = now.change(sec: 0, usec: 0)
|
36
|
-
stop = Time.at(60 * (now.to_i / 60))
|
37
|
-
offset = RailsPerformance::Reports::BaseReport.time_in_app_time_zone(now).utc_offset
|
37
|
+
stop = now # Time.at(60 * (now.to_i / 60), in:)
|
38
|
+
offset = 0 # RailsPerformance::Reports::BaseReport.time_in_app_time_zone(now).utc_offset
|
38
39
|
current = stop - RailsPerformance.duration
|
39
40
|
|
40
41
|
@data = []
|
@@ -48,7 +49,7 @@ module RailsPerformance
|
|
48
49
|
while current <= stop
|
49
50
|
key = current.strftime(RailsPerformance::FORMAT)
|
50
51
|
views = all[key].presence || 0
|
51
|
-
@data << [(current.to_i + offset) * 1000, views.
|
52
|
+
@data << [(current.to_i + offset) * 1000, views.round(2)]
|
52
53
|
current += 1.minute
|
53
54
|
end
|
54
55
|
|
@@ -65,10 +66,10 @@ module RailsPerformance
|
|
65
66
|
def nil_data
|
66
67
|
@nil_data ||= begin
|
67
68
|
result = {}
|
68
|
-
now =
|
69
|
+
now = RailsPerformance::Utils.time
|
69
70
|
now = now.change(sec: 0, usec: 0)
|
70
|
-
stop = Time.at(60 * (now.to_i / 60))
|
71
|
-
offset = RailsPerformance::Reports::BaseReport.time_in_app_time_zone(now).utc_offset
|
71
|
+
stop = now # Time.at(60 * (now.to_i / 60))
|
72
|
+
offset = 0 # RailsPerformance::Reports::BaseReport.time_in_app_time_zone(now).utc_offset
|
72
73
|
current = stop - RailsPerformance.duration
|
73
74
|
|
74
75
|
while current <= stop
|
@@ -1,13 +1,6 @@
|
|
1
1
|
module RailsPerformance
|
2
2
|
module Reports
|
3
3
|
class ResourcesReport < BaseReport
|
4
|
-
def self.x
|
5
|
-
@datasource = RailsPerformance::DataSource.new(type: :resources)
|
6
|
-
db = @datasource.db
|
7
|
-
@data = RailsPerformance::Reports::ResourcesReport.new(db)
|
8
|
-
# RailsPerformance::Reports::ResourcesReport.x
|
9
|
-
end
|
10
|
-
|
11
4
|
def data
|
12
5
|
@data ||= db.data
|
13
6
|
.collect { |e| e.record_hash }
|
@@ -1,5 +1,13 @@
|
|
1
1
|
module RailsPerformance
|
2
2
|
class Utils
|
3
|
+
def self.time
|
4
|
+
Time.now.utc
|
5
|
+
end
|
6
|
+
|
7
|
+
def self.from_datetimei(datetimei)
|
8
|
+
Time.at(datetimei, in: "+00:00")
|
9
|
+
end
|
10
|
+
|
3
11
|
# date key in redis store
|
4
12
|
def self.cache_key(now = Date.today)
|
5
13
|
"date-#{now}"
|
@@ -7,7 +15,7 @@ module RailsPerformance
|
|
7
15
|
|
8
16
|
# write to current slot
|
9
17
|
# time - date -minute
|
10
|
-
def self.field_key(now =
|
18
|
+
def self.field_key(now = RailsPerformance::Utils.time)
|
11
19
|
now.strftime("%H:%M")
|
12
20
|
end
|
13
21
|
|