mirror of
https://github.com/jambonz/sbc-inbound.git
synced 2026-10-09 21:14:09 +00:00
add metrics
This commit is contained in:
+25
-4
@@ -1,8 +1,7 @@
|
||||
const Emitter = require('events');
|
||||
const {getAppserver, isWSS, makeRtpEngineOpts} = require('./utils');
|
||||
const {isWSS, makeRtpEngineOpts} = require('./utils');
|
||||
const {forwardInDialogRequests} = require('drachtio-fn-b2b-sugar');
|
||||
const {parseUri, SipError} = require('drachtio-srf');
|
||||
const {getRtpEngine} = require('jambonz-rtpengine-utils')(process.env.JAMBONES_RTPENGINES.split(','));
|
||||
const debug = require('debug')('jambonz:sbc-inbound');
|
||||
|
||||
class CallSession extends Emitter {
|
||||
@@ -13,13 +12,21 @@ class CallSession extends Emitter {
|
||||
this.srf = req.srf;
|
||||
this.logger = logger.child({callId: req.get('Call-ID')});
|
||||
|
||||
this.getRtpEngine = req.srf.locals.getRtpEngine;
|
||||
this.getFeatureServer = req.srf.locals.getFeatureServer;
|
||||
this.stats = this.srf.locals.stats;
|
||||
this.activeCallIds = this.srf.locals.activeCallIds;
|
||||
|
||||
}
|
||||
|
||||
async connect() {
|
||||
const engine = getRtpEngine(this.logger);
|
||||
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!');
|
||||
const tags = ['accepted:no', 'sipStatus:480', `originator:${this.req.locals.originator}`];
|
||||
this.stats.increment('sbc.terminations', tags);
|
||||
return this.res.send(480);
|
||||
}
|
||||
debug(`got engine: ${JSON.stringify(engine)}`);
|
||||
@@ -31,6 +38,8 @@ class CallSession extends Emitter {
|
||||
const featureServer = this.getFeatureServer();
|
||||
if (!featureServer) {
|
||||
this.logger.info('No available feature servers, rejecting call!');
|
||||
const tags = ['accepted:no', 'sipStatus:480', `originator:${this.req.locals.originator}`];
|
||||
this.stats.increment('sbc.terminations', tags);
|
||||
return this.res.send(480);
|
||||
}
|
||||
this.logger.debug(`using feature server ${featureServer}`);
|
||||
@@ -79,6 +88,8 @@ class CallSession extends Emitter {
|
||||
}
|
||||
}
|
||||
|
||||
if (this.req.canceled) throw new Error('call canceled');
|
||||
|
||||
debug(`sending INVITE to ${proxy} with ${uri}`);
|
||||
const {uas, uac} = await this.srf.createB2BUA(this.req, this.res, uri, {
|
||||
proxy,
|
||||
@@ -102,16 +113,24 @@ class CallSession extends Emitter {
|
||||
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) {
|
||||
this.rtpEngineResource.destroy();
|
||||
this.activeCallIds.delete(this.req.get('Call-ID'));
|
||||
this.stats.gauge('sbc.sip.calls.count', this.activeCallIds.size);
|
||||
if (err instanceof SipError) {
|
||||
const tags = ['accepted:no', `sipStatus:${err.status}`, `originator:${this.req.locals.originator}`];
|
||||
this.stats.increment('sbc.terminations', tags);
|
||||
this.logger.info(`call failed with ${err.status}`);
|
||||
return this.emit('failed');
|
||||
}
|
||||
this.logger.error(err, 'unexpected error routing inbound call');
|
||||
else if (err.message !== 'call canceled') {
|
||||
this.logger.error(err, 'unexpected error routing inbound call');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -123,6 +142,8 @@ class CallSession extends Emitter {
|
||||
dlg.on('destroy', () => {
|
||||
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
|
||||
|
||||
Reference in New Issue
Block a user