From e74c70b3046e539f57c1dd9dfd77c3b03a41d15c Mon Sep 17 00:00:00 2001 From: usmannasir Date: Sat, 12 Apr 2025 22:17:52 +0500 Subject: [PATCH] show n8n version --- plogical/DockerSites.py | 12 ++++++++++-- .../static/websiteFunctions/DockerContainers.js | 2 +- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/plogical/DockerSites.py b/plogical/DockerSites.py index f54888442..ec49ee1ed 100644 --- a/plogical/DockerSites.py +++ b/plogical/DockerSites.py @@ -737,6 +737,14 @@ services: # Fetch container stats stats = container.stats(stream=False) + # Calculate CPU percentage properly + cpu_count = len(stats["cpu_stats"]["cpu_usage"]["percpu_usage"]) + cpu_delta = float(stats["cpu_stats"]["cpu_usage"]["total_usage"]) - float(stats["precpu_stats"]["cpu_usage"]["total_usage"]) + system_delta = float(stats["cpu_stats"]["system_cpu_usage"]) - float(stats["precpu_stats"]["system_cpu_usage"]) + cpu_usage = 0.0 + if system_delta > 0.0: + cpu_usage = (cpu_delta / system_delta) * 100.0 * cpu_count + dic = { 'id': container.short_id, 'name': container.name, @@ -744,8 +752,8 @@ services: 'volumes': container.attrs['HostConfig']['Binds'] if 'HostConfig' in container.attrs else [], 'logs_50': container.logs(tail=50).decode('utf-8'), 'ports': container.attrs['HostConfig']['PortBindings'] if 'HostConfig' in container.attrs else {}, - 'memory': stats['memory_stats']['usage'], - 'cpu' : stats['cpu_stats']['cpu_usage']['total_usage'] + 'memory_usage': stats['memory_stats'].get('usage', 0), + 'cpu_usage': cpu_usage # Now sending the properly calculated percentage } return 1, dic diff --git a/websiteFunctions/static/websiteFunctions/DockerContainers.js b/websiteFunctions/static/websiteFunctions/DockerContainers.js index 247db9e7f..6438836be 100644 --- a/websiteFunctions/static/websiteFunctions/DockerContainers.js +++ b/websiteFunctions/static/websiteFunctions/DockerContainers.js @@ -98,7 +98,7 @@ app.controller('ListDockersitecontainer', function ($scope, $http) { var memoryBytes = containerInfo.memory_usage; $scope.ContainerList[i].memoryUsage = formatBytes(memoryBytes); $scope.ContainerList[i].memoryUsagePercent = (memoryBytes / (1024 * 1024 * 1024)) * 100; - $scope.ContainerList[i].cpuUsagePercent = (containerInfo.cpu_usage / 10000000000) * 100; + $scope.ContainerList[i].cpuUsagePercent = containerInfo.cpu_usage; // Network & Ports $scope.ContainerList[i].ports = containerInfo.ports;