Skip to content

Commit

Permalink
feat(UMetrics): export default nodejs metrics
Browse files Browse the repository at this point in the history
  • Loading branch information
Goodluckhf committed Oct 8, 2019
1 parent 27b03ef commit 6a90a82
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 0 deletions.
14 changes: 14 additions & 0 deletions src/UMetrics.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import promClient from 'prom-client';
import MetricRegistry from './MetricRegistry';
import GaugeMetric from './metric/GaugeMetric';
import Transport from './transport/Transport';
Expand Down Expand Up @@ -56,9 +57,22 @@ class UMetrics {
* @return UMetrics
*/
start() {
if (this.nodejsMetricsEnabled) {
this.enableExportingDefaultMetrics();
}
this.transport.start();
return this;
}

/**
* @private
*/
enableExportingDefaultMetrics() {
promClient.collectDefaultMetrics({
prefix: this.prefix,
timeout: this.nodejsMetricsInterval,
});
}
}

// Конструкторы метрик, как внешний интерфейс
Expand Down
30 changes: 30 additions & 0 deletions src/UMetrics.server.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,4 +56,34 @@ describe('UMetrics facade', () => {
});
expect(uMetrics.nodejsMetricsInterval).to.be.equals(7000);
});

it('Should enable default metrics exports if option provided', () => {
let calledCount = 0;
const uMetrics = new UMetrics(new Transport(), {
port: 1111,
nodejsMetricsEnabled: true,
});

uMetrics.enableExportingDefaultMetrics = () => {
calledCount += 1;
};

uMetrics.start();
expect(calledCount).to.be.equals(1);
});

it('Should not enable default metrics exports if option is not provided', () => {
let calledCount = 0;
const uMetrics = new UMetrics(new Transport(), {
port: 1111,
nodejsMetricsEnabled: false,
});

uMetrics.enableExportingDefaultMetrics = () => {
calledCount += 1;
};

uMetrics.start();
expect(calledCount).to.be.equals(0);
});
});

0 comments on commit 6a90a82

Please sign in to comment.