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 4, 2017
1 parent 6b42bbf commit d05591a
Showing 1 changed file with 31 additions and 0 deletions.
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 d05591a

Please sign in to comment.