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

Commit

Permalink
fix: bring back metrics file that got deleted during rebase
Browse files Browse the repository at this point in the history
  • Loading branch information
daviddias committed Sep 3, 2017
1 parent cde212f commit dd5a5e6
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 2 deletions.
3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -128,9 +128,8 @@
"lodash.get": "^4.4.2",
"lodash.sortby": "^4.7.0",
"lodash.values": "^4.3.0",
"mime-types": "^2.1.13",
"mafmt": "^2.1.8",
"mime-types": "^2.1.16",
"mafmt": "^2.1.8",
"mkdirp": "~0.5.1",
"multiaddr": "^2.3.0",
"multihashes": "~0.4.9",
Expand Down
31 changes: 31 additions & 0 deletions src/http/api/routes/debug.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
'use strict'

const register = require('prom-client').register
const client = require('prom-client')

// Endpoint for handling debug metrics
module.exports = (server) => {
const api = server.select('API')
// Clear the register to make sure we're not registering multiple ones
register.clear()
const gauge = new client.Gauge({ name: 'number_of_peers', help: 'the_number_of_currently_connected_peers' })

api.route({
method: 'GET',
path: '/debug/metrics/prometheus',
handler: (request, reply) => {
if (!process.env.IPFS_MONITORING) {
return reply('Monitoring is disabled. Enable it by setting environment variable IPFS_MONITORING')
.code(501) // 501 = Not Implemented
}
server.app.ipfs.swarm.peers((err, res) => {
if (err) {
return reply(err).code(500)
}
const count = res.length
gauge.set(count)
reply(register.metrics()).header('Content-Type', register.contentType)
})
}
})
}

0 comments on commit dd5a5e6

Please sign in to comment.