rails_performance 0.0.1.3 → 0.0.1.4

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: 57398ce57cc6e6707959d81156ffb0b48f8b32f55e25657f1f0a714c89c1bc2c
4
- data.tar.gz: 1250f710f15e028d1c8ed187cd6e1e9849ad8e0d440cb6eb6bd5eb67ec09d491
3
+ metadata.gz: 457bfaa0d79609d19c413eba29dd8d859bdd44914f1b89575479670e93f7cd4c
4
+ data.tar.gz: 5ba7326c5428c8619c7f8d00762e2e4c93f94706fa62c05d6568c4888b22400f
5
5
  SHA512:
6
- metadata.gz: a1d3edeb648e2cd152e479c03c4d52e6c697963ba8c677f42bceb6fa373896cd353f24e0f0bababed286cd323b71db265a98fccaa9ea5f425eb46027b7873e04
7
- data.tar.gz: 74936554df31a3672f68985ff68f640f33faa4a798a2f7a53bcb2169eebcea6bf62a65ab3863771936013a166313a8f04cd5d564678481786cdaf1807bee1580
6
+ metadata.gz: b0092789df6c6f941c5625bdeab09e3428a18454eb146d5bb2e861939b117288be7f3fae207bc73acf6b2e357cd40d15fbff507a3270ef3c7eb96739c84152bf
7
+ data.tar.gz: e40e5f82fbd08e70fe0d279824b3ecb75dbc0e303e27a9dd53be38b7b9519aef7c08565e76d2a4640c32f586a3aa6d6d673ec9b26d5c8342cdf0b371bc56923d
@@ -3,11 +3,14 @@ class RailsPerformanceController < ActionController::Base
3
3
  def index
4
4
  @datasource = RailsPerformance::DataSource.new(RailsPerformance::QueryBuilder.compose_from(params))
5
5
 
6
- @throughput_report = RailsPerformance::ThroughputReport.new(@datasource.db)
7
- @throughput_report_data = @throughput_report.data
6
+ @throughput_report = RailsPerformance::Reports::ThroughputReport.new(@datasource.db)
7
+ @throughput_report_data = @throughput_report.data
8
8
 
9
- @global_report = RailsPerformance::RequestsReport.new(@datasource.db, group: :controller_action_format, sort: :db_runtime_slowest)
10
- @global_report_data = @global_report.data
9
+ @response_time_report = RailsPerformance::Reports::ResponseTimeReport.new(@datasource.db)
10
+ @response_time_report_data = @response_time_report.data
11
+
12
+ @global_report = RailsPerformance::Reports::RequestsReport.new(@datasource.db, group: :controller_action_format, sort: :db_runtime_slowest)
13
+ @global_report_data = @global_report.data
11
14
  end
12
15
 
13
16
  # def RailsPerformanceController.x
@@ -20,6 +20,6 @@ module RailsPerformanceHelper
20
20
  {}
21
21
  end
22
22
 
23
- link_to title, rails_performance_path(options)
23
+ link_to title, rails_performance_path(options), target: '_blank'
24
24
  end
25
25
  end
@@ -5,7 +5,7 @@
5
5
  <%= javascript_include_tag 'https://code.highcharts.com/modules/accessibility.js' %>
6
6
 
7
7
  <script>
8
- function showRequestsChart(div, data) {
8
+ function showTIRChart(div, data) {
9
9
  Highcharts.chart(div, {
10
10
  time: {
11
11
  timezone: 'Europe/Kiev'
@@ -65,4 +65,74 @@
65
65
  }]
66
66
  });
67
67
  };
68
+
69
+ function showRTChart(div, data) {
70
+ Highcharts.chart(div, {
71
+ time: {
72
+ timezone: 'Europe/Kiev'
73
+ },
74
+ chart: {
75
+ type: 'area',
76
+ zoomType: 'x',
77
+ backgroundColor: '#323a46'
78
+ },
79
+ title: {
80
+ text: ''
81
+ },
82
+ tooltip: {
83
+ formatter: function() {
84
+ if (this.y == 0) {
85
+ return null;
86
+ }
87
+
88
+ return this.y + ' ms';
89
+ }
90
+ },
91
+ xAxis: {
92
+ type: 'datetime',
93
+ labels: {
94
+ style: {
95
+ color: "#a6b0cf"
96
+ }
97
+ }
98
+ },
99
+ yAxis: {
100
+ min: 0,
101
+ title: {
102
+ text: 'Time',
103
+ style: {
104
+ color: "#f6f6f6"
105
+ }
106
+ },
107
+ labels: {
108
+ style: {
109
+ color: "#a6b0cf"
110
+ }
111
+ }
112
+ },
113
+ legend: {
114
+ enabled: false
115
+ },
116
+ exporting: {
117
+ buttons: {
118
+ contextButton: {
119
+ theme: {
120
+ fill: "#a6b0cf"
121
+ }
122
+ }
123
+ }
124
+ },
125
+ plotOptions: {
126
+ area: {
127
+ color: '#ff5b5b',
128
+ borderColor: '#ff5b5b',
129
+ }
130
+ },
131
+ series: [{
132
+ type: 'area',
133
+ name: 'Response Time',
134
+ data: data
135
+ }]
136
+ });
137
+ };
68
138
  </script>
@@ -12,7 +12,17 @@
12
12
 
13
13
  <div class="card">
14
14
  <h1>Throughput Report<h1>
15
- <div id="chart"></div>
15
+ <div id="throughput_report_chart"></div>
16
+ <p class="hint">All requests (site visitors, search engines, bots, etc)</p>
17
+ </div>
18
+
19
+ <br/>
20
+ <br/>
21
+ <br/>
22
+
23
+ <div class="card">
24
+ <h1>Average Response Time Report<h1>
25
+ <div id="response_time_report_chart"></div>
16
26
  <p class="hint">All requests (site visitors, search engines, bots, etc)</p>
17
27
  </div>
18
28
 
@@ -68,7 +78,10 @@
68
78
  <%= render '/rails_performance/js' %>
69
79
 
70
80
  <script>
71
- var data = <%= raw @throughput_report_data.to_json %>;
72
- showRequestsChart('chart', data);
81
+ var data1 = <%= raw @throughput_report_data.to_json %>;
82
+ showTIRChart('throughput_report_chart', data1);
83
+
84
+ var data2 = <%= raw @response_time_report_data.to_json %>;
85
+ showRTChart('response_time_report_chart', data2);
73
86
  </script>
74
87
 
@@ -5,9 +5,10 @@ require_relative "rails_performance/middleware.rb"
5
5
  require_relative "rails_performance/data_source.rb"
6
6
  require_relative "rails_performance/record.rb"
7
7
  require_relative "rails_performance/utils.rb"
8
- require_relative "rails_performance/base_report.rb"
9
- require_relative "rails_performance/requests_report.rb"
10
- require_relative "rails_performance/throughput_report.rb"
8
+ require_relative "rails_performance/reports/base_report.rb"
9
+ require_relative "rails_performance/reports/requests_report.rb"
10
+ require_relative "rails_performance/reports/response_time_report.rb"
11
+ require_relative "rails_performance/reports/throughput_report.rb"
11
12
 
12
13
  require "rails_performance/engine"
13
14
 
@@ -0,0 +1,24 @@
1
+ module RailsPerformance
2
+ module Reports
3
+ class BaseReport
4
+ attr_reader :db, :group, :sort
5
+
6
+ def initialize(db, group: nil, sort: nil)
7
+ @db = db
8
+ @group = group
9
+ @sort = sort
10
+
11
+ set_defaults
12
+ end
13
+
14
+ def collect
15
+ db.group_by(group).values.inject([]) do |res, (k,v)|
16
+ res << yield(k, v)
17
+ res
18
+ end
19
+ end
20
+
21
+ def set_defaults; end
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,28 @@
1
+ module RailsPerformance
2
+ module Reports
3
+ class RequestsReport < BaseReport
4
+ def set_defaults
5
+ @sort ||= :count
6
+ end
7
+
8
+ def data
9
+ collect do |k, v|
10
+ durations = v.collect{|e| e["duration"]}.compact
11
+ view_runtimes = v.collect{|e| e["view_runtime"]}.compact
12
+ db_runtimes = v.collect{|e| e["db_runtime"]}.compact
13
+
14
+ {
15
+ group: k,
16
+ count: v.size,
17
+ duration_average: durations.sum.to_f / durations.size,
18
+ view_runtime_average: view_runtimes.sum.to_f / view_runtimes.size,
19
+ db_runtime_average: db_runtimes.sum.to_f / db_runtimes.size,
20
+ duration_slowest: durations.max,
21
+ view_runtime_slowest: view_runtimes.max,
22
+ db_runtime_slowest: db_runtimes.max,
23
+ }
24
+ end.sort{|a, b| b[sort] <=> a[sort]}
25
+ end
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,37 @@
1
+ module RailsPerformance
2
+ module Reports
3
+ class ResponseTimeReport < BaseReport
4
+ def set_defaults
5
+ @group ||= :datetime
6
+ end
7
+
8
+ def data
9
+ all = {}
10
+ stop = Time.at(60 * (Time.now.to_i / 60))
11
+ current = stop - RailsPerformance.duration
12
+ @data = []
13
+ offset = Time.current.utc_offset
14
+
15
+ # puts "current: #{current}"
16
+ # puts "stop: #{stop}"
17
+
18
+ # read current values
19
+ db.group_by(group).values.each do |(k, v)|
20
+ durations = v.collect{|e| e["duration"]}.compact
21
+ next if durations.empty?
22
+ all[k] = durations.sum.to_f / durations.count
23
+ end
24
+
25
+ # add blank columns
26
+ while current <= stop
27
+ views = all[current.strftime(MetricsCollector::FORMAT)] || 0
28
+ @data << [(current.to_i + offset) * 1000, views.round(2)]
29
+ current += 1.minute
30
+ end
31
+
32
+ # sort by time
33
+ @data.sort!
34
+ end
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,37 @@
1
+ module RailsPerformance
2
+ module Reports
3
+ class ThroughputReport < BaseReport
4
+
5
+ def set_defaults
6
+ @group ||= :datetime
7
+ end
8
+
9
+ def data
10
+ all = {}
11
+ stop = Time.at(60 * (Time.now.to_i / 60))
12
+ current = stop - RailsPerformance.duration
13
+ @data = []
14
+ offset = Time.current.utc_offset
15
+
16
+ # puts "current: #{current}"
17
+ # puts "stop: #{stop}"
18
+
19
+ # read current values
20
+ db.group_by(group).values.each do |(k, v)|
21
+ all[k] = v.count
22
+ end
23
+
24
+ # add blank columns
25
+ while current <= stop
26
+ views = all[current.strftime(MetricsCollector::FORMAT)] || 0
27
+ @data << [(current.to_i + offset) * 1000, views.to_i]
28
+ current += 1.minute
29
+ end
30
+
31
+ # sort by time
32
+ @data.sort!
33
+ end
34
+
35
+ end
36
+ end
37
+ end
@@ -43,13 +43,5 @@ module RailsPerformance
43
43
  end
44
44
  end
45
45
 
46
- # populate test data
47
- # run in rails c
48
- def Utils.populate_test_data(seed = 20, limit = 10000, days = 7)
49
- limit.times do
50
- t = rand(86400*days).seconds.ago # within last 7 days
51
- RP.redis.hincrby(cache_key(t.to_date), field_key(t), rand(seed))
52
- end
53
- end
54
46
  end
55
47
  end
@@ -1,3 +1,3 @@
1
1
  module RailsPerformance
2
- VERSION = '0.0.1.3'
2
+ VERSION = '0.0.1.4'
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rails_performance
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1.3
4
+ version: 0.0.1.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Igor Kasyanchuk
@@ -98,7 +98,6 @@ files:
98
98
  - app/views/rails_performance/index.html.erb
99
99
  - config/routes.rb
100
100
  - lib/rails_performance.rb
101
- - lib/rails_performance/base_report.rb
102
101
  - lib/rails_performance/collection.rb
103
102
  - lib/rails_performance/data_source.rb
104
103
  - lib/rails_performance/engine.rb
@@ -106,8 +105,10 @@ files:
106
105
  - lib/rails_performance/middleware.rb
107
106
  - lib/rails_performance/query_builder.rb
108
107
  - lib/rails_performance/record.rb
109
- - lib/rails_performance/requests_report.rb
110
- - lib/rails_performance/throughput_report.rb
108
+ - lib/rails_performance/reports/base_report.rb
109
+ - lib/rails_performance/reports/requests_report.rb
110
+ - lib/rails_performance/reports/response_time_report.rb
111
+ - lib/rails_performance/reports/throughput_report.rb
111
112
  - lib/rails_performance/utils.rb
112
113
  - lib/rails_performance/version.rb
113
114
  homepage: https://github.com/igorkasyanchuk/rails_performance
@@ -1,23 +0,0 @@
1
- module RailsPerformance
2
- class BaseReport
3
- attr_reader :db, :group, :sort
4
-
5
- def initialize(db, group: nil, sort: nil)
6
- @db = db
7
- @group = group
8
- @sort = sort
9
-
10
- set_defaults
11
- end
12
-
13
- def collect
14
- db.group_by(group).values.inject([]) do |res, (k,v)|
15
- res << yield(k, v)
16
- res
17
- end
18
- end
19
-
20
- def set_defaults
21
- end
22
- end
23
- end
@@ -1,26 +0,0 @@
1
- module RailsPerformance
2
- class RequestsReport < BaseReport
3
- def set_defaults
4
- @sort ||= :count
5
- end
6
-
7
- def data
8
- collect do |k, v|
9
- durations = v.collect{|e| e["duration"]}.compact
10
- view_runtimes = v.collect{|e| e["view_runtime"]}.compact
11
- db_runtimes = v.collect{|e| e["db_runtime"]}.compact
12
-
13
- {
14
- group: k,
15
- count: v.size,
16
- duration_average: durations.sum.to_f / durations.size,
17
- view_runtime_average: view_runtimes.sum.to_f / view_runtimes.size,
18
- db_runtime_average: db_runtimes.sum.to_f / db_runtimes.size,
19
- duration_slowest: durations.max,
20
- view_runtime_slowest: view_runtimes.max,
21
- db_runtime_slowest: db_runtimes.max,
22
- }
23
- end.sort{|a, b| b[sort] <=> a[sort]}
24
- end
25
- end
26
- end
@@ -1,35 +0,0 @@
1
- module RailsPerformance
2
- class ThroughputReport < BaseReport
3
-
4
- def set_defaults
5
- @group ||= :datetime
6
- end
7
-
8
- def data
9
- all = {}
10
- stop = Time.at(60 * (Time.now.to_i / 60))
11
- current = stop - RailsPerformance.duration
12
- @data = []
13
- offset = Time.current.utc_offset
14
-
15
- # puts "current: #{current}"
16
- # puts "stop: #{stop}"
17
-
18
- # read current values
19
- db.group_by(group).values.each do |(k, v)|
20
- all[k] = v.count
21
- end
22
-
23
- # add blank columns
24
- while current <= stop
25
- views = all[current.strftime(MetricsCollector::FORMAT)] || 0
26
- @data << [(current.to_i + offset) * 1000, views.to_i]
27
- current += 1.minute
28
- end
29
-
30
- # sort by time
31
- @data.sort!
32
- end
33
-
34
- end
35
- end