serverapm.js
1.6 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
53
54
55
56
57
58
59
60
const lineparse = require('../lib/line-parse');
const bb = require('bluebird');
const logger = global.yoho.logger;
const {
handleErrorReport,
handleProcessInfo,
handleWebServerDuration
} = require('./serverapm-service');
//const riskService = require('./risk-service');
//const handleRisk = riskService();
const server = {
async handle(data) {
try {
let msgs = lineparse.parse(data);
await bb.map(msgs, async(m) => {
if (!m.measurement) {
return;
}
switch (m.measurement) {
case 'web-server-duration': {
handleWebServerDuration(m);
//await handleRisk(m);
break;
}
case 'error-report': {
handleErrorReport(m);
break;
}
case 'process-info': {
handleProcessInfo(m);
break;
}
default: {
logger.error('[server] handle ERROR [%s]', JSON.stringify(m));
break;
}
}
logger.info('[server] handle OK [%s]', data);
}, {concurrency: 2});
} catch (e) {
logger.error('[server] handle ERROR [%s]', e);
}
}
};
module.exports = function(req, res, next) {
let data = req.body || ' ';
server.handle(data).then(() => {
res.status(204).json();
}).catch(next);
};