This repository has been archived by the owner on Feb 12, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: bring back metrics file that got deleted during rebase
- Loading branch information
Showing
1 changed file
with
31 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
}) | ||
} | ||
}) | ||
} |