Authored by htoooth

fix

... ... @@ -182,15 +182,15 @@ const profile_service = {
return {code: 200, data: rows}
},
async server_time(ctx, app) {
async server_time(ctx, app, start, length) {
const slowRouterModel = new SlowRouteModel(ctx);
const result = await slowRouterModel.getList(app);
const result = await slowRouterModel.getList(app, start, length);
return {cde: 200, data: result};
return result;
},
async error(ctx, app) {
async error(ctx, app, start, length) {
const errorModel = new ErrorModel(ctx);
const result = await errorModel.getList(app);
const result = await errorModel.getList(app, start, length);
return {cde: 200, data: result};
}
... ... @@ -201,19 +201,25 @@ const profile_controller = {
await ctx.render('action/profile_server');
},
async server_mean_report_json(ctx) {
const app = ctx.query.app;
const app = parseInt(ctx.query.app) || 0;
const start = parseInt(ctx.query.start) || 0;
const length = parseInt(ctx.query.length) || 10;
const draw = ctx.query.draw;
const result = await profile_service.server_time(ctx, app);
ctx.body = result;
const result = await profile_service.server_time(ctx, app, start, length);
ctx.body = Object.assign({}, result, {draw});
},
async error_report_index(ctx) {
await ctx.render('action/profile_error');
},
async error_report_json(ctx) {
const app = ctx.query.app;
const app = parseInt(ctx.query.app) || 0;
const start = parseInt(ctx.query.start) || 0;
const length = parseInt(ctx.query.length) || 10;
const draw = ctx.query.draw;
const result = await profile_service.error(ctx, app);
ctx.body = result;
const result = await profile_service.error(ctx, app, start, length);
ctx.body = Object.assign({}, result, {draw});
}
};
... ...
const model = require('../../../lib/model');
const mysqlPromise = require('../../../lib/mysql-apm');
const vars = require('./vars');
class errorModel extends model {
constructor(ctx) {
... ... @@ -7,12 +8,17 @@ class errorModel extends model {
this.mysql = new mysqlPromise();
}
getList(app, page, pageSize) {
async getList(app, page, pageSize) {
pageSize = pageSize || 10;
page = page || 1;
let pageStart = (page - 1) * pageSize;
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]);
let recordsTotal = await this.mysql.query('SELECT COUNT(*) as count from error_report where app = ?', [app]).then(([r]) => r.count);
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));
return {
recordsTotal,
recordsFiltered: recordsTotal,
data
}
}
}
... ...
const model = require('../../../lib/model');
const mysqlPromise = require('../../../lib/mysql-apm');
const vars = require('./vars');
class slowRouteModel extends model {
constructor(ctx) {
... ... @@ -7,12 +8,19 @@ class slowRouteModel extends model {
this.mysql = new mysqlPromise();
}
getList(app, page, pageSize) {
async getList(app, page, pageSize) {
pageSize = pageSize || 10;
page = page || 1;
let pageStart = (page - 1) * pageSize;
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]);
let recordsTotal = await this.mysql.query('SELECT COUNT(*) as count from slow_duration where app = ?', [app]).then(([r]) => r.count);
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 => {
return r.map(vars.handleItem)
});
return {
recordsTotal,
recordsFiltered: recordsTotal,
data
}
}
}
... ...
const APP_VALUE = {
0: 'unknown',
1: 'yohobuy',
2: 'yohobuywap',
3: 'blk',
4: 'blkwap'
};
const TYPE_VALUE = {
0: 'unknown',
1: 'api',
2: 'route',
3: 'firstscreen',
4: 'domready',
5: 'documentload'
};
function handleItem(i) {
i.app = APP_VALUE[i.app];
i.type = TYPE_VALUE[i.type];
return i;
}
module.exports = {
handleItem
};
\ No newline at end of file
... ...
... ... @@ -69,21 +69,12 @@
<script>
var selectedServer, selectedStarTime, selectedEndTime, selectedApp, lastTime;
var selectedServer, selectedApp;
var data_end_point = '/profile/error.json';
var dataTable = null;
function ajaxUrl() {
let url = `${data_end_point}?app=${selectedApp}&server=${selectedServer}`;
if (selectedEndTime && selectedEndTime) {
url += `&start=${selectedStarTime}&end=${selectedEndTime}`;
}
if (lastTime) {
url += `&lastTime=${lastTime}`
}
return url
}
... ... @@ -101,12 +92,12 @@
function initTable() {
dataTable = $("#table-servers").DataTable({
pageLength: 20,
serverSide: true,
retrieve: true,
responsive: true,
searching: true,
searching: false,
ajax: ajaxUrl(),
dataSrc: 'data',
pageLength: 25,
deferLoading: 0,
columns: [
{data: 'time'},
{data: 'app'},
... ... @@ -148,19 +139,16 @@
}
],
order: [[0, "desc"]]
});
}
function initSelect() {
$('#selectedServer').change(function() {
selectedServer = $('#selectedServer').val();
});
$('#selectedApp').change(function() {
selectedApp = $('#selectedApp').val();
});
$('#search').on('click', function() {
$('#search').on('click', () => {
_handleChanged();
})
}
... ...
... ... @@ -7,9 +7,9 @@
<ul class="breadcrumb">
<li><a href=""><i class="glyphicon glyphicon-home"></i></a></li>
<li><a href="">性能监控</a></li>
<li>服务器调用时间统计</li>
<li>慢路由统计统计</li>
</ul>
<h4>服务器调用时间统计</h4>
<h4>慢路由统计</h4>
</div>
</div>
<!-- media -->
... ... @@ -52,28 +52,18 @@
<script>
var selectedServer, selectedStarTime, selectedEndTime, selectedApp, lastTime;
var selectedServer, selectedApp;
var data_end_point = '/profile/server.json';
var dataTable = null;
function ajaxUrl() {
let url = `${data_end_point}?app=${selectedApp}&server=${selectedServer}`;
if (selectedEndTime && selectedEndTime) {
url += `&start=${selectedStarTime}&end=${selectedEndTime}`;
}
if (lastTime) {
url += `&lastTime=${lastTime}`
}
return url
}
$(function() {
init();
initTable();
// initDatePicker();
initSelect();
});
... ... @@ -85,8 +75,10 @@
function initTable() {
dataTable = $("#table-servers").DataTable({
pageLength: 20,
serverSide: true,
retrieve: true,
searching: true,
searching: false,
ajax: ajaxUrl(),
dataSrc: 'data',
pageLength: 25,
columns: [
... ... @@ -100,7 +92,12 @@
api: 0,
route: 0,
duration: 0,
}],
columnDefs: [{
orderable: false,
targets: [0,1,2,3]
}]
});
}
... ...