Skip to content

Commit

Permalink
Add commit and public ip info to prometheus metrics (lynckia#1482)
Browse files Browse the repository at this point in the history
  • Loading branch information
jcague authored Oct 21, 2019
1 parent 59c19c9 commit 0a172a6
Show file tree
Hide file tree
Showing 3 changed files with 89 additions and 2 deletions.
2 changes: 1 addition & 1 deletion .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ jobs:
command: |
echo Building lynckia/licode:develop
SHORT_GIT_HASH="$(echo ${CIRCLE_SHA1} | cut -c -7)"
docker build --label COMMIT=${SHORT_GIT_HASH} --cache-from lynckia/licode:develop -t lynckia/licode:develop .
docker build --label COMMIT=${SHORT_GIT_HASH} --build-arg COMMIT=${SHORT_GIT_HASH} --cache-from lynckia/licode:develop -t lynckia/licode:develop .
- run:
name: Lint Erizo
Expand Down
8 changes: 8 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ MAINTAINER Lynckia

WORKDIR /opt

ARG COMMIT

# Download latest version of the code and install dependencies
RUN apt-get update && apt-get install -y git wget curl

Expand All @@ -28,6 +30,12 @@ RUN ./installErizo.sh -dfeacs && \
./../nuve/installNuve.sh && \
./installBasicExample.sh

WORKDIR /opt/licode

RUN echo $COMMIT > RELEASE
RUN date --rfc-3339='seconds' >> RELEASE
RUN cat RELEASE

WORKDIR /opt

ENTRYPOINT ["./licode/extras/docker/initDockerLicode.sh"]
81 changes: 80 additions & 1 deletion erizo_controller/ROV/rovMetricsGatherer.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,18 @@
const readline = require('readline');
const fs = require('fs');

// eslint-disable-next-line global-require, import/no-extraneous-dependencies
const AWS = require('aws-sdk');

// eslint-disable-next-line import/no-unresolved
const config = require('../../licode_config');

class RovMetricsGatherer {
constructor(rovClient, promClient, statsPrefix, logger) {
this.rovClient = rovClient;
this.prefix = statsPrefix;
this.prometheusMetrics = {
release: new promClient.Gauge({ name: this.getNameWithPrefix('release_info'), help: 'commit short hash', labelNames: ['commit', 'date', 'ip'] }),
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' }),
Expand All @@ -21,12 +31,79 @@ class RovMetricsGatherer {
totalSubscribersInErizoJS: new promClient.Gauge({ name: this.getNameWithPrefix('total_subscribers_erizojs'), help: 'total active subscribers in erizo js' }),
};
this.log = logger;
this.releaseInfoRead = false;
if (config && config.erizoAgent) {
this.publicIP = config.erizoAgent.publicIP;
}
}

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

getIP() {
// Here we assume that ROV runs in the same instance than Erizo Controller
if (config && config.cloudProvider && config.cloudProvider.name === 'amazon') {
return new Promise((resolve) => {
new AWS.MetadataService({
httpOptions: {
timeout: 5000,
},
}).request('/latest/meta-data/public-ipv4', (err, data) => {
if (err) {
this.log.error('Error: ', err);
} else {
this.publicIP = data;
}
resolve();
});
});
}
return Promise.resolve();
}

getReleaseInfo() {
this.log.debug('Getting release info');
if (!this.releaseInfoRead) {
this.releaseInfoRead = true;
try {
return new Promise((resolve) => {
const input = fs.createReadStream('../../RELEASE');

input.on('error', (e) => {
this.log.error('Error reading release file', e);
resolve();
});
const fileReader = readline.createInterface({
input,
output: process.stdout,
console: false,
});
let lineNumber = 0;
let releaseCommit = '';
let releaseDate = '';
fileReader.on('line', (line) => {
this.log.info(line);
if (lineNumber === 0) {
releaseCommit = line;
} else {
releaseDate = line;
}
lineNumber += 1;
});

fileReader.once('close', () => {
this.prometheusMetrics.release.labels(releaseCommit, releaseDate, this.publicIP).set(1);
resolve();
});
});
} catch (e) {
this.log.error('Error reading release file', e);
}
}
return Promise.resolve();
}

getTotalRooms() {
this.log.debug('Getting total rooms');
return this.rovClient.runInComponentList('console.log(context.rooms.size)', this.rovClient.components.erizoControllers)
Expand Down Expand Up @@ -128,7 +205,9 @@ class RovMetricsGatherer {
}

gatherMetrics() {
return this.rovClient.updateComponentsList()
return this.getIP()
.then(() => this.getReleaseInfo())
.then(() => this.rovClient.updateComponentsList())
.then(() => this.getTotalRooms())
.then(() => this.getTotalClients())
.then(() => this.getTotalPublishersAndSubscribers())
Expand Down

0 comments on commit 0a172a6

Please sign in to comment.