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

Commit dd5a5e6

Browse files
committed
fix: bring back metrics file that got deleted during rebase
1 parent cde212f commit dd5a5e6

File tree

2 files changed

+32
-2
lines changed

2 files changed

+32
-2
lines changed

package.json

+1-2
Original file line numberDiff line numberDiff line change
@@ -128,9 +128,8 @@
128128
"lodash.get": "^4.4.2",
129129
"lodash.sortby": "^4.7.0",
130130
"lodash.values": "^4.3.0",
131-
"mime-types": "^2.1.13",
132-
"mafmt": "^2.1.8",
133131
"mime-types": "^2.1.16",
132+
"mafmt": "^2.1.8",
134133
"mkdirp": "~0.5.1",
135134
"multiaddr": "^2.3.0",
136135
"multihashes": "~0.4.9",

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)