Authored by 周奇琪

Merge branch 'feature/report' into 'master'

fix

增加选择服务器

See merge request !6
... ... @@ -5,7 +5,8 @@ const SqlBuilder = require('../utils/sql-builder');
const request = require('superagent');
const _ = require('lodash');
const config = require('../../../config/config');
const ENDPOINT = `http://${config.influxdb.host}:${config.influxdb.port}`;
const endpoint = (server) => `http://${server.host}:${server.port}`;
const r = new Router;
... ... @@ -30,9 +31,9 @@ const profile_sql = {
}
};
async function exec(sql) {
console.log('influx sql =>', sql);
return request.get(`${ENDPOINT}/query`)
async function exec(server, sql) {
console.log('influx query from ', `[${server}] `, 'sql =>' ,sql);
return request.get(`${server}/query`)
.query({
q: sql,
db: DB_NAME
... ... @@ -60,8 +61,13 @@ const DURATION = {
3: {field: 'duration', op: '>', value: 200},
};
const SERVER = {
aws: endpoint(config.influxdb.aws),
qcloud: endpoint(config.influxdb.qcloud)
};
const profile_service = {
async time(start, end, app, duration) {
async time(server, start, end, app, duration) {
const model = profile_sql.duration()
.select('*')
.where(DURATION[duration])
... ... @@ -69,18 +75,18 @@ const profile_service = {
.where('time', '>=', start)
.where('time', '<', end);
const rows = await exec(model.toSql());
const rows = await exec(SERVER[server],model.toSql());
return {code: 200, data: rows}
},
async error(start, end, app) {
async error(server, start, end, app) {
const model = profile_sql.error()
.select('*')
.where(APP[app])
.where('time', '>=', start)
.where('time', '<', end);
const rows = await exec(model.toSql());
const rows = await exec(SERVER[server], model.toSql());
return {cde: 200, data: rows};
}
};
... ... @@ -94,8 +100,9 @@ const profile_controller = {
const end = ctx.query.end;
const app = ctx.query.app;
const duration = ctx.query.duration;
const server = ctx.query.server || 'aws';
const result = await profile_service.time(start, end, app, duration);
const result = await profile_service.time(server, start, end, app, duration);
ctx.body = result;
},
async error_report_index(ctx) {
... ... @@ -105,8 +112,9 @@ const profile_controller = {
const start = ctx.query.start;
const end = ctx.query.end;
const app = ctx.query.app;
const server = ctx.query.server || 'aws';
const result = await profile_service.error(start, end, app);
const result = await profile_service.error(server, start, end, app);
ctx.body = result;
}
... ...
... ... @@ -82,7 +82,7 @@ class SqlBuilder {
} else {
return value
}
}).filter(v => v.length).join(' AND ');
}).filter(v => v && v.length).join(' AND ');
let orWhere = this._orWhere.map(({field, op, value}) => `${field}${op}${value}`).filter(v => v.length).join(' OR ');
if (andWhere) {
... ...
... ... @@ -19,8 +19,16 @@
<div class="contentpanel page-servers">
<div class="panel panel-primary-head">
<div class="panel-heading" style="overflow: hidden">
<div class="pull-left">
<select id="selectedServer" class="selectpicker show-menu-arrow form-control" style="margin-left: 10px;">
<option value="aws" selected>aws</option>
<option value="qcloud">qcloud</option>
</select>
</div>
<div id="reportrange" class="pull-left"
style="display: inline-block; background: #fff; cursor: pointer; padding: 9px 10px; border: 1px solid #ccc; width: 250px; color: black">
style="display: inline-block; background: #fff; cursor: pointer; padding: 9px 10px; border: 1px solid #ccc; width: 250px; color: black; margin-left: 20px;">
<i class="glyphicon glyphicon-calendar fa fa-calendar"></i>&nbsp;
<span></span> <b class="caret"></b>
</div>
... ... @@ -41,7 +49,6 @@
<th>时间</th>
<th>应用</th>
<th>类型</th>
<th>父请求ID</th>
<th>请求ID</th>
<td>用户ID</td>
<td>访客ID</td>
... ... @@ -63,13 +70,13 @@
<script>
var selectedStarTime, selectedEndTime, selectedApp;
var selectedServer, selectedStarTime, selectedEndTime, selectedApp;
var data_end_point = '/profile/error.json';
var dataTable = null;
var handleChanged = skipOnce(_handleChanged);
function ajaxUrl() {
return `${data_end_point}?start=${selectedStarTime.format('YYYY-MM-DD')}&end=${selectedEndTime.format('YYYY-MM-DD')}&app=${selectedApp}`
return `${data_end_point}?start=${selectedStarTime.format('YYYY-MM-DD')}&end=${selectedEndTime.format('YYYY-MM-DD')}&app=${selectedApp}&server=${selectedServer}`
}
function skipOnce(fn) {
... ... @@ -89,6 +96,7 @@
});
function init() {
selectedServer = 'aws';
selectedStarTime = moment();
selectedEndTime = moment().add(1, 'days');
selectedApp = 'default';
... ... @@ -108,7 +116,6 @@
{ data: 'time' },
{ data: 'app' },
{ data: 'type' },
{ data: 'preqID' },
{ data: 'reqID' },
{ data: 'uid' },
{ data: 'udid' },
... ... @@ -178,6 +185,11 @@
}
function initSelect() {
$('#selectedServer').change(function() {
selectedApp = $('#selectedServer').val();
handleChanged();
});
$('#selectedApp').change(function() {
selectedApp = $('#selectedApp').val();
handleChanged();
... ...
... ... @@ -19,8 +19,16 @@
<div class="contentpanel page-servers">
<div class="panel panel-primary-head">
<div class="panel-heading" style="overflow: hidden">
<div class="pull-left">
<select id="selectedServer" class="selectpicker show-menu-arrow form-control" style="margin-left: 10px;">
<option value="aws" selected>aws</option>
<option value="qcloud">qcloud</option>
</select>
</div>
<div id="reportrange" class="pull-left"
style="display: inline-block; background: #fff; cursor: pointer; padding: 9px 10px; border: 1px solid #ccc; width: 250px; color: black">
style="display: inline-block; background: #fff; cursor: pointer; padding: 9px 10px; border: 1px solid #ccc; width: 250px; color: black; margin-left: 20px;">
<i class="glyphicon glyphicon-calendar fa fa-calendar"></i>&nbsp;
<span></span> <b class="caret"></b>
</div>
... ... @@ -53,7 +61,6 @@
<td>接口名称</td>
<td>请求路由</td>
<td>耗时</td>
<th>父请求ID</th>
<th>请求ID</th>
<td>用户ID</td>
<td>访客ID</td></tr>
... ... @@ -68,13 +75,13 @@
<script>
var selectedStarTime, selectedEndTime, selectedApp, selectedDuration;
var selectedServer, selectedStarTime, selectedEndTime, selectedApp, selectedDuration;
var data_end_point = '/profile/time.json';
var dataTable = null;
var handleChanged = skipOnce(_handleChanged);
function ajaxUrl() {
return `${data_end_point}?start=${selectedStarTime.format('YYYY-MM-DD')}&end=${selectedEndTime.format('YYYY-MM-DD')}&app=${selectedApp}&duration=${selectedDuration}`
return `${data_end_point}?start=${selectedStarTime.format('YYYY-MM-DD')}&end=${selectedEndTime.format('YYYY-MM-DD')}&app=${selectedApp}&duration=${selectedDuration}&server=${selectedServer}`
}
function skipOnce(fn) {
... ... @@ -95,6 +102,7 @@
});
function init() {
selectedServer = 'aws';
selectedStarTime = moment();
selectedEndTime = moment().add(1, 'days');
selectedApp = 'default';
... ... @@ -118,7 +126,6 @@
{data: "api"},
{data: "route"},
{data: "duration"},
{data: "preqID"},
{data: "reqID"},
{data: "uid"},
{data: "udid"}
... ... @@ -182,6 +189,11 @@
}
function initSelect() {
$('#selectedServer').change(function() {
selectedServer = $('#selectedServer').val();
handleChanged();
});
$('#selectedApp').change(function() {
selectedApp = $('#selectedApp').val();
handleChanged();
... ...
... ... @@ -5,16 +5,23 @@ const path = require('path');
const env = process.env.NODE_ENV || 'development';
const defaults = {
port: 9000,
buildDir: path.normalize(__dirname + '/../packages/'),
dbDir: path.normalize(__dirname + '/../db'),
influxdb: {
host: 'influxd.yoho.cn',
port: 80
},
redis: {
connect: {
host: '127.0.0.1',
port: 9000,
buildDir: path.normalize(__dirname + '/../packages/'),
dbDir: path.normalize(__dirname + '/../db'),
influxdb: {
aws: {
host: 'influxd.yoho.cn',
port: 80
},
qcloud: {
host: 'influxd.yoho.cn',
port: 80
}
},
redis: {
connect: {
host: '127.0.0.1',
port: '6379',
retry_strategy: options => {
if (options.error && options.error.code === 'ECONNREFUSED') {
... ... @@ -29,65 +36,71 @@ const defaults = {
}
return Math.min(options.attempt * 100, 1000);
}
}
},
mysql: {
host: '192.168.102.219',
user: 'yh_test',
password: 'yh_test',
port: '3306',
database: 'yoho_seo'
},
domains: {
// test3
singleApi: 'http://api-test3.yohops.com:9999/',
api: 'http://api-test3.yohops.com:9999/',
service: 'http://service-test3.yohops.com:9999/',
serviceNotify: 'http://service-test3.yohops.com:9999/',
global: 'http://global-test-soa.yohops.com:9999/',
platformApi: 'http://192.168.102.48:8088/',
search: 'http://192.168.102.216:8080/yohosearch/',
}
},
mysql: {
host: '192.168.102.219',
user: 'yh_test',
password: 'yh_test',
port: '3306',
database: 'yoho_seo'
},
domains: {
// test3
singleApi: 'http://api-test3.yohops.com:9999/',
api: 'http://api-test3.yohops.com:9999/',
service: 'http://service-test3.yohops.com:9999/',
serviceNotify: 'http://service-test3.yohops.com:9999/',
global: 'http://global-test-soa.yohops.com:9999/',
platformApi: 'http://192.168.102.48:8088/',
search: 'http://192.168.102.216:8080/yohosearch/',
imSocket: 'ws://socket.yohobuy.com:10240',
imCs: 'http://im.yohobuy.com/api',
unionApi: 'http://172.16.6.90:8080/',
imSocket: 'ws://socket.yohobuy.com:10240',
imCs: 'http://im.yohobuy.com/api',
unionApi: 'http://172.16.6.90:8080/',
},
},
baiduToken: '0lSAO4ZxEKsYopMG',
// redis key prefix
singleBrandKeyPre: 'golobal:yoho:single_brand:', // key: 品牌id, val: 名牌名
singleSortKeyPre: 'golobal:yoho:single_sort:' // key: 品类id, val: 品类名
// redis key prefix
singleBrandKeyPre: 'golobal:yoho:single_brand:', // key: 品牌id, val: 名牌名
singleSortKeyPre: 'golobal:yoho:single_sort:' // key: 品类id, val: 品类名
};
const specific = {
development: {},
test: {},
production: {
development: {},
test: {},
production: {
influxdb: {
host: 'influxdblog.web.yohoops.org',
port: 4444
aws: {
host: '172.31.26.70',
port: 8086
},
qcloud: {
host: '10.66.0.139',
port: 8086
}
},
redis: {
connect: {
host: 'web.redis.yohoops.org',
port: '6379',
retry_strategy: options => {
if (options.error && options.error.code === 'ECONNREFUSED') {
console.log('redis连接不成功');
}
if (options.total_retry_time > 1000 * 60 * 60 * 6) {
console.log('redis连接超时');
return;
}
if (options.attempt > 10) {
return 1000 * 60 * 60 * 0.5;
}
return Math.min(options.attempt * 100, 1000);
if (options.error && options.error.code === 'ECONNREFUSED') {
console.log('redis连接不成功');
}
if (options.total_retry_time > 1000 * 60 * 60 * 6) {
console.log('redis连接超时');
return;
}
if (options.attempt > 10) {
return 1000 * 60 * 60 * 0.5;
}
return Math.min(options.attempt * 100, 1000);
}
}
},
mysql: {
mysql: {
host: '172.31.200.242',
user: 'yoho_seo_user',
password: 'eRUWnPm6nqWT',
... ... @@ -95,15 +108,15 @@ const specific = {
database: 'yoho_seo',
},
domains: {
singleApi: 'http://single.yoho.cn/',
api: 'http://api.yoho.cn/',
service: 'http://service.yoho.cn/',
serviceNotify: 'http://service.yoho.cn/',
global: 'http://api-global.yohobuy.com/',
platformApi: 'http://172.16.6.210:8088/',
search: 'http://search.yohoops.org/yohosearch/'
singleApi: 'http://single.yoho.cn/',
api: 'http://api.yoho.cn/',
service: 'http://service.yoho.cn/',
serviceNotify: 'http://service.yoho.cn/',
global: 'http://api-global.yohobuy.com/',
platformApi: 'http://172.16.6.210:8088/',
search: 'http://search.yohoops.org/yohosearch/'
}
},
},
};
module.exports = Object.assign(defaults, specific[env]);
\ No newline at end of file
... ...