Skip to content
This repository was archived by the owner on Feb 12, 2024. It is now read-only.

Commit d05591a

Browse files
committed
fix: bring back metrics file that got deleted during rebase
1 parent 6b42bbf commit d05591a

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed

src/http/api/routes/debug.js

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
'use strict'
2+
3+
const register = require('prom-client').register
4+
const client = require('prom-client')
5+
6+
// Endpoint for handling debug metrics
7+
module.exports = (server) => {
8+
const api = server.select('API')
9+
// Clear the register to make sure we're not registering multiple ones
10+
register.clear()
11+
const gauge = new client.Gauge({ name: 'number_of_peers', help: 'the_number_of_currently_connected_peers' })
12+
13+
api.route({
14+
method: 'GET',
15+
path: '/debug/metrics/prometheus',
16+
handler: (request, reply) => {
17+
if (!process.env.IPFS_MONITORING) {
18+
return reply('Monitoring is disabled. Enable it by setting environment variable IPFS_MONITORING')
19+
.code(501) // 501 = Not Implemented
20+
}
21+
server.app.ipfs.swarm.peers((err, res) => {
22+
if (err) {
23+
return reply(err).code(500)
24+
}
25+
const count = res.length
26+
gauge.set(count)
27+
reply(register.metrics()).header('Content-Type', register.contentType)
28+
})
29+
}
30+
})
31+
}

0 commit comments

Comments
 (0)