Skip to content

Commit 6ad4d40

Browse files
Add ability to report the number of logical processors (#271)
* Add logical processors to custom field * Updated the update_results function to append any custom fields rather than overwriting them * fix: flake to load all dependencies as outlined in contributing.md * fix: bug in cpu_count where it may only retrieve sockets * chore: Rename custom field to be consistent with the api --------- Co-authored-by: samdesmondking <samuel-king@live.com.au>
1 parent b9c394b commit 6ad4d40

File tree

3 files changed

+23
-9
lines changed

3 files changed

+23
-9
lines changed

unix/flake.nix

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@
3232
postVenvCreation = ''
3333
unset SOURCE_DATE_EPOCH
3434
pip install -r ./requirements.txt
35+
pip install -r dev-requirements.txt
36+
pip install -e .
3537
'';
3638

3739
# Now we can execute any commands within the virtual environment.

unix/src/machine_stats/__init__.py

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -137,13 +137,13 @@ def storage_used_gb(facts):
137137

138138

139139
def cpu_count(facts):
140-
"""Return the number of CPUs"""
141-
return max(
142-
[
143-
int(facts.get("ansible_processor_count", 0)),
144-
int(facts.get("ansible_processor_vcpus", 0)),
145-
]
146-
)
140+
"""Return the number of CPU cores"""
141+
return max(int(facts.get("ansible_processor_count", 0)),
142+
int(facts.get("ansible_processor_cores", 0)))
143+
144+
def cpu_logical_processors(facts):
145+
"""Return the number of CPU logical processors."""
146+
return int(facts.get("ansible_processor_vcpus", 0))
147147

148148

149149
def cpu_name(proc):
@@ -200,8 +200,16 @@ def update_results(self, host, data: dict):
200200

201201
if host not in self._total_results:
202202
self._total_results[host] = data
203-
else:
203+
return
204+
205+
# Ensure we append any custom fields, rather than overwriting them
206+
if 'custom_fields' in data and 'custom_fields' in self._total_results[host]:
207+
combined_custom_fields = {**self._total_results[host]['custom_fields'], **data['custom_fields']}
208+
data['custom_fields'].update(combined_custom_fields)
204209
self._total_results[host].update(data)
210+
return
211+
212+
self._total_results[host].update(data)
205213

206214
def v2_runner_on_ok(self, result):
207215
self._plugins.ok_callback(self, result)
@@ -222,6 +230,9 @@ def v2_runner_on_ok(self, result):
222230
"storage_allocated_gb": storage_allocated_gb(facts),
223231
"storage_used_gb": storage_used_gb(facts),
224232
"cpu_count": cpu_count(facts),
233+
"custom_fields": {
234+
"cpu_logical_processors": cpu_logical_processors(facts)
235+
},
225236
"operating_system": facts["ansible_distribution"],
226237
"operating_system_version": facts["ansible_distribution_version"],
227238
"cpu_name": cpu_name(facts["ansible_processor"]),

windows/server_stats.ps1

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,8 @@ $ServerStats = {
167167
CPU_Description = $cpu.Description
168168
CPU_Manufacturer = $cpu.Manufacturer
169169
CPU_L2CacheSize = $cpu.L2CacheSize
170-
CPU_L3CacheSize = $cpu.L3CacheSize
170+
CPU_L3CacheSize = $cpu.L3CacheSize
171+
cpu_logical_processors = $cpu.NumberOfLogicalProcessors
171172
CPU_SocketDesignation = $cpu.SocketDesignation
172173
TotalVisible_Memory_GB = $OSTotalVisibleMemory
173174
TotalVirtual_Memory_GB = $OSTotalVirtualMemory

0 commit comments

Comments
 (0)