summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLiran Tal <liran.tal@gmail.com>2023-08-12 23:44:28 +0300
committerGitHub <noreply@github.com>2023-08-12 23:44:28 +0300
commit49254eb0e1f73e9e6c0f0ec161e36185ed9b1bec (patch)
tree60d8e23d5b4d06e4df19336bec58b0572d876478
parent878bb1f4db418f59e3204751c5f41cbb86d4cf89 (diff)
feat: container utilization wasn't counting cpu cores correctly (#267)v3.24.0
-rw-r--r--widgets/containers/containerUtilization.widget.js13
1 files changed, 4 insertions, 9 deletions
diff --git a/widgets/containers/containerUtilization.widget.js b/widgets/containers/containerUtilization.widget.js
index c83e77f..a13562b 100644
--- a/widgets/containers/containerUtilization.widget.js
+++ b/widgets/containers/containerUtilization.widget.js
@@ -50,8 +50,7 @@ class myWidget extends baseWidget() {
if (!data.cpu_stats || !data.precpu_stats || !data.cpu_stats.cpu_usage ||
!data.precpu_stats.cpu_usage || !data.cpu_stats.cpu_usage.total_usage ||
!data.precpu_stats.cpu_usage.total_usage ||
- !data.cpu_stats.system_cpu_usage || !data.precpu_stats.system_cpu_usage ||
- !data.cpu_stats.cpu_usage.percpu_usage) {
+ !data.cpu_stats.system_cpu_usage || !data.precpu_stats.system_cpu_usage) {
return this.widget.setData({
titles: ['CPU', 'Memory'],
data: [
@@ -64,15 +63,11 @@ class myWidget extends baseWidget() {
// Calculate CPU usage based on delta from previous measurement
let cpuUsageDelta = data.cpu_stats.cpu_usage.total_usage - data.precpu_stats.cpu_usage.total_usage
let systemUsageDelta = data.cpu_stats.system_cpu_usage - data.precpu_stats.system_cpu_usage
- let cpuCoresAvail = data.cpu_stats.cpu_usage.percpu_usage ? data.cpu_stats.cpu_usage.percpu_usage.length : 0
+ let cpuCoresAvail = data.cpu_stats.online_cpus ? data.cpu_stats.online_cpus : 1
let cpuUsagePercent = 0
- if (systemUsageDelta !== 0 || cpuCoresAvail !== 0) {
- let totalUsage = systemUsageDelta * cpuCoresAvail * 100
- cpuUsagePercent = 0
- if (totalUsage && totalUsage !== 0) {
- cpuUsagePercent = cpuUsageDelta / totalUsage
- }
+ if (systemUsageDelta > 0) {
+ cpuUsagePercent = (cpuUsageDelta / systemUsageDelta) * cpuCoresAvail * 100
}
// Calculate Memory usage