mirror of
https://github.com/jambonz/jambonz-feature-server.git
synced 2025-12-20 16:50:39 +00:00
metrics
This commit is contained in:
@@ -1,12 +1,12 @@
|
||||
const ip = require('ip');
|
||||
const localIp = ip.address();
|
||||
const PORT = process.env.HTTP_PORT || 3000;
|
||||
const assert = require('assert');
|
||||
|
||||
function installSrfLocals(srf, logger) {
|
||||
if (srf.locals.dbHelpers) return;
|
||||
assert(!srf.locals.dbHelpers);
|
||||
|
||||
const {getSBC, getSrf} = require('./sbc-pinger')(logger);
|
||||
|
||||
const freeswitch = process.env.JAMBONES_FREESWITCH
|
||||
.split(',')
|
||||
.map((fs) => {
|
||||
@@ -15,6 +15,9 @@ function installSrfLocals(srf, logger) {
|
||||
});
|
||||
logger.info({freeswitch}, 'freeswitch inventory');
|
||||
|
||||
const StatsCollector = require('jambonz-stats-collector');
|
||||
const stats = srf.locals.stats = new StatsCollector(logger);
|
||||
|
||||
const {
|
||||
lookupAppByPhoneNumber,
|
||||
lookupAppBySid,
|
||||
@@ -51,8 +54,11 @@ function installSrfLocals(srf, logger) {
|
||||
serviceUrl: `http://${localIp}:${PORT}`,
|
||||
getSBC,
|
||||
getSrf,
|
||||
getFreeswitch: () => freeswitch[0]
|
||||
getFreeswitch: () => freeswitch[0],
|
||||
stats: stats
|
||||
});
|
||||
|
||||
logger.debug({locals: srf.locals}, 'srf.locals installed');
|
||||
}
|
||||
|
||||
module.exports = installSrfLocals;
|
||||
|
||||
@@ -153,7 +153,7 @@ class SingleDialer extends Emitter {
|
||||
status.sipStatus = err.status;
|
||||
if (err.status === 487) status.callStatus = CallStatus.NoAnswer;
|
||||
else if ([486, 600].includes(err.status)) status.callStatus = CallStatus.Busy;
|
||||
this.logger.debug(`SingleDialer:exec outdial failure ${err.status}`);
|
||||
this.logger.info(`SingleDialer:exec outdial failure ${err.status}`);
|
||||
}
|
||||
else {
|
||||
this.logger.error(err, 'SingleDialer:exec');
|
||||
|
||||
@@ -31,15 +31,22 @@ class Requestor {
|
||||
|
||||
const u = parseUrl(this.url);
|
||||
const myPort = u.port ? `:${u.port}` : '';
|
||||
const baseUrl = `${u.protocol}://${u.resource}${myPort}`;
|
||||
const baseUrl = this._baseUrl = `${u.protocol}://${u.resource}${myPort}`;
|
||||
|
||||
this.get = bent(baseUrl, 'GET', 'buffer', 200, 201);
|
||||
this.post = bent(baseUrl, 'POST', 'buffer', 200, 201);
|
||||
|
||||
this.username = hook.username;
|
||||
this.password = hook.password;
|
||||
|
||||
assert(isAbsoluteUrl(this.url));
|
||||
assert(['GET', 'POST'].includes(this.method));
|
||||
}
|
||||
|
||||
get baseUrl() {
|
||||
return this._baseUrl;
|
||||
}
|
||||
|
||||
/**
|
||||
* Make an HTTP request.
|
||||
* All requests use json bodies.
|
||||
@@ -61,11 +68,11 @@ class Requestor {
|
||||
assert.ok, (['GET', 'POST'].includes(method), `Requestor:request method must be 'GET' or 'POST' not ${method}`);
|
||||
|
||||
|
||||
this.logger.debug({hook}, `Requestor:request ${method} ${url}`);
|
||||
this.logger.debug({hook, params}, `Requestor:request ${method} ${url}`);
|
||||
const buf = isRelativeUrl(url) ?
|
||||
await this.post(url, params, this.authHeader) :
|
||||
await bent(method, 'buffer', 200, 201)(url, params, basicAuth(username, password));
|
||||
//this.logger.debug({body: }, `Requestor:request ${method} ${url} succeeded`);
|
||||
this.logger.debug(`Requestor:request ${method} ${url} succeeded`);
|
||||
|
||||
if (buf && buf.toString().length > 0) {
|
||||
try {
|
||||
|
||||
Reference in New Issue
Block a user