Skip to content

Commit

Permalink
fix: set labels for linux memory metrics
Browse files Browse the repository at this point in the history
  • Loading branch information
jamsinclair authored and zbjornson committed Jul 31, 2021
1 parent 216e2b3 commit 4c8bbc7
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ project adheres to [Semantic Versioning](http://semver.org/).
### Changed

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

### Added

Expand Down
11 changes: 8 additions & 3 deletions lib/metrics/osMemoryHeapLinux.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,14 @@ function structureOutput(input) {
module.exports = (registry, config = {}) => {
const registers = registry ? [registry] : undefined;
const namePrefix = config.prefix ? config.prefix : '';
const labels = config.labels ? config.labels : {};
const labelNames = Object.keys(labels);

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

residentMemGauge.set(structuredOutput.VmRSS);
virtualMemGauge.set(structuredOutput.VmSize);
heapSizeMemGauge.set(structuredOutput.VmData);
residentMemGauge.set(labels, structuredOutput.VmRSS);
virtualMemGauge.set(labels, structuredOutput.VmSize);
heapSizeMemGauge.set(labels, structuredOutput.VmData);
} catch {
// noop
}
Expand All @@ -63,11 +66,13 @@ module.exports = (registry, config = {}) => {
name: namePrefix + PROCESS_VIRTUAL_MEMORY,
help: 'Virtual memory size in bytes.',
registers,
labelNames,
});
const heapSizeMemGauge = new Gauge({
name: namePrefix + PROCESS_HEAP,
help: 'Process heap size in bytes.',
registers,
labelNames,
});
};

Expand Down

0 comments on commit 4c8bbc7

Please sign in to comment.