Showing
5 changed files
with
49 additions
and
22 deletions
@@ -65,7 +65,10 @@ module.exports = { | @@ -65,7 +65,10 @@ module.exports = { | ||
65 | error: 'error_report' | 65 | error: 'error_report' |
66 | }, | 66 | }, |
67 | slowRoute: { | 67 | slowRoute: { |
68 | - min: 1000, | 68 | + // min: 1000, |
69 | + // max: 10 * 1000 | ||
70 | + | ||
71 | + min: 0, | ||
69 | max: 10 * 1000 | 72 | max: 10 * 1000 |
70 | } | 73 | } |
71 | }; | 74 | }; |
1 | const qs = require('querystring'); | 1 | const qs = require('querystring'); |
2 | -const crypto = global.yoho.crypto; | ||
3 | -const logger = global.yoho.logger; | 2 | +const routeDecode = require('../middleware/route-decode'); |
4 | 3 | ||
5 | class Message { | 4 | class Message { |
6 | constructor(measurement, tags, fields, time) { | 5 | constructor(measurement, tags, fields, time) { |
@@ -30,6 +29,14 @@ function parseMessage(line) { | @@ -30,6 +29,14 @@ function parseMessage(line) { | ||
30 | 29 | ||
31 | let [tags, fields, time] = [qs.parse(tokens[0], ',', '=', opt), qs.parse(tokens[1], ',', '=', opt), tokens[2]]; | 30 | let [tags, fields, time] = [qs.parse(tokens[0], ',', '=', opt), qs.parse(tokens[1], ',', '=', opt), tokens[2]]; |
32 | 31 | ||
32 | + if (tags.path) { | ||
33 | + let [, p] = tags.path.split(']'); | ||
34 | + | ||
35 | + p = routeDecode(p) || 'null'; | ||
36 | + tags.path = p; | ||
37 | + tags.route = tags.path; | ||
38 | + } | ||
39 | + | ||
33 | return new Message(measurement, tags, fields, time); | 40 | return new Message(measurement, tags, fields, time); |
34 | } | 41 | } |
35 | 42 |
@@ -6,6 +6,7 @@ const _ = require('lodash'); | @@ -6,6 +6,7 @@ const _ = require('lodash'); | ||
6 | const logger = global.yoho.logger; | 6 | const logger = global.yoho.logger; |
7 | const config = global.yoho.config; | 7 | const config = global.yoho.config; |
8 | const msg2row = require('./msg2row'); | 8 | const msg2row = require('./msg2row'); |
9 | +const routeDecode = require('./route-decode'); | ||
9 | 10 | ||
10 | const durationType = { | 11 | const durationType = { |
11 | dcl: 'domcontentload', | 12 | dcl: 'domcontentload', |
@@ -37,6 +38,10 @@ module.exports = (req, res, next) => { | @@ -37,6 +38,10 @@ module.exports = (req, res, next) => { | ||
37 | item.pt = item.pt.substring(0, item.pt.indexOf('openby:yohobuy')); | 38 | item.pt = item.pt.substring(0, item.pt.indexOf('openby:yohobuy')); |
38 | } | 39 | } |
39 | 40 | ||
41 | + if (item.r) { | ||
42 | + item.r = routeDecode(item.r) || 'null'; | ||
43 | + } | ||
44 | + | ||
40 | if (item.tp === 'err') { | 45 | if (item.tp === 'err') { |
41 | let data = { | 46 | let data = { |
42 | tags: { | 47 | tags: { |
@@ -44,7 +49,7 @@ module.exports = (req, res, next) => { | @@ -44,7 +49,7 @@ module.exports = (req, res, next) => { | ||
44 | reqID: item.rid, | 49 | reqID: item.rid, |
45 | uid: item.u, | 50 | uid: item.u, |
46 | udid: item.ud, | 51 | udid: item.ud, |
47 | - route: item.pt | 52 | + route: item.r |
48 | }, | 53 | }, |
49 | time: new Date().getTime() * 1000000 | 54 | time: new Date().getTime() * 1000000 |
50 | }; | 55 | }; |
@@ -88,7 +93,7 @@ module.exports = (req, res, next) => { | @@ -88,7 +93,7 @@ module.exports = (req, res, next) => { | ||
88 | let data = { | 93 | let data = { |
89 | tags: { | 94 | tags: { |
90 | app, | 95 | app, |
91 | - route: item.pt | 96 | + route: item.r |
92 | }, | 97 | }, |
93 | fields: { | 98 | fields: { |
94 | reqID: item.rid, | 99 | reqID: item.rid, |
@@ -113,14 +118,13 @@ module.exports = (req, res, next) => { | @@ -113,14 +118,13 @@ module.exports = (req, res, next) => { | ||
113 | }); | 118 | }); |
114 | 119 | ||
115 | routeInfluxSender.addMessage({ | 120 | routeInfluxSender.addMessage({ |
116 | - measurement: 'route-info', | ||
117 | tags: { | 121 | tags: { |
118 | app: app, | 122 | app: app, |
119 | host: item.hostname, | 123 | host: item.hostname, |
120 | - route: item.pt | 124 | + route: item.r |
121 | }, | 125 | }, |
122 | fields: { | 126 | fields: { |
123 | - duration: item.duration | 127 | + duration: duration |
124 | } | 128 | } |
125 | }); | 129 | }); |
126 | 130 |
middleware/route-decode.js
0 → 100644
1 | -const lineparse = require('../lib/line-parse'); | ||
2 | - | ||
3 | const Sender = require('influx-batch-sender'); | 1 | const Sender = require('influx-batch-sender'); |
4 | const MysqlSender = require('../lib/mysql-sender'); | 2 | const MysqlSender = require('../lib/mysql-sender'); |
5 | const config = require('../common/config'); | 3 | const config = require('../common/config'); |
6 | const msg2row = require('./msg2row'); | 4 | const msg2row = require('./msg2row'); |
5 | +const lineparse = require('../lib/line-parse'); | ||
7 | 6 | ||
8 | const errorSender = new MysqlSender(config.table.error); | 7 | const errorSender = new MysqlSender(config.table.error); |
9 | const slowRouterSender = new MysqlSender(config.table.slow); | 8 | const slowRouterSender = new MysqlSender(config.table.slow); |
10 | 9 | ||
11 | -const influxSender = new Sender(config.reportRoute); | 10 | +const routeSender = new Sender(config.reportRoute); |
11 | +const apiSender = new Sender(config.reportApi); | ||
12 | 12 | ||
13 | const server = { | 13 | const server = { |
14 | async handle(data) { | 14 | async handle(data) { |
@@ -18,43 +18,40 @@ const server = { | @@ -18,43 +18,40 @@ const server = { | ||
18 | if (m.measurement === 'web-server-duration') { | 18 | if (m.measurement === 'web-server-duration') { |
19 | let duration = parseInt(m.fields.duration); | 19 | let duration = parseInt(m.fields.duration); |
20 | 20 | ||
21 | - if (duration > config.slowRoute.min || duration < config.slowRoute.max) { | 21 | + if (duration > config.slowRoute.min && duration < config.slowRoute.max) { |
22 | slowRouterSender.addMessage(msg2row.slowRouter(m)); | 22 | slowRouterSender.addMessage(msg2row.slowRouter(m)); |
23 | } | 23 | } |
24 | 24 | ||
25 | if (m.tags.type.toLowerCase() === 'api') { | 25 | if (m.tags.type.toLowerCase() === 'api') { |
26 | - influxSender.addMessage({ | ||
27 | - measurement: 'api-info', | 26 | + apiSender.addMessage({ |
28 | tags: { | 27 | tags: { |
29 | app: m.tags.app, | 28 | app: m.tags.app, |
30 | - hostname: m.tags.hostname, | 29 | + host: m.tags.hostname, |
31 | api: m.tags.api | 30 | api: m.tags.api |
32 | }, | 31 | }, |
33 | fields: { | 32 | fields: { |
34 | - duration: m.duration, | 33 | + duration: duration, |
35 | times: 1 | 34 | times: 1 |
36 | } | 35 | } |
37 | }); | 36 | }); |
38 | } | 37 | } |
39 | 38 | ||
40 | if (m.tags.type.toLowerCase() === 'route') { | 39 | if (m.tags.type.toLowerCase() === 'route') { |
41 | - influxSender.addMessage({ | ||
42 | - measurement: 'route-info', | 40 | + routeSender.addMessage({ |
43 | tags: { | 41 | tags: { |
44 | app: m.tags.app, | 42 | app: m.tags.app, |
45 | - hostname: m.tags.hostname, | 43 | + host: m.tags.hostname, |
46 | route: m.tags.route | 44 | route: m.tags.route |
47 | - | ||
48 | }, | 45 | }, |
49 | fields: { | 46 | fields: { |
50 | - duration: m.duration | 47 | + duration: duration |
51 | } | 48 | } |
52 | }); | 49 | }); |
53 | } | 50 | } |
54 | } else if (m.measurement === 'error-report') { | 51 | } else if (m.measurement === 'error-report') { |
55 | errorSender.addMessage(msg2row.errorRouter(m)); | 52 | errorSender.addMessage(msg2row.errorRouter(m)); |
56 | } else if (m.measurement === 'process-info') { | 53 | } else if (m.measurement === 'process-info') { |
57 | - influxSender.addMessage(m); | 54 | + routeSender.addMessage(m); |
58 | } | 55 | } |
59 | } | 56 | } |
60 | } | 57 | } |
-
Please register or login to post a comment