| 13 | let started = false |
| 14 | |
| 15 | export function startMemoryTelemetry(intervalMs = 60_000) { |
| 16 | if (started) return |
| 17 | started = true |
| 18 | |
| 19 | const timer = setInterval(() => { |
| 20 | const mem = process.memoryUsage() |
| 21 | const heap = v8.getHeapStatistics() |
| 22 | |
| 23 | logger.info('Memory snapshot', { |
| 24 | heapUsedMB: Math.round(mem.heapUsed / MB), |
| 25 | heapTotalMB: Math.round(mem.heapTotal / MB), |
| 26 | rssMB: Math.round(mem.rss / MB), |
| 27 | externalMB: Math.round(mem.external / MB), |
| 28 | arrayBuffersMB: Math.round(mem.arrayBuffers / MB), |
| 29 | heapSizeLimitMB: Math.round(heap.heap_size_limit / MB), |
| 30 | nativeContexts: heap.number_of_native_contexts, |
| 31 | activeResources: |
| 32 | typeof process.getActiveResourcesInfo === 'function' |
| 33 | ? process.getActiveResourcesInfo().length |
| 34 | : -1, |
| 35 | uptimeMin: Math.round(process.uptime() / 60), |
| 36 | }) |
| 37 | }, intervalMs) |
| 38 | timer.unref() |
| 39 | } |