UNPKG

@hclsoftware/secagent

Version:

IAST agent

43 lines (35 loc) 1.24 kB
//IASTIGNORE /* * **************************************************** * Licensed Materials - Property of HCL. * (c) Copyright HCL Technologies Ltd. 2017, 2025. * Note to U.S. Government Users *Restricted Rights. * **************************************************** */ const v8 = require('v8') const {ConfigInfo} = require('../ConfigFile/ConfigInfo') class MemoryInfo { constructor() { this.usage = 0 this.totalMem = 0 this.usedMem = 0 } updateMemoryUsage() { let heapStats = v8.getHeapStatistics() this.usedMem = heapStats.used_heap_size this.totalMem = heapStats.heap_size_limit this.usage = this.usedMem / this.totalMem } checkMemoryWarning() { this.updateMemoryUsage(); return this.usage >= ConfigInfo.ConfigInfo.memoryThreshold } getMemoryDebugInfo() { return `Total memory: ${this.totalMem/1048576}MB, Used memory: ${Number(this.usedMem/1048576).toFixed(3)}MB, Usage: ${Number(this.usage).toFixed(3)}` } updateAndGetMemoryInfo() { this.updateMemoryUsage(); return this.getMemoryDebugInfo() } } module.exports.MemoryInfo = new MemoryInfo()