Authored by htoooth

fix

... ... @@ -4,6 +4,8 @@ const Router = require('koa-router');
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 r = new Router;
... ... @@ -23,7 +25,7 @@ const profile_sql = {
async function exec(sql) {
console.log('influx sql =>', sql);
return request.get('http://influxd.yoho.cn/query')
return request.get(`${ENDPOINT}/query`)
.query({
q: sql,
db: 'web-apm'
... ... @@ -64,10 +66,15 @@ const profile_service = {
return {code: 200, data: rows}
},
async error() {
const model = profile_sql.error().select('*');
async error(start, end, app) {
const model = profile_sql.error()
.select('*')
.where(APP[app])
.where('time', '>=', start)
.where('time', '<', end);
const rows = await exec(model.toSql());
return {errors: rows};
return {cde: 200, data: rows};
}
};
... ... @@ -85,13 +92,22 @@ const profile_controller = {
ctx.body = result;
},
async error_report_index(ctx) {
const result = await profile_service.error();
await ctx.render('action/profile_error', result);
await ctx.render('action/profile_error');
},
async error_report_json(ctx) {
const start = ctx.query.start;
const end = ctx.query.end;
const app = ctx.query.app;
const result = await profile_service.error(start, end, app);
ctx.body = result;
}
};
r.get('/time', profile_controller.time_report_index);
r.get('/time.json', profile_controller.time_report_json);
r.get('/error', profile_controller.error_report_index);
r.get('/error.json', profile_controller.error_report_json);
module.exports = r;
\ No newline at end of file
... ...
... ... @@ -18,14 +18,21 @@
<div class="contentpanel page-servers">
<div class="panel panel-primary-head">
<!--<div class="panel-heading">-->
<!--<div class="pull-right">-->
<!--<a id="new-page" href="/servers/new" class="btn btn-success btn-rounded"><i class="glyphicon glyphicon-plus"></i> 新增服务器</a>-->
<!--</div>-->
<!--<h4 class="panel-title">服务器设置</h4>-->
<!--<p>配置服务器连接方式、可以通过标签区分</p>-->
<!--</div>-->
<div class="panel-heading" style="overflow: hidden">
<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">
<i class="glyphicon glyphicon-calendar fa fa-calendar"></i>&nbsp;
<span></span> <b class="caret"></b>
</div>
<div class="pull-left">
<select id="selectedApp" class="selectpicker show-menu-arrow form-control" style="margin-left: 10px;">
<option value="default">全部</option>
<option value="pc">PC</option>
<option value="h5">H5</option>
</select>
</div>
</div>
<!-- panel-heading -->
<table id="table-servers" class="table table-striped table-bordered responsive">
... ... @@ -48,23 +55,6 @@
</thead>
<tbody>
{{#each errors}}
<tr>
<td>{{time}}</td>
<td>{{app}}</td>
<td>{{type}}</td>
<td>{{preqID}}</td>
<td>{{reqID}}</td>
<td>{{uid}}</td>
<td>{{udid}}</td>
<td>{{code}}</td>
<td>{{message}}</td>
<td>{{script}}</td>
<td>{{line}}</td>
<td>{{column}}</td>
<td>{{stack}}</td>
</tr>
{{/each}}
</tbody>
</table>
</div>
... ... @@ -73,42 +63,129 @@
<script>
$(document).off().on('ready pjax:end', function() {
console.log('page: servers');
// $("#table-servers").on('draw.dt', function() {
// eventBind();
// });
function eventBind() {
$('.server-del').off().on('click', function(){
var id = $(this).parent().data('id');
$.post('/servers/del', {id: id}, function(ret){
if(ret.code == 200){
var i = layer.alert('操作成功', function(){
layer.close(i);
location.href = location.href;
});
}
});
});
$('.server-edit').off().on('click', function(){
var id = $(this).parent().data('id');
location.href = '/servers/edit?id=' + id;
});
var 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}`
}
function skipOnce(fn) {
var count = 0;
return function() {
if (count++ >= 1) fn.apply(null, arguments);
return null
}
}
eventBind();
$(function() {
init();
initTable();
initDatePicker();
initSelect();
});
function init() {
selectedStarTime = moment();
selectedEndTime = moment().add(1, 'days');
selectedApp = 'default';
}
$("#table-servers").DataTable({
function initTable() {
dataTable = $("#table-servers").DataTable({
pageLength: 20,
retrieve: true,
responsive: true,
searching: false
searching: true,
ajax: ajaxUrl(),
dataSrc: 'data',
pageLength: 25,
deferLoading: 0,
columns: [
{ data: 'time' },
{ data: 'app' },
{ data: 'type' },
{ data: 'preqID' },
{ data: 'reqID' },
{ data: 'uid' },
{ data: 'udid' },
{ data: 'code' },
{ data: 'message' },
{ data: 'script' },
{ data: 'line' },
{ data: 'column' },
{ data: 'stack' }
],
columnDefs: [
{
render: function ( data, type, row ) {
return moment(data).format('YYYY/MM/DD HH:MM:ss');
},
targets: 0
}
],
order: [[ 0, "desc" ]]
});
}
});
function initDatePicker() {
var start = selectedStarTime;
var end = selectedEndTime;
$('#reportrange span').html('今天');
function cb(start, end, label) {
if (label !== '自定义日期') {
$('#reportrange span').html(label);
} else {
$('#reportrange span').html(start.format('YYYY-MM-DD') + ' 至 ' + end.format('YYYY-MM-DD'))
}
selectedStarTime = start;
selectedEndTime = end;
handleChanged();
}
$('#reportrange').daterangepicker({
startDate: start,
endDate: end,
ranges: {
'今天': [moment(), moment().add(1, 'days')],
'昨天': [moment().subtract(1, 'days'), moment()],
'最近 7 天': [moment().subtract(6, 'days'), moment().add(1, 'days')],
'最近 30 天': [moment().subtract(29, 'days'), moment().add(1, 'days')],
'本月': [moment().startOf('month'), moment().endOf('month')],
'上个月': [moment().subtract(1, 'month').startOf('month'), moment().subtract(1, 'month').endOf('month')]
},
locale: {
format: "YYYY-MM-DD",
applyLabel: '确定',
cancelLabel: '取消',
weekLabel: 'W',
customRangeLabel: '自定义日期',
daysOfWeek: '一_二_三_四_五_六_日'.split('_'),
monthNames: '1月_2月_3月_4月_5月_6月_7月_8月_9月_10月_11月_12月'.split('_'),
firstDay: 1
},
}, cb);
cb(start, end);
}
function initSelect() {
$('#selectedApp').change(function() {
selectedApp = $('#selectedApp').val();
handleChanged();
});
}
function _handleChanged() {
dataTable && dataTable.ajax.url(ajaxUrl()).load();
}
</script>
\ No newline at end of file
... ...
... ... @@ -9,8 +9,8 @@ const defaults = {
buildDir: path.normalize(__dirname + '/../packages/'),
dbDir: path.normalize(__dirname + '/../db'),
influxdb: {
host: 'influxdblog.web.yohoops.org',
port: 4444
host: 'influxd.yoho.cn',
port: 80
},
redis: {
connect: {
... ... @@ -64,6 +64,10 @@ const specific = {
development: {},
test: {},
production: {
influxdb: {
host: 'influxdblog.web.yohoops.org',
port: 4444
},
redis: {
connect: {
host: 'web.redis.yohoops.org',
... ...