Authored by htoooth

fix

@@ -182,15 +182,15 @@ const profile_service = { @@ -182,15 +182,15 @@ const profile_service = {
182 182
183 return {code: 200, data: rows} 183 return {code: 200, data: rows}
184 }, 184 },
185 - async server_time(ctx, app) { 185 + async server_time(ctx, app, start, length) {
186 const slowRouterModel = new SlowRouteModel(ctx); 186 const slowRouterModel = new SlowRouteModel(ctx);
187 - const result = await slowRouterModel.getList(app); 187 + const result = await slowRouterModel.getList(app, start, length);
188 188
189 - return {cde: 200, data: result}; 189 + return result;
190 }, 190 },
191 - async error(ctx, app) { 191 + async error(ctx, app, start, length) {
192 const errorModel = new ErrorModel(ctx); 192 const errorModel = new ErrorModel(ctx);
193 - const result = await errorModel.getList(app); 193 + const result = await errorModel.getList(app, start, length);
194 194
195 return {cde: 200, data: result}; 195 return {cde: 200, data: result};
196 } 196 }
@@ -201,19 +201,25 @@ const profile_controller = { @@ -201,19 +201,25 @@ const profile_controller = {
201 await ctx.render('action/profile_server'); 201 await ctx.render('action/profile_server');
202 }, 202 },
203 async server_mean_report_json(ctx) { 203 async server_mean_report_json(ctx) {
204 - const app = ctx.query.app; 204 + const app = parseInt(ctx.query.app) || 0;
  205 + const start = parseInt(ctx.query.start) || 0;
  206 + const length = parseInt(ctx.query.length) || 10;
  207 + const draw = ctx.query.draw;
205 208
206 - const result = await profile_service.server_time(ctx, app);  
207 - ctx.body = result; 209 + const result = await profile_service.server_time(ctx, app, start, length);
  210 + ctx.body = Object.assign({}, result, {draw});
208 }, 211 },
209 async error_report_index(ctx) { 212 async error_report_index(ctx) {
210 await ctx.render('action/profile_error'); 213 await ctx.render('action/profile_error');
211 }, 214 },
212 async error_report_json(ctx) { 215 async error_report_json(ctx) {
213 - const app = ctx.query.app; 216 + const app = parseInt(ctx.query.app) || 0;
  217 + const start = parseInt(ctx.query.start) || 0;
  218 + const length = parseInt(ctx.query.length) || 10;
  219 + const draw = ctx.query.draw;
214 220
215 - const result = await profile_service.error(ctx, app);  
216 - ctx.body = result; 221 + const result = await profile_service.error(ctx, app, start, length);
  222 + ctx.body = Object.assign({}, result, {draw});
217 } 223 }
218 224
219 }; 225 };
1 const model = require('../../../lib/model'); 1 const model = require('../../../lib/model');
2 const mysqlPromise = require('../../../lib/mysql-apm'); 2 const mysqlPromise = require('../../../lib/mysql-apm');
  3 +const vars = require('./vars');
3 4
4 class errorModel extends model { 5 class errorModel extends model {
5 constructor(ctx) { 6 constructor(ctx) {
@@ -7,12 +8,17 @@ class errorModel extends model { @@ -7,12 +8,17 @@ class errorModel extends model {
7 this.mysql = new mysqlPromise(); 8 this.mysql = new mysqlPromise();
8 } 9 }
9 10
10 - getList(app, page, pageSize) { 11 + async getList(app, page, pageSize) {
11 pageSize = pageSize || 10; 12 pageSize = pageSize || 10;
12 - page = page || 1;  
13 - let pageStart = (page - 1) * pageSize;  
14 13
15 - return this.mysql.query('SELECT id, app, type, preq_id, req_id, uid, udid, code, line, `column`, script, message, stack from error_report where app = ? limit ?, ?', [app, pageStart, pageSize]); 14 + let recordsTotal = await this.mysql.query('SELECT COUNT(*) as count from error_report where app = ?', [app]).then(([r]) => r.count);
  15 + let data = await this.mysql.query('SELECT id, app, type, preq_id, req_id, uid, udid, code, line, `column`, script, message, stack from error_report where app = ? limit ?, ? order by create_time desc', [app, page, pageSize]).then(r => r.map(vars.handleItem));
  16 +
  17 + return {
  18 + recordsTotal,
  19 + recordsFiltered: recordsTotal,
  20 + data
  21 + }
16 } 22 }
17 } 23 }
18 24
1 const model = require('../../../lib/model'); 1 const model = require('../../../lib/model');
2 const mysqlPromise = require('../../../lib/mysql-apm'); 2 const mysqlPromise = require('../../../lib/mysql-apm');
  3 +const vars = require('./vars');
3 4
4 class slowRouteModel extends model { 5 class slowRouteModel extends model {
5 constructor(ctx) { 6 constructor(ctx) {
@@ -7,12 +8,19 @@ class slowRouteModel extends model { @@ -7,12 +8,19 @@ class slowRouteModel extends model {
7 this.mysql = new mysqlPromise(); 8 this.mysql = new mysqlPromise();
8 } 9 }
9 10
10 - getList(app, page, pageSize) { 11 + async getList(app, page, pageSize) {
11 pageSize = pageSize || 10; 12 pageSize = pageSize || 10;
12 - page = page || 1;  
13 - let pageStart = (page - 1) * pageSize;  
14 13
15 - return this.mysql.query('SELECT id, app, type, preq_id, req_id, uid, udid, api, route, duration from slow_duration where app = ? limit ?, ?', [app, pageStart, pageSize]); 14 + let recordsTotal = await this.mysql.query('SELECT COUNT(*) as count from slow_duration where app = ?', [app]).then(([r]) => r.count);
  15 + let data = await this.mysql.query('SELECT id, app, `type`, preq_id, req_id, uid, udid, api, route, duration from slow_duration where app = ? limit ?, ? order by create_time desc', [app, page, pageSize]).then(r => {
  16 + return r.map(vars.handleItem)
  17 + });
  18 +
  19 + return {
  20 + recordsTotal,
  21 + recordsFiltered: recordsTotal,
  22 + data
  23 + }
16 } 24 }
17 } 25 }
18 26
  1 +const APP_VALUE = {
  2 + 0: 'unknown',
  3 + 1: 'yohobuy',
  4 + 2: 'yohobuywap',
  5 + 3: 'blk',
  6 + 4: 'blkwap'
  7 +};
  8 +
  9 +const TYPE_VALUE = {
  10 + 0: 'unknown',
  11 + 1: 'api',
  12 + 2: 'route',
  13 + 3: 'firstscreen',
  14 + 4: 'domready',
  15 + 5: 'documentload'
  16 +};
  17 +
  18 +function handleItem(i) {
  19 + i.app = APP_VALUE[i.app];
  20 + i.type = TYPE_VALUE[i.type];
  21 + return i;
  22 +}
  23 +
  24 +module.exports = {
  25 + handleItem
  26 +};
@@ -69,21 +69,12 @@ @@ -69,21 +69,12 @@
69 69
70 70
71 <script> 71 <script>
72 - var selectedServer, selectedStarTime, selectedEndTime, selectedApp, lastTime; 72 + var selectedServer, selectedApp;
73 var data_end_point = '/profile/error.json'; 73 var data_end_point = '/profile/error.json';
74 var dataTable = null; 74 var dataTable = null;
75 75
76 function ajaxUrl() { 76 function ajaxUrl() {
77 let url = `${data_end_point}?app=${selectedApp}&server=${selectedServer}`; 77 let url = `${data_end_point}?app=${selectedApp}&server=${selectedServer}`;
78 -  
79 - if (selectedEndTime && selectedEndTime) {  
80 - url += `&start=${selectedStarTime}&end=${selectedEndTime}`;  
81 - }  
82 -  
83 - if (lastTime) {  
84 - url += `&lastTime=${lastTime}`  
85 - }  
86 -  
87 return url 78 return url
88 } 79 }
89 80
@@ -101,12 +92,12 @@ @@ -101,12 +92,12 @@
101 function initTable() { 92 function initTable() {
102 dataTable = $("#table-servers").DataTable({ 93 dataTable = $("#table-servers").DataTable({
103 pageLength: 20, 94 pageLength: 20,
  95 + serverSide: true,
104 retrieve: true, 96 retrieve: true,
105 - responsive: true,  
106 - searching: true, 97 + searching: false,
  98 + ajax: ajaxUrl(),
107 dataSrc: 'data', 99 dataSrc: 'data',
108 pageLength: 25, 100 pageLength: 25,
109 - deferLoading: 0,  
110 columns: [ 101 columns: [
111 {data: 'time'}, 102 {data: 'time'},
112 {data: 'app'}, 103 {data: 'app'},
@@ -148,19 +139,16 @@ @@ -148,19 +139,16 @@
148 } 139 }
149 ], 140 ],
150 order: [[0, "desc"]] 141 order: [[0, "desc"]]
  142 +
151 }); 143 });
152 } 144 }
153 145
154 function initSelect() { 146 function initSelect() {
155 - $('#selectedServer').change(function() {  
156 - selectedServer = $('#selectedServer').val();  
157 - });  
158 -  
159 $('#selectedApp').change(function() { 147 $('#selectedApp').change(function() {
160 selectedApp = $('#selectedApp').val(); 148 selectedApp = $('#selectedApp').val();
161 }); 149 });
162 150
163 - $('#search').on('click', function() { 151 + $('#search').on('click', () => {
164 _handleChanged(); 152 _handleChanged();
165 }) 153 })
166 } 154 }
@@ -7,9 +7,9 @@ @@ -7,9 +7,9 @@
7 <ul class="breadcrumb"> 7 <ul class="breadcrumb">
8 <li><a href=""><i class="glyphicon glyphicon-home"></i></a></li> 8 <li><a href=""><i class="glyphicon glyphicon-home"></i></a></li>
9 <li><a href="">性能监控</a></li> 9 <li><a href="">性能监控</a></li>
10 - <li>服务器调用时间统计</li> 10 + <li>慢路由统计统计</li>
11 </ul> 11 </ul>
12 - <h4>服务器调用时间统计</h4> 12 + <h4>慢路由统计</h4>
13 </div> 13 </div>
14 </div> 14 </div>
15 <!-- media --> 15 <!-- media -->
@@ -52,28 +52,18 @@ @@ -52,28 +52,18 @@
52 52
53 53
54 <script> 54 <script>
55 - var selectedServer, selectedStarTime, selectedEndTime, selectedApp, lastTime; 55 + var selectedServer, selectedApp;
56 var data_end_point = '/profile/server.json'; 56 var data_end_point = '/profile/server.json';
57 var dataTable = null; 57 var dataTable = null;
58 58
59 function ajaxUrl() { 59 function ajaxUrl() {
60 let url = `${data_end_point}?app=${selectedApp}&server=${selectedServer}`; 60 let url = `${data_end_point}?app=${selectedApp}&server=${selectedServer}`;
61 -  
62 - if (selectedEndTime && selectedEndTime) {  
63 - url += `&start=${selectedStarTime}&end=${selectedEndTime}`;  
64 - }  
65 -  
66 - if (lastTime) {  
67 - url += `&lastTime=${lastTime}`  
68 - }  
69 -  
70 return url 61 return url
71 } 62 }
72 63
73 $(function() { 64 $(function() {
74 init(); 65 init();
75 initTable(); 66 initTable();
76 -// initDatePicker();  
77 initSelect(); 67 initSelect();
78 }); 68 });
79 69
@@ -85,8 +75,10 @@ @@ -85,8 +75,10 @@
85 function initTable() { 75 function initTable() {
86 dataTable = $("#table-servers").DataTable({ 76 dataTable = $("#table-servers").DataTable({
87 pageLength: 20, 77 pageLength: 20,
  78 + serverSide: true,
88 retrieve: true, 79 retrieve: true,
89 - searching: true, 80 + searching: false,
  81 + ajax: ajaxUrl(),
90 dataSrc: 'data', 82 dataSrc: 'data',
91 pageLength: 25, 83 pageLength: 25,
92 columns: [ 84 columns: [
@@ -100,7 +92,12 @@ @@ -100,7 +92,12 @@
100 api: 0, 92 api: 0,
101 route: 0, 93 route: 0,
102 duration: 0, 94 duration: 0,
  95 + }],
  96 + columnDefs: [{
  97 + orderable: false,
  98 + targets: [0,1,2,3]
103 }] 99 }]
  100 +
104 }); 101 });
105 } 102 }
106 103