Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions docs/metrics.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,25 @@ The current allocated heap size in bytes.

The currently used heap size in bytes.

[float]
[[metric-nodejs.memory.external.bytes]]
=== `nodejs.memory.external.bytes`

* *Type:* Long
* *Format:* Bytes

Memory usage of C++ objects bound to JavaScript objects managed by V8.

[float]
[[metric-nodejs.memory.arrayBuffers.bytes]]
=== `nodejs.memory.arrayBuffers.bytes`

* *Type:* Long
* *Format:* Bytes

Memory allocated for ArrayBuffers and SharedArrayBuffers, including all Node.js Buffers.
This is also included in the `nodejs.memory.external.bytes` value.

[float]
[[metrics-transaction.duration.sum]]
=== `transaction.duration.sum`
Expand Down
17 changes: 10 additions & 7 deletions lib/metrics/runtime.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
'use strict'

const v8 = require('v8')

const eventLoopMonitor = require('monitor-event-loop-delay')

const activeHandles = typeof process._getActiveHandles === 'function'
Expand All @@ -21,7 +19,9 @@ class RuntimeCollector {
'nodejs.requests.active': 0,
'nodejs.eventloop.delay.ns': 0,
'nodejs.memory.heap.allocated.bytes': 0,
'nodejs.memory.heap.used.bytes': 0
'nodejs.memory.heap.used.bytes': 0,
'nodejs.memory.external.bytes': 0,
'nodejs.memory.arrayBuffers.bytes': 0
}

const monitor = eventLoopMonitor({
Expand All @@ -43,10 +43,13 @@ class RuntimeCollector {
this.stats['nodejs.eventloop.delay.avg.ms'] = loopDelay
this.loopMonitor.reset()

// Heap
const heap = v8.getHeapStatistics()
this.stats['nodejs.memory.heap.allocated.bytes'] = heap.total_heap_size
this.stats['nodejs.memory.heap.used.bytes'] = heap.used_heap_size
// Memory / Heap
const memoryUsage = process.memoryUsage()
this.stats['nodejs.memory.heap.allocated.bytes'] = memoryUsage.heapTotal
this.stats['nodejs.memory.heap.used.bytes'] = memoryUsage.heapUsed

this.stats['nodejs.memory.external.bytes'] = memoryUsage.external
this.stats['nodejs.memory.arrayBuffers.bytes'] = memoryUsage.arrayBuffers || 0 // Only available in NodeJS +13.0

if (cb) process.nextTick(cb)
}
Expand Down
6 changes: 6 additions & 0 deletions test/metrics/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,12 @@ test('reports expected metrics', function (t) {
'nodejs.memory.heap.used.bytes': (value) => {
t.ok(value >= 0, 'is positive')
},
'nodejs.memory.external.bytes': (value) => {
t.ok(value >= 0, 'is positive')
},
'nodejs.memory.arrayBuffers.bytes': (value) => {
t.ok(value >= 0, 'is positive')
},
'ws.connections': (value) => {
t.equal(value, 23)
}
Expand Down