feature(alipay): send successfully registered info to influxdb
Showing
1 changed file
with
40 additions
and
0 deletions
1 | +const InfluxSender = require('influx-batch-sender'); | ||
1 | const alipayService = require('./alipay.service'); | 2 | const alipayService = require('./alipay.service'); |
3 | +const { logger, config } = global.yoho; | ||
4 | + | ||
5 | +/** | ||
6 | + * 统计成功注册的用户数, 使用 APM db | ||
7 | + */ | ||
8 | +const monitor = new InfluxSender({ | ||
9 | + ...config.report, | ||
10 | + measurement: 'alipay-register-count', | ||
11 | + duration: 1 * 60 * 1000, // 1m | ||
12 | + immediate: false, | ||
13 | +}); | ||
14 | + | ||
15 | +monitor.on('sendError', e => { | ||
16 | + logger.error('alipay send monitor info', e); | ||
17 | +}); | ||
18 | + | ||
19 | +monitor.on('failed', statusCode => { | ||
20 | + logger.warn('alipay send monitor info', statusCode); | ||
21 | +}); | ||
22 | + | ||
23 | +// monitor tags | ||
24 | +const tags = { | ||
25 | + appName: config.appName, | ||
26 | + host: require('os').hostname(), | ||
27 | + pid: process.pid, | ||
28 | +}; | ||
2 | 29 | ||
3 | function submit(req, res, next) { | 30 | function submit(req, res, next) { |
4 | const { alipayAccount, alipayName } = req.body; | 31 | const { alipayAccount, alipayName } = req.body; |
@@ -16,6 +43,19 @@ function submit(req, res, next) { | @@ -16,6 +43,19 @@ function submit(req, res, next) { | ||
16 | return res.json(result.error); | 43 | return res.json(result.error); |
17 | } | 44 | } |
18 | 45 | ||
46 | + try { | ||
47 | + monitor.addMessage({ | ||
48 | + tags, | ||
49 | + fields: { | ||
50 | + uid, | ||
51 | + ip: req.yoho.clientIp, | ||
52 | + udid: req.yoho.udid | ||
53 | + } | ||
54 | + }); | ||
55 | + } catch (e) { | ||
56 | + logger.error('alipay send monitor info, addMessage', e); | ||
57 | + } | ||
58 | + | ||
19 | return res.json(result); | 59 | return res.json(result); |
20 | }).catch(next); | 60 | }).catch(next); |
21 | } | 61 | } |
-
Please register or login to post a comment