write call_counts time series data tracking inbound call counts by account

This commit is contained in:
Dave Horton
2022-04-01 13:08:25 -04:00
parent 17b53438e2
commit 91cd677ad8
5 changed files with 22 additions and 12 deletions

2
app.js
View File

@@ -14,6 +14,7 @@ const opts = Object.assign({
}, {level: process.env.JAMBONES_LOGLEVEL || 'info'});
const logger = require('pino')(opts);
const {
writeCallCount,
queryCdrs,
writeCdrs,
writeAlerts,
@@ -61,6 +62,7 @@ const {getRtpEngine, setRtpEngines} = require('@jambonz/rtpengine-utils')([], lo
});
srf.locals = {...srf.locals,
stats,
writeCallCount,
queryCdrs,
writeCdrs,
writeAlerts,

View File

@@ -257,9 +257,14 @@ class CallSession extends Emitter {
} catch (err) {}
this.unsubscribeDTMF(this.logger, this.req.get('Call-ID'), this.rtpEngineOpts.uas.tag);
if (process.env.JAMBONES_HOSTING || process.env.JAMBONES_TRACK_ACCOUNT_CALLS) {
const {account_sid, writeCallCount} = this.req.locals;
this.decrKey(this.callCountKey)
.then((count) => this.logger.info({key: this.callCountKey},
`after hangup there are ${count} active calls for this account`))
.then((count) => {
this.logger.info(
{key: this.callCountKey},
`after hangup there are ${count} active calls for this account`);
return writeCallCount({account_sid, calls_in_progress: count});
})
.catch((err) => this.logger.error({err}, 'Error decrementing call count'));
}

View File

@@ -224,7 +224,7 @@ module.exports = function(srf, logger) {
const {incrKey, decrKey} = req.srf.locals.realtimeDbHelpers;
const {logger, account_sid} = req.locals;
const {writeAlerts, AlertType} = req.srf.locals;
const {writeCallCount, writeAlerts, AlertType} = req.srf.locals;
assert(account_sid);
const key = makeCallCountKey(account_sid);
@@ -235,8 +235,9 @@ module.exports = function(srf, logger) {
.then((count) => {
logger.debug({key}, `after rejection there are ${count} active calls for this account`);
debug({key}, `after rejection there are ${count} active calls for this account`);
return;
return count;
})
.then((count) => writeCallCount({account_sid, calls_in_progress: count}))
.catch((err) => logger.error({err}, 'checkLimits: decrKey err'));
}
});
@@ -244,6 +245,8 @@ module.exports = function(srf, logger) {
try {
/* increment the call count */
const calls = await incrKey(key);
writeCallCount({account_sid, calls_in_progress: calls})
.catch((err) => logger.error({err}, 'checkLimits: error writing call count'));
if (!process.env.JAMBONES_HOSTING) return next();
/* compare to account's limit, though avoid db hit when call count is low */

14
package-lock.json generated
View File

@@ -15,7 +15,7 @@
"@jambonz/realtimedb-helpers": "^0.4.24",
"@jambonz/rtpengine-utils": "^0.3.1",
"@jambonz/stats-collector": "^0.1.6",
"@jambonz/time-series": "^0.1.7",
"@jambonz/time-series": "^0.1.9",
"aws-sdk": "^2.1036.0",
"bent": "^7.3.12",
"cidr-matcher": "^2.1.1",
@@ -1520,9 +1520,9 @@
}
},
"node_modules/@jambonz/time-series": {
"version": "0.1.7",
"resolved": "https://registry.npmjs.org/@jambonz/time-series/-/time-series-0.1.7.tgz",
"integrity": "sha512-H5/iahNzmUMRYTzRW6YFqmZ/hIMkAXIevOBixLZG6EU3eqY51keP9t0YvtoSc6go9W3SMByz8FD3EpXTxIonYA==",
"version": "0.1.9",
"resolved": "https://registry.npmjs.org/@jambonz/time-series/-/time-series-0.1.9.tgz",
"integrity": "sha512-FLD7mLGEMToG7s6LGWr/GtNp61753RBxyYuKSxCVI6G14bm6ydgcBdG85h8EGTVQlIp9dnwbn5ebSVsGb8a46w==",
"dependencies": {
"debug": "^4.3.1",
"influx": "^5.8.0"
@@ -7278,9 +7278,9 @@
}
},
"@jambonz/time-series": {
"version": "0.1.7",
"resolved": "https://registry.npmjs.org/@jambonz/time-series/-/time-series-0.1.7.tgz",
"integrity": "sha512-H5/iahNzmUMRYTzRW6YFqmZ/hIMkAXIevOBixLZG6EU3eqY51keP9t0YvtoSc6go9W3SMByz8FD3EpXTxIonYA==",
"version": "0.1.9",
"resolved": "https://registry.npmjs.org/@jambonz/time-series/-/time-series-0.1.9.tgz",
"integrity": "sha512-FLD7mLGEMToG7s6LGWr/GtNp61753RBxyYuKSxCVI6G14bm6ydgcBdG85h8EGTVQlIp9dnwbn5ebSVsGb8a46w==",
"requires": {
"debug": "^4.3.1",
"influx": "^5.8.0"

View File

@@ -31,7 +31,7 @@
"@jambonz/realtimedb-helpers": "^0.4.24",
"@jambonz/rtpengine-utils": "^0.3.1",
"@jambonz/stats-collector": "^0.1.6",
"@jambonz/time-series": "^0.1.7",
"@jambonz/time-series": "^0.1.9",
"aws-sdk": "^2.1036.0",
"bent": "^7.3.12",
"cidr-matcher": "^2.1.1",