Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move rss metric from system.process.memory.* to nodejs.memory.* #1725

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
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
39 changes: 29 additions & 10 deletions docs/metrics.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -51,16 +51,6 @@ Free memory of the system in bytes.
The percentage of CPU time spent by the process since the last event.
This value is normalized by the number of CPU cores and it ranges from 0 to 100%.

[float]
[[metric-system.process.memory.rss.bytes]]
=== `system.process.memory.rss.bytes`

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

The Resident Set Size,
the amount of memory the process occupies in main memory (RAM).

[float]
[[metric-nodejs.handles.active]]
=== `nodejs.handles.active`
Expand Down Expand Up @@ -111,6 +101,16 @@ Event loop delay is sampled every 10 milliseconds.
Delays shorter than 10ms may not be observed,
for example if a blocking operation starts and ends within the same sampling period.

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

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

The Resident Set Size,
the amount of memory the process occupies in main memory (RAM).

[float]
[[metric-nodejs.memory.heap.allocated.bytes]]
=== `nodejs.memory.heap.allocated.bytes`
Expand All @@ -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
5 changes: 0 additions & 5 deletions lib/metrics/platforms/generic/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,4 @@ module.exports = function createSystemMetrics (registry) {
for (const metric of metrics) {
registry.getOrCreateGauge(metric, () => stats.toJSON()[metric])
}

registry.getOrCreateGauge(
'system.process.memory.rss.bytes',
() => process.memoryUsage().rss
)
}
7 changes: 2 additions & 5 deletions lib/metrics/platforms/linux/stats.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,7 @@ class Stats {
'system.process.cpu.total.norm.pct': 0,
'system.process.cpu.system.norm.pct': 0,
'system.process.cpu.user.norm.pct': 0,
'system.process.memory.size': 0,
'system.process.memory.rss.bytes': 0
'system.process.memory.size': 0
}

this.inProgress = false
Expand Down Expand Up @@ -150,8 +149,7 @@ class Stats {
memAvailable,
utime,
stime,
vsize,
rss: process.memoryUsage().rss // TODO: Calculate using field 24 (rss) * PAGE_SIZE
vsize
}
}

Expand Down Expand Up @@ -186,7 +184,6 @@ class Stats {
stats['system.process.cpu.user.norm.pct'] = cpuProcessUserPercent
stats['system.process.cpu.system.norm.pct'] = cpuProcessSystemPercent
stats['system.process.memory.size'] = next.vsize
stats['system.process.memory.rss.bytes'] = next.rss

this.previous = next
this.inProgress = false
Expand Down
19 changes: 12 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,10 @@ 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.rss.bytes': 0,
'nodejs.memory.external.bytes': 0,
'nodejs.memory.arrayBuffers.bytes': 0
}

const monitor = eventLoopMonitor({
Expand All @@ -43,10 +44,14 @@ 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.rss.bytes'] = memoryUsage.rss
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
14 changes: 10 additions & 4 deletions test/metrics/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,10 +81,6 @@ test('reports expected metrics', function (t) {
t.ok(isRoughly(value, free, 0.1), `is close to current free memory (value: ${value}, free: ${free})`)
}
},
'system.process.memory.rss.bytes': (value) => {
const rss = process.memoryUsage().rss
t.ok(isRoughly(value, rss, 0.1), `is close to current rss (value: ${value}, rss: ${rss})`)
},
'system.process.cpu.total.norm.pct': (value) => {
if (count === 1) {
t.ok(value >= 0 && value <= 1, 'is betewen 0 and 1')
Expand Down Expand Up @@ -117,6 +113,16 @@ test('reports expected metrics', function (t) {
'nodejs.memory.heap.used.bytes': (value) => {
t.ok(value >= 0, 'is positive')
},
'nodejs.memory.rss.bytes': (value) => {
const rss = process.memoryUsage().rss
t.ok(isRoughly(value, rss, 0.1), `is close to current rss (value: ${value}, rss: ${rss})`)
},
'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