From ef9ee30fdc5b950a1e06b81d6e681947f3762d48 Mon Sep 17 00:00:00 2001 From: Dave Horton Date: Tue, 18 Feb 2020 20:19:20 -0500 Subject: [PATCH] more metrics --- app.js | 8 ++++++-- lib/call-session.js | 12 +++++------- 2 files changed, 11 insertions(+), 9 deletions(-) diff --git a/app.js b/app.js index 1efe416..d4568d9 100644 --- a/app.js +++ b/app.js @@ -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}; diff --git a/lib/call-session.js b/lib/call-session.js index 00c4283..8f25e68 100644 --- a/lib/call-session.js +++ b/lib/call-session.js @@ -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