From 94e5187d88a3a88141ce8965d04f55687e1148a4 Mon Sep 17 00:00:00 2001 From: Sebastian Hildebrandt Date: Thu, 8 Dec 2022 13:14:01 +0100 Subject: [PATCH] dockerContainerStats() improved calculation cpuPercent --- CHANGELOG.md | 1 + README.md | 4 ++-- docs/history.html | 7 ++++++- docs/index.html | 4 ++-- lib/docker.js | 8 +++++++- 5 files changed, 18 insertions(+), 6 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 4daf427..f4e0b51 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -82,6 +82,7 @@ For major (breaking) changes - **version 4, 3 and 2** - see end of page. | Version | Date | Comment | | ------- | ---------- | --------------------------------------------------------------------------------------------------- | +| 5.16.2 | 2022-12-08 | `dockerContainerStats()` improved calculation cpuPercent | | 5.16.1 | 2022-12-04 | code cleanup, moved from lgtm to GitHub Code Scan | | 5.16.0 | 2022-12-01 | `fsSize()` added rw (win, linux, mac OS, BSD) | | 5.15.1 | 2022-11-29 | fix typescript typings | diff --git a/README.md b/README.md index 8ac6800..b2866dd 100644 --- a/README.md +++ b/README.md @@ -24,8 +24,8 @@ [![Git Issues][issues-img]][issues-url] [![Closed Issues][closed-issues-img]][closed-issues-url] no dependencies - [![Caretaker][caretaker-image]][caretaker-url] [![Sponsoring][sponsor-badge]][sponsor-url] + [![Caretaker][caretaker-image]][caretaker-url] [![MIT license][license-img]][license-url] This is amazing. Started as a small project just for myself, it now has > 15,000 lines of code, > 500 versions published, up to 5 mio downloads per month, > 100 mio downloads overall. #1 NPM ranking for backend packages. Thank you to all who contributed to this project! @@ -1057,7 +1057,7 @@ All other trademarks are the property of their respective owners. [downloads-image]: https://img.shields.io/npm/dm/systeminformation.svg?style=flat-square [downloads-url]: https://npmjs.org/package/systeminformation -[sponsor-badge]: https://img.shields.io/badge/-Buy%20me%20a%20coffee-blue?style=flat-square +[sponsor-badge]: https://img.shields.io/badge/Support-Buy%20me%20a%20coffee-brightgreen?style=flat-square [sponsor-url]: https://www.buymeacoffee.com/systeminfo [license-url]: https://github.com/sebhildebrandt/systeminformation/blob/master/LICENSE diff --git a/docs/history.html b/docs/history.html index 4345336..d8b0f9f 100644 --- a/docs/history.html +++ b/docs/history.html @@ -57,6 +57,11 @@ + + 5.16.2 + 2022-12-04 + code cleanup, moved from lgtm to GitHub Code Scan + 5.16.1 2022-12-04 @@ -2879,4 +2884,4 @@ - + \ No newline at end of file diff --git a/docs/index.html b/docs/index.html index 0cf38f4..aa14068 100644 --- a/docs/index.html +++ b/docs/index.html @@ -170,7 +170,7 @@
systeminformation
 
-
New Version: 5.16.1
+
New Version: 5.16.2
@@ -401,4 +401,4 @@ - + \ No newline at end of file diff --git a/lib/docker.js b/lib/docker.js index c2a152d..9d8ac7a 100644 --- a/lib/docker.js +++ b/lib/docker.js @@ -361,7 +361,12 @@ function docker_calcCPUPercent(cpu_stats, precpu_stats) { if (systemDelta > 0.0 && cpuDelta > 0.0) { // calculate the change for the cpu usage of the container in between readings - cpuPercent = (cpuDelta / systemDelta) * cpu_stats.cpu_usage.percpu_usage.length * 100.0; + if (precpu_stats.online_cpus) { + cpuPercent = (cpuDelta / systemDelta) * precpu_stats.online_cpus * 100.0; + } + else { + cpuPercent = (cpuDelta / systemDelta) * cpu_stats.cpu_usage.percpu_usage.length * 100.0; + } } return cpuPercent; @@ -706,6 +711,7 @@ function dockerVolumes(callback) { } exports.dockerVolumes = dockerVolumes; + function dockerAll(callback) { return new Promise((resolve) => { process.nextTick(() => {