Skip to content

Commit 55aa171

Browse files
authored
Allow turning off default metrics collection. (#6)
1 parent 4ca3c48 commit 55aa171

File tree

2 files changed

+20
-4
lines changed

2 files changed

+20
-4
lines changed

index.js

+4-2
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,10 @@ class APM {
5050
// prometheus stuff
5151
// --------------------------------------------------------------
5252
this.config.NORMALIZE_ENDPOINT = this.config.NORMALIZE_ENDPOINT === undefined ? true : this.config.NORMALIZE_ENDPOINT
53-
const collectDefaultMetrics = this.client.collectDefaultMetrics
54-
collectDefaultMetrics(this.config.PROM_CLIENT_CONF)
53+
if ([1, true, 'true', 'on', 'yes', undefined].indexOf(this.config.COLLECT_DEFAULT_METRICS) >= 0 ) {
54+
const collectDefaultMetrics = this.client.collectDefaultMetrics
55+
collectDefaultMetrics(this.config.PROM_CLIENT_CONF)
56+
}
5557
this.server = http.createServer(requestListener)
5658
this.server.listen(this.config.PORT || 9350)
5759
}

tests/main.test.js

+16-2
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,26 @@
11
const APM = require('../index')
22

3-
describe('retry', () => {
3+
describe('prom-client integration', () => {
44
let apm
55

6-
afterAll(() => {
6+
afterEach(() => {
77
apm.destroy()
88
})
99

10+
it('should report metrics by default', async () => {
11+
apm = new APM()
12+
apm.init()
13+
const data = await apm.client.register.metrics()
14+
expect(data.includes("process_cpu_user_seconds_total")).toEqual(true)
15+
});
16+
17+
it('should support turning off default collection', async () => {
18+
apm = new APM({ COLLECT_DEFAULT_METRICS: false })
19+
apm.init()
20+
const data = await apm.client.register.metrics()
21+
expect(data.includes("process_cpu_user_seconds_total")).toEqual(false)
22+
});
23+
1024
it('should use custom config for prom', async () => {
1125
apm = new APM({
1226
PROM_CLIENT_CONF: {

0 commit comments

Comments
 (0)