...
|
...
|
@@ -12,7 +12,7 @@ const endpoint = (server) => `http://${server.host}:${server.port}`; |
|
|
const r = new Router;
|
|
|
|
|
|
const TABLE = {
|
|
|
DURATION: 'web-client-duration',
|
|
|
CLIENT: 'web-client-duration',
|
|
|
REPORT: 'error-report',
|
|
|
SERVER: 'web-server-duration'
|
|
|
};
|
...
|
...
|
@@ -24,6 +24,11 @@ const APP_NAME = { |
|
|
h5: 'yohobuywap-node'
|
|
|
};
|
|
|
|
|
|
const APP_NAME2 = {
|
|
|
pc: 'www.yohobuy.com',
|
|
|
h5: 'm.yohobuy.com'
|
|
|
};
|
|
|
|
|
|
const TYPE = {
|
|
|
DOMContentLoaded: 0,
|
|
|
load: 0,
|
...
|
...
|
@@ -31,8 +36,8 @@ const TYPE = { |
|
|
};
|
|
|
|
|
|
const profile_sql = {
|
|
|
duration() {
|
|
|
return SqlBuilder.of(TABLE.DURATION);
|
|
|
client() {
|
|
|
return SqlBuilder.of(TABLE.CLIENT);
|
|
|
},
|
|
|
error() {
|
|
|
return SqlBuilder.of(TABLE.REPORT);
|
...
|
...
|
@@ -62,6 +67,12 @@ const APP = { |
|
|
h5: {field: 'app', op: '=', value: APP_NAME.h5}
|
|
|
};
|
|
|
|
|
|
const APP2 = {
|
|
|
default: {field: '', op: '', value: ''},
|
|
|
pc: {field: 'app', op: '=', value: APP_NAME2.pc},
|
|
|
h5: {field: 'app', op: '=', value: APP_NAME2.h5}
|
|
|
};
|
|
|
|
|
|
const SERVER = {
|
|
|
aws: endpoint(config.apm.aws),
|
|
|
qcloud: endpoint(config.apm.qcloud)
|
...
|
...
|
@@ -77,6 +88,14 @@ function handleZip(items) { |
|
|
});
|
|
|
}
|
|
|
|
|
|
function handleZip2(item) {
|
|
|
const col = _.get(item, 'columns', []);
|
|
|
const values = _.get(item, "values[0]", []);
|
|
|
const tags = _.get(item, "tags", []);
|
|
|
|
|
|
return Object.assign({}, _.zipObject(col, values), tags)
|
|
|
}
|
|
|
|
|
|
function handleRows(rows) {
|
|
|
let stats = rows.reduce((acc, cur) => {
|
|
|
_.updateWith(acc, [cur.route, cur.type, 'duration'], function(n) {
|
...
|
...
|
@@ -126,9 +145,21 @@ function handleRows(rows) { |
|
|
return result;
|
|
|
}
|
|
|
|
|
|
function handleApi(totalRows, apiRows) {
|
|
|
let totalObj = totalRows.map(handleZip2);
|
|
|
let apiObj = apiRows.map(handleZip2);
|
|
|
|
|
|
totalObj.forEach(i => {
|
|
|
i.detail = jp.query(apiObj, `$..[?(@.route=="${i.route}")]`);
|
|
|
i.length = i.detail.length;
|
|
|
});
|
|
|
|
|
|
return totalObj;
|
|
|
}
|
|
|
|
|
|
const profile_service = {
|
|
|
async mean(server, start, end, app, lastTime) {
|
|
|
const model = profile_sql.duration()
|
|
|
async client_time(server, start, end, app, lastTime) {
|
|
|
const model = profile_sql.client()
|
|
|
.select('*')
|
|
|
.where(APP[app]);
|
|
|
|
...
|
...
|
@@ -149,10 +180,12 @@ const profile_service = { |
|
|
|
|
|
return {code: 200, data: rows}
|
|
|
},
|
|
|
async time(server, start, end, app, lastTime) {
|
|
|
const model = profile_sql.duration()
|
|
|
.select('*')
|
|
|
.where(APP[app]);
|
|
|
async server_time(server, start, end, app, lastTime) {
|
|
|
const model = profile_sql.server()
|
|
|
.select('count("duration"), mean("duration")')
|
|
|
.where(APP2[app])
|
|
|
.where('type', '=', 'route')
|
|
|
.groupBy(['route']);
|
|
|
|
|
|
if (lastTime) {
|
|
|
model.where('time', '>=', SqlBuilder.raw(`now() - ${lastTime}`))
|
...
|
...
|
@@ -163,9 +196,28 @@ const profile_service = { |
|
|
.where('time', '<', end);
|
|
|
}
|
|
|
|
|
|
const rows = await exec(SERVER[server], model.toSql())
|
|
|
.then(result => _.get(result, 'results[0].series[0]', []))
|
|
|
.then(handleZip);
|
|
|
const total = await exec(SERVER[server], model.toSql())
|
|
|
.then(result => _.get(result, 'results[0].series', []));
|
|
|
|
|
|
const apiModel = profile_sql.server()
|
|
|
.select('count("duration"), mean("duration")')
|
|
|
.where(APP2[app])
|
|
|
.where('type', '=', 'api')
|
|
|
.groupBy(['route', 'api']);
|
|
|
|
|
|
if (lastTime) {
|
|
|
apiModel.where('time', '>=', SqlBuilder.raw(`now() - ${lastTime}`))
|
|
|
}
|
|
|
|
|
|
if (start && end) {
|
|
|
apiModel.where('time', '>=', start)
|
|
|
.where('time', '<', end);
|
|
|
}
|
|
|
|
|
|
const api = await exec(SERVER[server], apiModel.toSql())
|
|
|
.then(result => _.get(result, 'results[0].series', []));
|
|
|
|
|
|
const rows = handleApi(total, api);
|
|
|
|
|
|
return {cde: 200, data: rows};
|
|
|
},
|
...
|
...
|
@@ -192,30 +244,30 @@ const profile_service = { |
|
|
};
|
|
|
|
|
|
const profile_controller = {
|
|
|
async mean_report_index(ctx) {
|
|
|
await ctx.render('action/profile_mean');
|
|
|
async client_mean_report_index(ctx) {
|
|
|
await ctx.render('action/profile_client');
|
|
|
},
|
|
|
async mean_report_json(ctx) {
|
|
|
async client_mean_report_json(ctx) {
|
|
|
const start = ctx.query.start;
|
|
|
const end = ctx.query.end;
|
|
|
const app = ctx.query.app;
|
|
|
const server = ctx.query.server || 'aws';
|
|
|
const lastTime = ctx.query.lastTime;
|
|
|
|
|
|
const result = await profile_service.mean(server, start, end, app, lastTime);
|
|
|
const result = await profile_service.client_time(server, start, end, app, lastTime);
|
|
|
ctx.body = result;
|
|
|
},
|
|
|
async time_report_index(ctx) {
|
|
|
await ctx.render('action/profile_time');
|
|
|
async server_mean_report_index(ctx) {
|
|
|
await ctx.render('action/profile_server');
|
|
|
},
|
|
|
async time_report_json(ctx) {
|
|
|
async server_mean_report_json(ctx) {
|
|
|
const start = ctx.query.start;
|
|
|
const end = ctx.query.end;
|
|
|
const app = ctx.query.app;
|
|
|
const server = ctx.query.server || 'aws';
|
|
|
const lastTime = ctx.query.lastTime;
|
|
|
|
|
|
const result = await profile_service.time(server, start, end, app, lastTime);
|
|
|
const result = await profile_service.server_time(server, start, end, app, lastTime);
|
|
|
ctx.body = result;
|
|
|
},
|
|
|
async error_report_index(ctx) {
|
...
|
...
|
@@ -234,11 +286,11 @@ const profile_controller = { |
|
|
|
|
|
};
|
|
|
|
|
|
r.get('/mean', profile_controller.mean_report_index);
|
|
|
r.get('/mean.json', profile_controller.mean_report_json);
|
|
|
r.get('/client', profile_controller.client_mean_report_index);
|
|
|
r.get('/client.json', profile_controller.client_mean_report_json);
|
|
|
|
|
|
r.get('/time', profile_controller.time_report_index);
|
|
|
r.get('/time.json', profile_controller.time_report_json);
|
|
|
r.get('/server', profile_controller.server_mean_report_index);
|
|
|
r.get('/server.json', profile_controller.server_mean_report_json);
|
|
|
|
|
|
r.get('/error', profile_controller.error_report_index);
|
|
|
r.get('/error.json', profile_controller.error_report_json);
|
...
|
...
|
|