From fc0f7283720291b1cba86c6c6bf2c11210c87ca1 Mon Sep 17 00:00:00 2001 From: samdesmondking Date: Tue, 25 Feb 2025 23:20:18 +1100 Subject: [PATCH 1/2] Updated MS4U to report cpu_count as logical cpu count --- unix/src/machine_stats/__init__.py | 17 +---------------- 1 file changed, 1 insertion(+), 16 deletions(-) diff --git a/unix/src/machine_stats/__init__.py b/unix/src/machine_stats/__init__.py index 6a7a4b8..9c9bb49 100644 --- a/unix/src/machine_stats/__init__.py +++ b/unix/src/machine_stats/__init__.py @@ -104,28 +104,23 @@ def method(*args, **kwargs): return method - def ram_allocated_gb(facts): """Return total memory allocation in GB""" return facts["ansible_memtotal_mb"] / 1024 - def ram_used_gb(facts): """Return used memory in GB""" return (facts["ansible_memtotal_mb"] - facts["ansible_memfree_mb"]) / 1024 - def _size(key, mounts): return sum([item.get(key, 0) for item in mounts]) - def storage_allocated_gb(facts): """Return total storage allocation in GB""" if "ansible_mounts" not in facts: return 0 return _size("size_total", facts["ansible_mounts"]) / 1024 ** 3 - def storage_used_gb(facts): """Return used storage in GB""" if "ansible_mounts" not in facts: @@ -135,17 +130,10 @@ def storage_used_gb(facts): - _size("size_available", facts["ansible_mounts"]) ) / 1024 ** 3 - -def cpu_count(facts): - """Return the number of CPU cores""" - return max(int(facts.get("ansible_processor_count", 0)), - int(facts.get("ansible_processor_cores", 0))) - def cpu_logical_processors(facts): """Return the number of CPU logical processors.""" return int(facts.get("ansible_processor_vcpus", 0)) - def cpu_name(proc): """Return CPU name""" items_count = len(proc) @@ -229,10 +217,7 @@ def v2_runner_on_ok(self, result): "ram_used_gb": ram_used_gb(facts), "storage_allocated_gb": storage_allocated_gb(facts), "storage_used_gb": storage_used_gb(facts), - "cpu_count": cpu_count(facts), - "custom_fields": { - "cpu_logical_processors": cpu_logical_processors(facts) - }, + "cpu_count": cpu_logical_processors(facts), "operating_system": facts["ansible_distribution"], "operating_system_version": facts["ansible_distribution_version"], "cpu_name": cpu_name(facts["ansible_processor"]), From 954b38908a03c2615d3b65321d4e894bab131cec Mon Sep 17 00:00:00 2001 From: samdesmondking Date: Tue, 25 Feb 2025 23:20:54 +1100 Subject: [PATCH 2/2] Updated MS4W to report cpu_count as cpu logical processors --- windows/server_stats.ps1 | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/windows/server_stats.ps1 b/windows/server_stats.ps1 index 35690c4..a2dc1a3 100644 --- a/windows/server_stats.ps1 +++ b/windows/server_stats.ps1 @@ -57,10 +57,6 @@ $ServerStats = { $cpu = $CPUInfo } - $cpu_count = Get-WmiObject Win32_Processor @getWmiObjectParams | - Measure-Object -Property NumberOfCores -Sum | - Select-Object -ExpandProperty Sum - # Get Memory Information. # The data will be shown in a table as MB, rounded to the nearest second decimal. $OSTotalVirtualMemory = [math]::round($OSInfo.TotalVirtualMemorySize / 1MB, 2) @@ -157,7 +153,7 @@ $ServerStats = { ram_used_gb = $OSUsedMemory storage_allocated_gb = $Total_DriveSpaceGB storage_used_gb = $Total_UsedDriveSpaceGB - cpu_count = $cpu_count + cpu_count = $cpu.NumberOfLogicalProcessors operating_system = $OSInfo.Caption operating_system_version = $OSInfo.Version cpu_name = $cpu.Name @@ -168,7 +164,6 @@ $ServerStats = { CPU_Manufacturer = $cpu.Manufacturer CPU_L2CacheSize = $cpu.L2CacheSize CPU_L3CacheSize = $cpu.L3CacheSize - cpu_logical_processors = $cpu.NumberOfLogicalProcessors CPU_SocketDesignation = $cpu.SocketDesignation TotalVisible_Memory_GB = $OSTotalVisibleMemory TotalVirtual_Memory_GB = $OSTotalVirtualMemory