Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sam/logical cpu count #275

Merged
merged 2 commits into from
Feb 26, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 1 addition & 16 deletions unix/src/machine_stats/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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)
Expand Down Expand Up @@ -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"]),
Expand Down
7 changes: 1 addition & 6 deletions windows/server_stats.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down