Skip to content

Commit a3f2ce7

Browse files
mcollinaclaude
authored andcommitted
refactor: use async fs/promises in osMemoryHeapLinux
Changed osMemoryHeapLinux to use async readFile from fs/promises instead of synchronous readFileSync for better non-blocking I/O. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
1 parent 4b87a35 commit a3f2ce7

File tree

1 file changed

+4
-5
lines changed

1 file changed

+4
-5
lines changed

lib/metrics/osMemoryHeapLinux.js

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
'use strict';
22

33
const Gauge = require('../gauge');
4-
const fs = require('fs');
4+
const { readFile } = require('fs/promises');
55

66
const values = ['VmSize', 'VmRSS', 'VmData'];
77

@@ -42,15 +42,14 @@ module.exports = (registry, config = {}) => {
4242
registers,
4343
labelNames,
4444
// Use this one metric's `collect` to set all metrics' values.
45-
collect() {
45+
async collect() {
4646
try {
47-
// Sync I/O is often problematic, but /proc isn't really I/O, it
48-
// a virtual filesystem that maps directly to in-kernel data
47+
// /proc is a virtual filesystem that maps directly to in-kernel data
4948
// structures and never blocks.
5049
//
5150
// Node.js/libuv do this already for process.memoryUsage(), see:
5251
// - https://github.com/libuv/libuv/blob/a629688008694ed8022269e66826d4d6ec688b83/src/unix/linux-core.c#L506-L523
53-
const stat = fs.readFileSync('/proc/self/status', 'utf8');
52+
const stat = await readFile('/proc/self/status', 'utf8');
5453
const structuredOutput = structureOutput(stat);
5554

5655
residentMemGauge.set(labels, structuredOutput.VmRSS);

0 commit comments

Comments
 (0)