Commit 4e2f695bedd9e46ab49a22ac061a2e17f5a0ac47
1 parent
99f1f3d97a
Exists in
master
Messages counter
Showing 2 changed files with 27 additions and 0 deletions Side-by-side Diff
lib/counters.js
... | ... | @@ -0,0 +1,24 @@ |
1 | +'use strict'; | |
2 | + | |
3 | +const countersSdk = require('komodo-sdk/counters'); | |
4 | + | |
5 | +function increment(name, modemInfo) { | |
6 | + if (!name || !modemInfo.imsi) return; | |
7 | + | |
8 | + countersSdk.increment(`IMSI_${modemInfo.IMSI}_${name}`); | |
9 | +} | |
10 | + | |
11 | +function get(name, modemInfo) { | |
12 | + return new Promise(async (resolve) => { | |
13 | + if (!name || !modemInfo.imsi) { | |
14 | + resolve(0); | |
15 | + return; | |
16 | + } | |
17 | + | |
18 | + const value = await countersSdk.get(`IMSI_${modemInfo.IMSI}_${name}`); | |
19 | + resolve(Number(value)); | |
20 | + }); | |
21 | +} | |
22 | + | |
23 | +exports.get = get; | |
24 | +exports.increment = increment; |
lib/modem.js
... | ... | @@ -21,6 +21,7 @@ const dbCops = require('./db-cops'); |
21 | 21 | const reportSender = require('./report-sender'); |
22 | 22 | // const msisdn = require('./msisdn'); |
23 | 23 | const registerModem = require('./register-modem'); |
24 | +const counters = require('./counters'); | |
24 | 25 | |
25 | 26 | const modemInfo = { |
26 | 27 | device: config.modem.device, |
... | ... | @@ -145,6 +146,7 @@ parserReadLine.on('data', (data) => { |
145 | 146 | registerModem(modemInfo); |
146 | 147 | } |
147 | 148 | } else if (data.indexOf('+CMTI: ') === 0) { |
149 | + counters.increment('MESSAGE_RECEIVED', modemInfo); | |
148 | 150 | onIncomingSMS(data); |
149 | 151 | } else if (data.indexOf('+COPS: ') === 0) { |
150 | 152 | onCOPS(data); |
... | ... | @@ -288,6 +290,7 @@ async function sendSMS(destination, msg) { |
288 | 290 | await mutex.setLockWaitForCommand(); |
289 | 291 | |
290 | 292 | logger.info('Sending message', { destination, msg }); |
293 | + counters.increment('MESSAGE_SENT', modemInfo); | |
291 | 294 | |
292 | 295 | const correctedDestination = `+${destination}`.replace(/^0/, '62').replace(/^\++/, '+'); |
293 | 296 |