Skip to content

Commit 95fa1fb

Browse files
committed
feat(metrics): add metrics for external memory
Added metrics for `nodejs.memory.external.bytes` and `nodejs.memory.arrayBuffers.bytes`
1 parent b1f4b81 commit 95fa1fb

File tree

3 files changed

+31
-1
lines changed

3 files changed

+31
-1
lines changed

docs/metrics.asciidoc

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,25 @@ The current allocated heap size in bytes.
129129

130130
The currently used heap size in bytes.
131131

132+
[float]
133+
[[metric-nodejs.memory.external.bytes]]
134+
=== `nodejs.memory.external.bytes`
135+
136+
* *Type:* Long
137+
* *Format:* Bytes
138+
139+
Memory usage of C++ objects bound to JavaScript objects managed by V8.
140+
141+
[float]
142+
[[metric-nodejs.memory.arrayBuffers.bytes]]
143+
=== `nodejs.memory.arrayBuffers.bytes`
144+
145+
* *Type:* Long
146+
* *Format:* Bytes
147+
148+
Memory allocated for ArrayBuffers and SharedArrayBuffers, including all Node.js Buffers.
149+
This is also included in the `nodejs.memory.external.bytes` value.
150+
132151
[float]
133152
[[metrics-transaction.duration.sum]]
134153
=== `transaction.duration.sum`

lib/metrics/runtime.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,9 @@ class RuntimeCollector {
1919
'nodejs.requests.active': 0,
2020
'nodejs.eventloop.delay.ns': 0,
2121
'nodejs.memory.heap.allocated.bytes': 0,
22-
'nodejs.memory.heap.used.bytes': 0
22+
'nodejs.memory.heap.used.bytes': 0,
23+
'nodejs.memory.external.bytes': 0,
24+
'nodejs.memory.arrayBuffers.bytes': 0
2325
}
2426

2527
const monitor = eventLoopMonitor({
@@ -46,6 +48,9 @@ class RuntimeCollector {
4648
this.stats['nodejs.memory.heap.allocated.bytes'] = memoryUsage.heapTotal
4749
this.stats['nodejs.memory.heap.used.bytes'] = memoryUsage.heapUsed
4850

51+
this.stats['nodejs.memory.external.bytes'] = memoryUsage.external
52+
this.stats['nodejs.memory.arrayBuffers.bytes'] = memoryUsage.arrayBuffers || 0 // Only available in NodeJS +13.0
53+
4954
if (cb) process.nextTick(cb)
5055
}
5156
}

test/metrics/index.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,12 @@ test('reports expected metrics', function (t) {
117117
'nodejs.memory.heap.used.bytes': (value) => {
118118
t.ok(value >= 0, 'is positive')
119119
},
120+
'nodejs.memory.external.bytes': (value) => {
121+
t.ok(value >= 0, 'is positive')
122+
},
123+
'nodejs.memory.arrayBuffers.bytes': (value) => {
124+
t.ok(value >= 0, 'is positive')
125+
},
120126
'ws.connections': (value) => {
121127
t.equal(value, 23)
122128
}

0 commit comments

Comments
 (0)