Showing
5 changed files
with
15 additions
and
17 deletions
@@ -10,24 +10,12 @@ class Message { | @@ -10,24 +10,12 @@ class Message { | ||
10 | } | 10 | } |
11 | } | 11 | } |
12 | 12 | ||
13 | -const opt = { | ||
14 | - decodeURIComponent: function(str) { | ||
15 | - let result = decodeURIComponent(str); | ||
16 | - | ||
17 | - if (result[0] === '"') { | ||
18 | - result = String(result); | ||
19 | - } | ||
20 | - | ||
21 | - return result; | ||
22 | - } | ||
23 | -}; | ||
24 | - | ||
25 | function parseMessage(line) { | 13 | function parseMessage(line) { |
26 | let measurement = line.split(',', 1)[0]; | 14 | let measurement = line.split(',', 1)[0]; |
27 | let body = line.substring(measurement.length + 1); | 15 | let body = line.substring(measurement.length + 1); |
28 | let tokens = body.split(' '); | 16 | let tokens = body.split(' '); |
29 | 17 | ||
30 | - let [tags, fields, time] = [qs.parse(tokens[0], ',', '=', opt), qs.parse(tokens[1], ',', '=', opt), tokens[2]]; | 18 | + let [tags, fields, time] = [qs.parse(tokens[0], ',', '='), qs.parse(tokens[1], ',', '='), tokens[2]]; |
31 | 19 | ||
32 | if (tags.path) { | 20 | if (tags.path) { |
33 | let [, p] = tags.path.split(']'); | 21 | let [, p] = tags.path.split(']'); |
@@ -37,6 +25,10 @@ function parseMessage(line) { | @@ -37,6 +25,10 @@ function parseMessage(line) { | ||
37 | tags.route = tags.path; | 25 | tags.route = tags.path; |
38 | } | 26 | } |
39 | 27 | ||
28 | + if (!tags.route) { | ||
29 | + tags.route = 'null'; | ||
30 | + } | ||
31 | + | ||
40 | return new Message(measurement, tags, fields, time); | 32 | return new Message(measurement, tags, fields, time); |
41 | } | 33 | } |
42 | 34 |
@@ -29,7 +29,7 @@ module.exports = (req, res, next) => { | @@ -29,7 +29,7 @@ module.exports = (req, res, next) => { | ||
29 | return res.send(); | 29 | return res.send(); |
30 | } | 30 | } |
31 | report.forEach(item => { | 31 | report.forEach(item => { |
32 | - if (item.pt.indexOf('openby:yohobuy')) { | 32 | + if (item.pt && item.pt.indexOf('openby:yohobuy')) { |
33 | item.pt = item.pt.substring(0, item.pt.indexOf('openby:yohobuy')); | 33 | item.pt = item.pt.substring(0, item.pt.indexOf('openby:yohobuy')); |
34 | } | 34 | } |
35 | if (item.tp === 'err') { | 35 | if (item.tp === 'err') { |
@@ -39,7 +39,7 @@ module.exports = (req, res, next) => { | @@ -39,7 +39,7 @@ module.exports = (req, res, next) => { | ||
39 | reqID: item.rid, | 39 | reqID: item.rid, |
40 | uid: item.u, | 40 | uid: item.u, |
41 | udid: item.ud, | 41 | udid: item.ud, |
42 | - route: item.pt | 42 | + route: item.pt || 'null' |
43 | } | 43 | } |
44 | }; | 44 | }; |
45 | 45 |
@@ -40,6 +40,8 @@ module.exports = (req, res, next) => { | @@ -40,6 +40,8 @@ module.exports = (req, res, next) => { | ||
40 | 40 | ||
41 | if (item.r) { | 41 | if (item.r) { |
42 | item.r = routeDecode(item.r) || 'null'; | 42 | item.r = routeDecode(item.r) || 'null'; |
43 | + } else { | ||
44 | + item.r = 'null'; | ||
43 | } | 45 | } |
44 | 46 | ||
45 | if (item.tp === 'err') { | 47 | if (item.tp === 'err') { |
@@ -12,7 +12,7 @@ function slowRouter(m) { | @@ -12,7 +12,7 @@ function slowRouter(m) { | ||
12 | api: _.get(m, 'tags.api', ''), | 12 | api: _.get(m, 'tags.api', ''), |
13 | route: _.get(m, 'tags.route', ''), | 13 | route: _.get(m, 'tags.route', ''), |
14 | duration: _.get(m, 'fields.duration', ''), | 14 | duration: _.get(m, 'fields.duration', ''), |
15 | - create_time: _.get(m, 'time') / 1000000 | 15 | + create_time: _.get(m, 'time') ? _.get(m, 'time') / 1000000 : 0 |
16 | }; | 16 | }; |
17 | } | 17 | } |
18 | 18 | ||
@@ -32,7 +32,7 @@ function errorRouter(m) { | @@ -32,7 +32,7 @@ function errorRouter(m) { | ||
32 | script: _.get(m, 'fields.script', ''), | 32 | script: _.get(m, 'fields.script', ''), |
33 | message: _.get(m, 'fields.message', ''), | 33 | message: _.get(m, 'fields.message', ''), |
34 | stack: _.get(m, 'fields.stack', ''), | 34 | stack: _.get(m, 'fields.stack', ''), |
35 | - create_time: _.get(m, 'time') / 1000000 | 35 | + create_time: _.get(m, 'time') ? _.get(m, 'time') / 1000000 : 0 |
36 | }; | 36 | }; |
37 | } | 37 | } |
38 | 38 |
@@ -9,6 +9,7 @@ const slowRouterSender = new MysqlSender(config.table.slow); | @@ -9,6 +9,7 @@ const slowRouterSender = new MysqlSender(config.table.slow); | ||
9 | 9 | ||
10 | const routeSender = new Sender(config.reportRoute); | 10 | const routeSender = new Sender(config.reportRoute); |
11 | const apiSender = new Sender(config.reportApi); | 11 | const apiSender = new Sender(config.reportApi); |
12 | +const _ = require('lodash'); | ||
12 | 13 | ||
13 | const server = { | 14 | const server = { |
14 | async handle(data) { | 15 | async handle(data) { |
@@ -51,6 +52,9 @@ const server = { | @@ -51,6 +52,9 @@ const server = { | ||
51 | } else if (m.measurement === 'error-report') { | 52 | } else if (m.measurement === 'error-report') { |
52 | errorSender.addMessage(msg2row.errorRouter(m)); | 53 | errorSender.addMessage(msg2row.errorRouter(m)); |
53 | } else if (m.measurement === 'process-info') { | 54 | } else if (m.measurement === 'process-info') { |
55 | + m.measurement = 'process1-info'; | ||
56 | + _.set(m, 'fields.memory', parseInt(_.get(m, 'fields.memory', '0'))); | ||
57 | + _.set(m, 'fields.cpu', parseInt(_.get(m, 'fields.cpu', '0'))); | ||
54 | routeSender.addMessage(m); | 58 | routeSender.addMessage(m); |
55 | } | 59 | } |
56 | } | 60 | } |
-
Please register or login to post a comment