rails_performance 1.4.0.alpha5 → 1.4.1.alpha1

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,349 +1,125 @@
1
- Highcharts.setOptions({
2
- time: {
3
- timezone: window.APP_TIME_ZONE
4
- }
5
- });
6
-
7
- function showTIRChart(div, data, addon, name) {
8
- Highcharts.chart(div, {
1
+ function showChart(element_id, type, title, options) {
2
+ const chart = new ApexCharts(
3
+ document.getElementById(element_id),
4
+ {
5
+ ...options,
9
6
  chart: {
10
- type: 'area',
11
- zoomType: 'x',
7
+ type: type,
8
+ height: 300,
9
+ zoom: {
10
+ type: 'x',
11
+ },
12
12
  },
13
- title: {
14
- text: ''
13
+ colors: ['#ff5b5b'],
14
+ stroke: {
15
+ width: 1,
15
16
  },
16
- tooltip: {
17
- borderWidth: 0,
18
- backgroundColor: 'yellow',
19
- pointFormat: '{point.y}',
20
- //headerFormat: '',
21
- shadow: false,
22
- style: {
23
- fontSize: '16px',
24
- color: '#000',
25
- },
26
- formatter: function() {
27
- if (this.y == 0) {
28
- return false;
29
- }
30
- return this.y + addon;
31
- }
32
- },
33
- xAxis: {
34
- crosshair: true,
35
- type: 'datetime',
36
- labels: {
37
- style: {
38
- color: "#a6b0cf"
39
- }
40
- }
41
- },
42
- yAxis: {
43
- min: 0,
44
- title: {
45
- text: 'RPM',
46
- style: {
47
- color: "#f6f6f6"
48
- }
49
- },
50
- labels: {
51
- style: {
52
- color: "#a6b0cf"
53
- }
54
- }
17
+ dataLabels: {
18
+ enabled: false
55
19
  },
56
20
  legend: {
57
- enabled: false
58
- },
59
- exporting: {
60
- buttons: {
61
- contextButton: {
62
- theme: {
63
- fill: "#eee"
64
- }
21
+ show: false
22
+ },
23
+ xaxis: {
24
+ crosshairs: {
25
+ show: true
26
+ },
27
+ type: 'datetime',
28
+ labels: {
29
+ datetimeUTC: false,
30
+ style: {
31
+ colors: ["#a6b0cf"]
65
32
  }
66
33
  }
67
34
  },
68
- plotOptions: {
69
- area: {
70
- color: '#ff5b5b',
71
- }
72
- },
73
- series: [{
74
- type: 'area',
75
- name: name,
76
- data: data,
77
- fillOpacity: 0.3,
78
- lineWidth: 1,
79
- states: {
80
- hover: {
81
- lineWidth: 1
82
- }
83
- }
84
- }]
85
- });
86
- };
87
-
88
- function showRTChart(div, data) {
89
- Highcharts.chart(div, {
90
- chart: {
91
- type: 'area',
92
- zoomType: 'x',
93
- },
94
- title: {
95
- text: ''
96
- },
97
-
98
- tooltip: {
99
- borderWidth: 0,
100
- backgroundColor: 'yellow',
101
- pointFormat: '{point.y}',
102
- //headerFormat: '',
103
- shadow: false,
35
+ yaxis: {
36
+ min: 0,
37
+ title: {
38
+ text: title,
104
39
  style: {
105
- fontSize: '16px',
106
- color: '#000',
107
- },
108
- formatter: function() {
109
- if (this.y == 0) {
110
- return false;
111
- }
112
- return this.y + ' ms';
40
+ color: "#f6f6f6"
113
41
  }
114
- },
115
- xAxis: {
116
- crosshair: false,
117
- type: 'datetime',
118
- labels: {
119
- style: {
120
- color: "#a6b0cf"
121
- }
122
- }
123
- },
124
- yAxis: {
125
- min: 0,
126
- title: {
127
- text: 'Time',
128
- style: {
129
- color: "#f6f6f6"
130
- }
131
- },
132
- labels: {
133
- style: {
134
- color: "#a6b0cf"
135
- }
136
- }
137
- },
138
- legend: {
139
- enabled: false
140
- },
141
- exporting: {
142
- buttons: {
143
- contextButton: {
144
- theme: {
145
- fill: "#eee"
146
- }
42
+ },
43
+ labels: {
44
+ style: {
45
+ colors: ["#a6b0cf"]
147
46
  }
148
47
  }
149
- },
150
- plotOptions: {
151
- area: {
152
- color: '#ff5b5b',
153
- }
154
- },
155
- series: [{
156
- type: 'area',
157
- name: 'Response Time',
158
- data: data,
159
- fillOpacity: 0.3,
160
- lineWidth: 1,
161
- states: {
162
- hover: {
163
- lineWidth: 1
164
- }
165
- }
166
- }]
167
- });
168
- };
48
+ }
49
+ }
50
+ );
51
+ chart.render();
52
+ }
169
53
 
170
- function showPercentageChart(div, data, addon, name) {
171
- Highcharts.chart(div, {
172
- chart: {
173
- type: 'line',
174
- zoomType: 'x',
175
- },
54
+ function tooltipOptions(formatter) {
55
+ return {
56
+ style: {
57
+ fontSize: '16px'
58
+ },
59
+ marker: {
60
+ show: false,
61
+ },
62
+ x: {
63
+ show: false,
64
+ format: 'dd/MM/yy HH:mm'
65
+ },
66
+ y: {
67
+ formatter: formatter,
176
68
  title: {
177
- text: ''
178
- },
179
- tooltip: {
180
- borderWidth: 0,
181
- backgroundColor: 'yellow',
182
- pointFormat: '{point.y}',
183
- //headerFormat: '',
184
- shadow: false,
185
- style: {
186
- fontSize: '16px',
187
- color: '#000',
188
- },
189
- formatter: function() {
190
- if (this.y == 0) {
191
- return false;
192
- }
193
- return this.y + ' %';
194
- }
195
- },
196
- xAxis: {
197
- crosshair: true,
198
- type: 'datetime',
199
- labels: {
200
- style: {
201
- color: "#a6b0cf"
202
- }
203
- }
204
- },
205
- yAxis: {
206
- min: 0,
207
- title: {
208
- text: '%',
209
- style: {
210
- color: "#f6f6f6"
211
- }
212
- },
213
- labels: {
214
- style: {
215
- color: "#a6b0cf"
216
- }
217
- }
218
- },
219
- legend: {
220
- enabled: false
221
- },
222
- exporting: {
223
- buttons: {
224
- contextButton: {
225
- theme: {
226
- fill: "#eee"
227
- }
228
- }
229
- }
230
- },
231
- plotOptions: {
232
- area: {
233
- color: '#ff5b5b',
234
- }
235
- },
236
- series: [{
237
- type: 'line',
238
- name: name,
239
- data: data,
240
- fillOpacity: 0.3,
241
- lineWidth: 1,
242
- states: {
243
- hover: {
244
- lineWidth: 2
245
- }
246
- }
247
- }]
69
+ formatter: () => '',
70
+ }
71
+ }
72
+ };
73
+ }
74
+
75
+ function showTIRChart(element_id, data, addon, name) {
76
+ console.dir(data);
77
+ showChart(element_id, 'area', 'RPM', {
78
+ tooltip: tooltipOptions(value => (value ? value + addon : undefined)),
79
+ series: [{
80
+ name: name,
81
+ data: data
82
+ }]
248
83
  });
249
- };
84
+ }
250
85
 
86
+ function showRTChart(element_id, data) {
87
+ showChart(element_id, 'area', 'Time', {
88
+ tooltip: tooltipOptions(value => (value ? value + ' ms' : undefined)),
89
+ series: [{
90
+ name: 'Response Time',
91
+ data: data,
92
+ }],
93
+ });
94
+ }
251
95
 
252
- function showUsageChart(div, data, addon, name) {
253
- Highcharts.chart(div, {
254
- chart: {
255
- type: 'line',
256
- zoomType: 'x',
257
- },
258
- title: {
259
- text: ''
260
- },
261
- tooltip: {
262
- borderWidth: 0,
263
- backgroundColor: 'yellow',
264
- pointFormat: '{point.y}',
265
- //headerFormat: '',
266
- shadow: false,
267
- style: {
268
- fontSize: '16px',
269
- color: '#000',
270
- },
271
- formatter: function() {
272
- if (this.y == 0) {
273
- return false;
274
- }
275
- return bytes(this.y, true);
276
- }
277
- },
278
- xAxis: {
279
- crosshair: true,
280
- type: 'datetime',
281
- labels: {
282
- style: {
283
- color: "#a6b0cf"
284
- }
285
- }
286
- },
287
- yAxis: {
288
- min: 0,
289
- title: {
290
- text: '',
291
- style: {
292
- color: "#f6f6f6"
293
- }
294
- },
295
- labels: {
296
- style: {
297
- color: "#a6b0cf"
298
- }
299
- }
300
- },
301
- legend: {
302
- enabled: false
303
- },
304
- exporting: {
305
- buttons: {
306
- contextButton: {
307
- theme: {
308
- fill: "#eee"
309
- }
310
- }
311
- }
312
- },
313
- plotOptions: {
314
- area: {
315
- color: '#ff5b5b',
316
- }
317
- },
318
- series: [{
319
- type: 'line',
320
- name: name,
321
- data: data,
322
- fillOpacity: 0.3,
323
- lineWidth: 1,
324
- states: {
325
- hover: {
326
- lineWidth: 2
327
- }
328
- }
329
- }]
96
+ function showPercentageChart(element_id, data, name) {
97
+ showChart(element_id, 'line', '%', {
98
+ tooltip: tooltipOptions(value => (value ? value + ' %' : undefined)),
99
+ series: [{
100
+ name: name,
101
+ data: data,
102
+ }]
330
103
  });
331
- };
104
+ }
105
+
106
+ function showUsageChart(element_id, data, name, pow) {
107
+ const units = ['bytes', 'KB', 'MB', 'GB', 'TB', 'PB'][pow];
108
+ const bytes = Math.pow(1024, pow);
332
109
 
333
- function bytes(bytes, label) {
334
- if (bytes == 0) return '';
335
- var s = ['bytes', 'KB', 'MB', 'GB', 'TB', 'PB'];
336
- var e = Math.floor(Math.log(bytes)/Math.log(1024));
337
- var value = ((bytes/Math.pow(1024, Math.floor(e))).toFixed(2));
338
- e = (e<0) ? (-e) : e;
339
- if (label) value += ' ' + s[e];
340
- return value;
110
+ showChart(element_id, 'line', name, {
111
+ tooltip: tooltipOptions(value => (value ? `${value} ${units}` : undefined)),
112
+ series: [{
113
+ name: name,
114
+ data: data.map(([timestamp, value]) => [timestamp, typeof value === 'number' ? (value / bytes).toFixed(2) : null]),
115
+ }]
116
+ });
341
117
  }
342
118
 
343
- const recent = document.getElementById("recent")
344
- const autoupdate = document.getElementById("autoupdate")
119
+ const recent = document.getElementById("recent");
120
+ const autoupdate = document.getElementById("autoupdate");
345
121
 
346
- if(autoupdate) {
122
+ if (autoupdate) {
347
123
  // set autoupdate checked from localStorage is missing
348
124
  if (localStorage.getItem("autoupdate") === null) {
349
125
  localStorage.setItem("autoupdate", "true");
@@ -354,12 +130,12 @@ if(autoupdate) {
354
130
  });
355
131
  }
356
132
 
357
- if(recent) {
358
- const tbody = recent.querySelector("tbody")
133
+ if (recent) {
134
+ const tbody = recent.querySelector("tbody");
359
135
 
360
136
  setInterval(() => {
361
- tr = tbody.children[0];
362
- from_timei = tr.getAttribute("from_timei") || ''
137
+ const tr = tbody.children[0];
138
+ const from_timei = tr.getAttribute("from_timei") || '';
363
139
 
364
140
  if (!autoupdate.checked) {
365
141
  return;
@@ -373,6 +149,6 @@ if(recent) {
373
149
  .then(res => res.text())
374
150
  .then(html => {
375
151
  tbody.innerHTML = html + tbody.innerHTML;
376
- })
152
+ });
377
153
  }, 3000);
378
154
  }
@@ -6,9 +6,6 @@
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>
12
9
  <%= render '/rails_performance/stylesheets/stylesheets' %>
13
10
  <link rel="shortcut icon" href="/favicon.ico">
14
11
  </head>
@@ -38,13 +38,13 @@
38
38
  <script>
39
39
  <% @resources_report.data.keys.each do |server_key| %>
40
40
  var data1 = <%= raw @resources_report.cpu[server_key].to_json %>;
41
- showPercentageChart('cpu_report_<%= server_key.parameterize %>', data1, ' %', '%');
41
+ showPercentageChart('cpu_report_<%= server_key.parameterize %>', data1, 'CPU');
42
42
 
43
43
  var data2 = <%= raw @resources_report.memory[server_key].to_json %>;
44
- showUsageChart('memory_report_<%= server_key.parameterize %>', data2, ' Mb', 'Mb');
44
+ showUsageChart('memory_report_<%= server_key.parameterize %>', data2, 'Usage', 2);
45
45
 
46
46
  var data3 = <%= raw @resources_report.disk[server_key].to_json %>;
47
- showUsageChart('disk_report_<%= server_key.parameterize %>', data3, ' Gb', 'Gb');
47
+ showUsageChart('disk_report_<%= server_key.parameterize %>', data3, 'Available', 3);
48
48
  <% end %>
49
49
  </script>
50
50
  <% end %>
@@ -140,3 +140,7 @@ body.has-sticky-footer {
140
140
  background-color: #f5f5f5;
141
141
  padding: 1rem 0;
142
142
  }
143
+
144
+ .apexcharts-tooltip {
145
+ background: yellow !important;
146
+ }
@@ -69,7 +69,7 @@ module RailsPerformance
69
69
  when :custom
70
70
  "custom|*#{compile_custom_query}*|END|#{RailsPerformance::SCHEMA}"
71
71
  else
72
- raise "wrong type for datasource query builder"
72
+ raise "wrong type: \"#{type}\" for datasource query builder"
73
73
  end
74
74
  end
75
75
 
@@ -3,6 +3,8 @@ module RailsPerformance
3
3
  class RakeExt
4
4
  def self.init
5
5
  ::Rake::Task.class_eval do
6
+ next if method_defined?(:invoke_with_rails_performance)
7
+
6
8
  def invoke_with_rails_performance(*args)
7
9
  now = RailsPerformance::Utils.time
8
10
  status = "success"
@@ -1,4 +1,4 @@
1
1
  module RailsPerformance
2
- VERSION = "1.4.0.alpha5"
2
+ VERSION = "1.4.1.alpha1"
3
3
  SCHEMA = "1.0.2"
4
4
  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.4.0.alpha5
4
+ version: 1.4.1.alpha1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Igor Kasyanchuk
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2024-11-22 00:00:00.000000000 Z
11
+ date: 2024-11-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: railties
@@ -320,6 +320,7 @@ files:
320
320
  - app/helpers/rails_performance/rails_performance_helper.rb
321
321
  - app/views/rails_performance/_panel.html.erb
322
322
  - app/views/rails_performance/javascripts/_javascripts.html.erb
323
+ - app/views/rails_performance/javascripts/apexcharts.min.js
323
324
  - app/views/rails_performance/javascripts/app.js
324
325
  - app/views/rails_performance/javascripts/jquery-3.4.1.min.js
325
326
  - app/views/rails_performance/javascripts/navbar.js