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

Commit b545688

Browse files
authored
fix: add node memory stats to prometheus output (#4209)
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()`.
1 parent 89aeaf8 commit b545688

File tree

1 file changed

+11
-1
lines changed
  • packages/ipfs-http-server/src/api/routes

1 file changed

+11
-1
lines changed

packages/ipfs-http-server/src/api/routes/debug.js

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,13 @@ import { disable, enable } from '@libp2p/logger'
88
client.register.clear()
99

1010
/** @type {Record<string, client.Gauge<any>>} */
11-
const gauges = {}
11+
const gauges = {
12+
nodejs_memory_usage: new client.Gauge({
13+
name: 'nodejs_memory_usage',
14+
help: 'nodejs_memory_usage',
15+
labelNames: Object.keys(process.memoryUsage())
16+
})
17+
}
1218

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

32+
Object.entries(process.memoryUsage()).forEach(([key, value]) => {
33+
gauges.nodejs_memory_usage.set({ [key]: key }, value)
34+
})
35+
2636
const { ipfs } = request.server.app
2737
// @ts-expect-error libp2p does not exist on ipfs
2838
const metrics = ipfs.libp2p.metrics

0 commit comments

Comments
 (0)