| 390 | } |
| 391 | |
| 392 | protected async sample(): Promise<void> { |
| 393 | const { cpu, memory } = await this.statsSource.read(); |
| 394 | |
| 395 | if (cpu !== null) { |
| 396 | // statsSource returns 0-1 fraction; smoothed value is stored as 0-100 percent. |
| 397 | const current = cpu * 100; |
| 398 | const alpha = this.config.getCpuEmaAlpha(); |
| 399 | this.smoothedCpu = |
| 400 | this.smoothedCpu === null |
| 401 | ? current |
| 402 | : alpha * current + (1 - alpha) * this.smoothedCpu; |
| 403 | } |
| 404 | |
| 405 | if (memory !== null) { |
| 406 | this.cachedMemory = memory; |
| 407 | } |
| 408 | } |
| 409 | |
| 410 | public async getMachineStats(): Promise<IResourceLoad> { |
| 411 | return this.statsSource.read(); |