Authored by htoooth

fix

... ... @@ -10,24 +10,12 @@ class Message {
}
}
const opt = {
decodeURIComponent: function(str) {
let result = decodeURIComponent(str);
if (result[0] === '"') {
result = String(result);
}
return result;
}
};
function parseMessage(line) {
let measurement = line.split(',', 1)[0];
let body = line.substring(measurement.length + 1);
let tokens = body.split(' ');
let [tags, fields, time] = [qs.parse(tokens[0], ',', '=', opt), qs.parse(tokens[1], ',', '=', opt), tokens[2]];
let [tags, fields, time] = [qs.parse(tokens[0], ',', '='), qs.parse(tokens[1], ',', '='), tokens[2]];
if (tags.path) {
let [, p] = tags.path.split(']');
... ... @@ -37,6 +25,10 @@ function parseMessage(line) {
tags.route = tags.path;
}
if (!tags.route) {
tags.route = 'null';
}
return new Message(measurement, tags, fields, time);
}
... ...
... ... @@ -29,7 +29,7 @@ module.exports = (req, res, next) => {
return res.send();
}
report.forEach(item => {
if (item.pt.indexOf('openby:yohobuy')) {
if (item.pt && item.pt.indexOf('openby:yohobuy')) {
item.pt = item.pt.substring(0, item.pt.indexOf('openby:yohobuy'));
}
if (item.tp === 'err') {
... ... @@ -39,7 +39,7 @@ module.exports = (req, res, next) => {
reqID: item.rid,
uid: item.u,
udid: item.ud,
route: item.pt
route: item.pt || 'null'
}
};
... ...
... ... @@ -40,6 +40,8 @@ module.exports = (req, res, next) => {
if (item.r) {
item.r = routeDecode(item.r) || 'null';
} else {
item.r = 'null';
}
if (item.tp === 'err') {
... ...
... ... @@ -12,7 +12,7 @@ function slowRouter(m) {
api: _.get(m, 'tags.api', ''),
route: _.get(m, 'tags.route', ''),
duration: _.get(m, 'fields.duration', ''),
create_time: _.get(m, 'time') / 1000000
create_time: _.get(m, 'time') ? _.get(m, 'time') / 1000000 : 0
};
}
... ... @@ -32,7 +32,7 @@ function errorRouter(m) {
script: _.get(m, 'fields.script', ''),
message: _.get(m, 'fields.message', ''),
stack: _.get(m, 'fields.stack', ''),
create_time: _.get(m, 'time') / 1000000
create_time: _.get(m, 'time') ? _.get(m, 'time') / 1000000 : 0
};
}
... ...
... ... @@ -9,6 +9,7 @@ const slowRouterSender = new MysqlSender(config.table.slow);
const routeSender = new Sender(config.reportRoute);
const apiSender = new Sender(config.reportApi);
const _ = require('lodash');
const server = {
async handle(data) {
... ... @@ -51,6 +52,9 @@ const server = {
} else if (m.measurement === 'error-report') {
errorSender.addMessage(msg2row.errorRouter(m));
} else if (m.measurement === 'process-info') {
m.measurement = 'process1-info';
_.set(m, 'fields.memory', parseInt(_.get(m, 'fields.memory', '0')));
_.set(m, 'fields.cpu', parseInt(_.get(m, 'fields.cpu', '0')));
routeSender.addMessage(m);
}
}
... ...