Skip to content

Commit

Permalink
feat: container utilization wasn't counting cpu cores correctly (#267)
Browse files Browse the repository at this point in the history
  • Loading branch information
lirantal authored Aug 12, 2023
1 parent 878bb1f commit 49254eb
Showing 1 changed file with 4 additions and 9 deletions.
13 changes: 4 additions & 9 deletions widgets/containers/containerUtilization.widget.js
Original file line number Diff line number Diff line change
Expand Up @@ -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: [
Expand All @@ -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
Expand Down

0 comments on commit 49254eb

Please sign in to comment.