more metrics

This commit is contained in:
Dave Horton
2020-02-18 20:19:20 -05:00
parent f5b8853581
commit ef9ee30fdc
2 changed files with 11 additions and 9 deletions
+6 -2
View File
@@ -14,13 +14,13 @@ const opts = Object.assign({
}, {level: process.env.JAMBONES_LOGLEVEL || 'info'});
const logger = require('pino')(opts);
const StatsCollector = require('jambonz-stats-collector');
srf.locals.stats = new StatsCollector(logger);
const stats = srf.locals.stats = new StatsCollector(logger);
srf.locals.getFeatureServer = require('./lib/fs-tracking')(srf, logger);
const {getRtpEngine} = require('jambonz-rtpengine-utils')(process.env.JAMBONES_RTPENGINES.split(','), {
emitter: srf.locals.stats
});
srf.locals.getRtpEngine = getRtpEngine;
srf.locals.activeCallIds = new Set();
const activeCallIds = srf.locals.activeCallIds = new Set();
logger.info('starting..');
const {
@@ -69,4 +69,8 @@ srf.use((req, res, next, err) => {
res.send(500);
});
setInterval(() => {
stats.gauge('sbc.sip.calls.count', activeCallIds.size, ['direction:inbound']);
}, 3000);
module.exports = {srf, logger};
+5 -7
View File
@@ -20,8 +20,6 @@ class CallSession extends Emitter {
}
async connect() {
this.activeCallIds.add(this.req.get('Call-ID'));
this.stats.gauge('sbc.sip.calls.count', this.activeCallIds.size);
const engine = this.getRtpEngine(this.logger);
if (!engine) {
this.logger.info('No available rtpengines, rejecting call!');
@@ -112,10 +110,6 @@ class CallSession extends Emitter {
// successfully connected
this.logger.info('call connected');
debug('call connected');
this.emit('connected');
const tags = ['accepted:yes', 'sipStatus:200', `originator:${this.req.locals.originator}`];
this.stats.increment('sbc.terminations', tags);
this._setHandlers({uas, uac});
return;
} catch (err) {
@@ -135,6 +129,11 @@ class CallSession extends Emitter {
}
_setHandlers({uas, uac}) {
this.emit('connected');
const tags = ['accepted:yes', 'sipStatus:200', `originator:${this.req.locals.originator}`];
this.stats.increment('sbc.terminations', tags);
this.activeCallIds.add(this.req.get('Call-ID'));
this.uas = uas;
this.uac = uac;
[uas, uac].forEach((dlg) => {
@@ -143,7 +142,6 @@ class CallSession extends Emitter {
this.logger.info('call ended');
this.rtpEngineResource.destroy();
this.activeCallIds.delete(this.req.get('Call-ID'));
this.stats.gauge('sbc.sip.calls.count', this.activeCallIds.size);
});
//re-invite