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

Commit

Permalink
fix: add node memory stats to prometheus output (#4209)
Browse files Browse the repository at this point in the history
The default prometheus memory stats are clunky and hard to interpret without additional tools like graphana because you get separate measurements for different types of memory usage.

Add a single `nodejs_memory_usage` metric that is the output of `process.memoryUsage()`.
  • Loading branch information
achingbrain committed Sep 16, 2022
1 parent 89aeaf8 commit b545688
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion packages/ipfs-http-server/src/api/routes/debug.js
Expand Up @@ -8,7 +8,13 @@ import { disable, enable } from '@libp2p/logger'
client.register.clear()

/** @type {Record<string, client.Gauge<any>>} */
const gauges = {}
const gauges = {
nodejs_memory_usage: new client.Gauge({
name: 'nodejs_memory_usage',
help: 'nodejs_memory_usage',
labelNames: Object.keys(process.memoryUsage())
})
}

// Endpoint for handling debug metrics
export default [{
Expand All @@ -23,6 +29,10 @@ export default [{
throw Boom.notImplemented('Monitoring is disabled. Enable it by setting environment variable IPFS_MONITORING')
}

Object.entries(process.memoryUsage()).forEach(([key, value]) => {
gauges.nodejs_memory_usage.set({ [key]: key }, value)
})

const { ipfs } = request.server.app
// @ts-expect-error libp2p does not exist on ipfs
const metrics = ipfs.libp2p.metrics
Expand Down

0 comments on commit b545688

Please sign in to comment.