msg2row.js
1.89 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
const _ = require('lodash');
function slowRouter(m) {
let uid = `${_.get(m, 'fields.uid', '0') || '0'}`.replace(/"/g, '');
return {
app: _.get(m, 'tags.app', ''),
type: _.get(m, 'tags.type', ''),
hostname: _.get(m, 'tags.hostname', ''),
preqid: _.get(m, 'fields.preqid', '').replace(/"/g, ''),
reqid: _.get(m, 'fields.reqID', '').replace(/"/g, ''),
uid: _.parseInt(uid),
udid: _.get(m, 'fields.udid', '').replace(/"/g, ''),
api: _.get(m, 'tags.api', ''),
route: _.get(m, 'tags.route', ''),
duration: _.get(m, 'fields.duration', ''),
create_time: _.get(m, 'time') ? _.get(m, 'time') / 1000000 : 0
};
}
function errorRouter(m) {
let uid = `${_.get(m, 'fields.uid', '0') || '0'}`.replace(/"/g, '');
let line = `${_.get(m, 'fields.line', '0') || '0'}`.replace(/"/g, '');
let column = `${_.get(m, 'fields.column', '0') || '0'}`.replace(/"/g, '');
return {
app: _.get(m, 'tags.app', ''),
api: _.get(m, 'tags.api', ''),
type: _.get(m, 'tags.type', ''),
hostname: _.get(m, 'tags.hostname', ''),
preqid: _.get(m, 'fields.preqid', '').replace(/"/g, ''),
reqid: _.get(m, 'fields.reqID', '').replace(/"/g, ''),
uid: _.parseInt(uid),
udid: _.get(m, 'fields.udid', '').replace(/"/g, ''),
route: _.get(m, 'tags.path', ''),
url: _.get(m, 'tags.url', ''),
ip: _.get(m, 'tags.ip', ''),
code: _.parseInt(_.get(m, 'tags.code', '0')) || -1,
line: _.parseInt(line),
column: _.parseInt(column),
script: _.get(m, 'fields.script', ''),
message: _.get(m, 'fields.message', ''),
stack: _.get(m, 'fields.stack', ''),
useragent: _.get(m, 'fields.useragent', ''),
create_time: _.get(m, 'time') ? _.get(m, 'time') / 1000000 : 0
};
}
module.exports = {
slowRouter,
errorRouter
};