Authored by htoooth

fix

... ... @@ -65,7 +65,10 @@ module.exports = {
error: 'error_report'
},
slowRoute: {
min: 1000,
// min: 1000,
// max: 10 * 1000
min: 0,
max: 10 * 1000
}
};
... ...
const qs = require('querystring');
const crypto = global.yoho.crypto;
const logger = global.yoho.logger;
const routeDecode = require('../middleware/route-decode');
class Message {
constructor(measurement, tags, fields, time) {
... ... @@ -30,6 +29,14 @@ function parseMessage(line) {
let [tags, fields, time] = [qs.parse(tokens[0], ',', '=', opt), qs.parse(tokens[1], ',', '=', opt), tokens[2]];
if (tags.path) {
let [, p] = tags.path.split(']');
p = routeDecode(p) || 'null';
tags.path = p;
tags.route = tags.path;
}
return new Message(measurement, tags, fields, time);
}
... ...
... ... @@ -6,6 +6,7 @@ const _ = require('lodash');
const logger = global.yoho.logger;
const config = global.yoho.config;
const msg2row = require('./msg2row');
const routeDecode = require('./route-decode');
const durationType = {
dcl: 'domcontentload',
... ... @@ -37,6 +38,10 @@ module.exports = (req, res, next) => {
item.pt = item.pt.substring(0, item.pt.indexOf('openby:yohobuy'));
}
if (item.r) {
item.r = routeDecode(item.r) || 'null';
}
if (item.tp === 'err') {
let data = {
tags: {
... ... @@ -44,7 +49,7 @@ module.exports = (req, res, next) => {
reqID: item.rid,
uid: item.u,
udid: item.ud,
route: item.pt
route: item.r
},
time: new Date().getTime() * 1000000
};
... ... @@ -88,7 +93,7 @@ module.exports = (req, res, next) => {
let data = {
tags: {
app,
route: item.pt
route: item.r
},
fields: {
reqID: item.rid,
... ... @@ -113,14 +118,13 @@ module.exports = (req, res, next) => {
});
routeInfluxSender.addMessage({
measurement: 'route-info',
tags: {
app: app,
host: item.hostname,
route: item.pt
route: item.r
},
fields: {
duration: item.duration
duration: duration
}
});
... ...
const crypto = global.yoho.crypto;
const _ = require('lodash');
const decode = _.memoize(function(r) {
return crypto.decrypt(null, r);
});
module.exports = function(r) {
try {
let s = decode(r);
return s;
} catch (e) {
return r;
}
};
... ...
const lineparse = require('../lib/line-parse');
const Sender = require('influx-batch-sender');
const MysqlSender = require('../lib/mysql-sender');
const config = require('../common/config');
const msg2row = require('./msg2row');
const lineparse = require('../lib/line-parse');
const errorSender = new MysqlSender(config.table.error);
const slowRouterSender = new MysqlSender(config.table.slow);
const influxSender = new Sender(config.reportRoute);
const routeSender = new Sender(config.reportRoute);
const apiSender = new Sender(config.reportApi);
const server = {
async handle(data) {
... ... @@ -18,43 +18,40 @@ const server = {
if (m.measurement === 'web-server-duration') {
let duration = parseInt(m.fields.duration);
if (duration > config.slowRoute.min || duration < config.slowRoute.max) {
if (duration > config.slowRoute.min && duration < config.slowRoute.max) {
slowRouterSender.addMessage(msg2row.slowRouter(m));
}
if (m.tags.type.toLowerCase() === 'api') {
influxSender.addMessage({
measurement: 'api-info',
apiSender.addMessage({
tags: {
app: m.tags.app,
hostname: m.tags.hostname,
host: m.tags.hostname,
api: m.tags.api
},
fields: {
duration: m.duration,
duration: duration,
times: 1
}
});
}
if (m.tags.type.toLowerCase() === 'route') {
influxSender.addMessage({
measurement: 'route-info',
routeSender.addMessage({
tags: {
app: m.tags.app,
hostname: m.tags.hostname,
host: m.tags.hostname,
route: m.tags.route
},
fields: {
duration: m.duration
duration: duration
}
});
}
} else if (m.measurement === 'error-report') {
errorSender.addMessage(msg2row.errorRouter(m));
} else if (m.measurement === 'process-info') {
influxSender.addMessage(m);
routeSender.addMessage(m);
}
}
}
... ...