Merge pull request #793 from shocknet/memory-usage

memory usage stats
This commit is contained in:
Justin (shocknet) 2025-02-25 15:20:38 -05:00 committed by GitHub
commit 4b86cd12b5
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 19 additions and 0 deletions

View file

@ -2,10 +2,15 @@ import { MainSettings } from "../main/settings.js";
import { StateBundler } from "../storage/stateBundler.js";
export class Utils {
stateBundler: StateBundler
settings: MainSettings
constructor(settings: MainSettings) {
this.settings = settings
this.stateBundler = new StateBundler(settings.storageSettings)
}
Stop() {
this.stateBundler.Stop()
}
}

View file

@ -84,6 +84,7 @@ export default class {
this.lnd.Stop()
this.applicationManager.Stop()
this.paymentManager.Stop()
this.utils.Stop()
}
StartBeacons() {

View file

@ -33,10 +33,23 @@ export class StateBundler {
tlvStorage: TlvFilesStorage
reportLog = getLogger({ component: 'stateBundlerReport' })
prevValues: Record<string, number> = {}
interval: NodeJS.Timeout
constructor(settings: StorageSettings) {
const bundlerPath = [settings.dataDir, "bundler_events"].filter(s => !!s).join("/")
this.tlvStorage = new TlvFilesStorage(bundlerPath)
this.tlvStorage.initMeta()
this.interval = setInterval(() => {
const mem = process.memoryUsage()
this.AddValue('_root', 'memory_rss_kb', Math.ceil(mem.rss / 1000 || 0), true)
this.AddValue('_root', 'memory_buffer_kb', Math.ceil(mem.arrayBuffers / 1000 || 0), true)
this.AddValue('_root', 'memory_heap_total_kb', Math.ceil(mem.heapTotal / 1000 || 0), true)
this.AddValue('_root', 'memory_heap_used_kb', Math.ceil(mem.heapUsed / 1000 || 0), true)
this.AddValue('_root', 'memory_external_kb', Math.ceil(mem.external / 1000 || 0), true)
}, 60 * 1000)
}
Stop() {
clearInterval(this.interval)
}
async GetBundleMetrics(req: Types.LatestBundleMetricReq): Promise<Types.BundleMetrics> {