serverapm.js
1.41 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
const lineparse = require('../lib/line-parse');
const logger = global.yoho.logger;
const {
handleErrorReport,
handleProcessInfo,
handleWebServerDuration
} = require('./serverapm-service');
const server = {
async handle(data) {
try {
let msgs = lineparse.parse(data);
msgs.forEach((m) => {
if (!m.measurement) {
return;
}
switch (m.measurement) {
case 'web-server-duration': {
handleWebServerDuration(m);
break;
}
case 'error-report': {
handleErrorReport(m);
break;
}
case 'process-info': {
handleProcessInfo(m);
break;
}
default: {
logger.error('not handle server info [%s]', JSON.stringify(m));
break;
}
}
});
logger.info('[server] handle OK [%s]', data);
} 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);
};