Skip to content

Commit 4c8bbc7

Browse files
jamsinclairzbjornson
authored andcommitted
fix: set labels for linux memory metrics
1 parent 216e2b3 commit 4c8bbc7

File tree

2 files changed

+9
-3
lines changed

2 files changed

+9
-3
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ project adheres to [Semantic Versioning](http://semver.org/).
1212
### Changed
1313

1414
- Don't add event listener to `process` if cluster module is not used.
15+
- fix: set labels for default memory metrics on linux
1516

1617
### Added
1718

lib/metrics/osMemoryHeapLinux.js

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,14 @@ function structureOutput(input) {
3434
module.exports = (registry, config = {}) => {
3535
const registers = registry ? [registry] : undefined;
3636
const namePrefix = config.prefix ? config.prefix : '';
37+
const labels = config.labels ? config.labels : {};
38+
const labelNames = Object.keys(labels);
3739

3840
const residentMemGauge = new Gauge({
3941
name: namePrefix + PROCESS_RESIDENT_MEMORY,
4042
help: 'Resident memory size in bytes.',
4143
registers,
44+
labelNames,
4245
// Use this one metric's `collect` to set all metrics' values.
4346
collect() {
4447
try {
@@ -51,9 +54,9 @@ module.exports = (registry, config = {}) => {
5154
const stat = fs.readFileSync('/proc/self/status', 'utf8');
5255
const structuredOutput = structureOutput(stat);
5356

54-
residentMemGauge.set(structuredOutput.VmRSS);
55-
virtualMemGauge.set(structuredOutput.VmSize);
56-
heapSizeMemGauge.set(structuredOutput.VmData);
57+
residentMemGauge.set(labels, structuredOutput.VmRSS);
58+
virtualMemGauge.set(labels, structuredOutput.VmSize);
59+
heapSizeMemGauge.set(labels, structuredOutput.VmData);
5760
} catch {
5861
// noop
5962
}
@@ -63,11 +66,13 @@ module.exports = (registry, config = {}) => {
6366
name: namePrefix + PROCESS_VIRTUAL_MEMORY,
6467
help: 'Virtual memory size in bytes.',
6568
registers,
69+
labelNames,
6670
});
6771
const heapSizeMemGauge = new Gauge({
6872
name: namePrefix + PROCESS_HEAP,
6973
help: 'Process heap size in bytes.',
7074
registers,
75+
labelNames,
7176
});
7277
};
7378

0 commit comments

Comments
 (0)