Skip to content

Commit

Permalink
Added option to set a prefix for prometheus stats (lynckia#1365)
Browse files Browse the repository at this point in the history
  • Loading branch information
lodoyun authored Feb 22, 2019
1 parent cc42561 commit bd55ddf
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 10 deletions.
17 changes: 11 additions & 6 deletions erizo_controller/ROV/rovMetricsGatherer.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,21 @@
class RovMetricsGatherer {
constructor(rovClient, promClient, logger) {
constructor(rovClient, promClient, statsPrefix, logger) {
this.rovClient = rovClient;
this.prefix = statsPrefix;
this.prometheusMetrics = {
activeRooms: new promClient.Gauge({ name: 'active_rooms', help: 'active rooms in all erizoControllers' }),
activeClients: new promClient.Gauge({ name: 'active_clients', help: 'active clients in all erizoControllers' }),
totalPublishers: new promClient.Gauge({ name: 'total_publishers', help: 'total active publishers' }),
totalSubscribers: new promClient.Gauge({ name: 'total_subscribers', help: 'total active subscribers' }),
activeErizoJsProcesses: new promClient.Gauge({ name: 'active_erizojs_processes', help: 'active processes' }),
activeRooms: new promClient.Gauge({ name: this.getNameWithPrefix('active_rooms'), help: 'active rooms in all erizoControllers' }),
activeClients: new promClient.Gauge({ name: this.getNameWithPrefix('active_clients'), help: 'active clients in all erizoControllers' }),
totalPublishers: new promClient.Gauge({ name: this.getNameWithPrefix('total_publishers'), help: 'total active publishers' }),
totalSubscribers: new promClient.Gauge({ name: this.getNameWithPrefix('total_subscribers'), help: 'total active subscribers' }),
activeErizoJsProcesses: new promClient.Gauge({ name: this.getNameWithPrefix('active_erizojs_processes'), help: 'active processes' }),
};
this.log = logger;
}

getNameWithPrefix(name) {
return `${this.prefix}${name}`;
}

getTotalRooms() {
this.log.debug('Getting total rooms');
return this.rovClient.runInComponentList('console.log(context.rooms.size)', this.rovClient.components.erizoControllers)
Expand Down
8 changes: 5 additions & 3 deletions erizo_controller/ROV/rovMetricsServer.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,12 +65,14 @@ log.info('Starting: Connecting to rabbitmq');
amqper.connect(() => {
log.info('connected to rabbitmq');
const rovClient = new RovClient(amqper);
const rovMetricsGatherer = new RovMetricsGatherer(rovClient, promClient, log);
const rovMetricsGatherer =
new RovMetricsGatherer(rovClient, promClient, config.rov.statsPrefix, log);
promClient.collectDefaultMetrics(
{ prefix: config.rov.statsPrefix, timeout: config.rov.statsPeriod });

setInterval(() => {
rovMetricsGatherer.gatherMetrics().then(() => {
log.debug('Gathered metrics, promClient Collecting');
promClient.collectDefaultMetrics();
log.debug('Gathered licode metrics');
})
.catch((error) => {
log.error('Error gathering metrics', error);
Expand Down
3 changes: 2 additions & 1 deletion scripts/licode_default.js
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,8 @@ config.rov = {};
config.rov.statsPeriod = 20000;
// The port to expose the stats to prometheus
config.rov.serverPort = 3005;

// A prefix for the prometheus stats
config.rov.statsPrefix = "licode_";
/***** END *****/
// Following lines are always needed.
var module = module || {};
Expand Down

0 comments on commit bd55ddf

Please sign in to comment.