-
Notifications
You must be signed in to change notification settings - Fork 1
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
Add logical processors to custom field #271
Changes from 2 commits
6391fb5
474f44a
705f696
322797c
2eba583
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -137,13 +137,12 @@ def storage_used_gb(facts): | |
|
||
|
||
def cpu_count(facts): | ||
"""Return the number of CPUs""" | ||
return max( | ||
[ | ||
int(facts.get("ansible_processor_count", 0)), | ||
int(facts.get("ansible_processor_vcpus", 0)), | ||
] | ||
) | ||
"""Return the number of CPU cores""" | ||
return int(facts.get("ansible_processor_count", 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): | ||
|
@@ -200,8 +199,16 @@ def update_results(self, host, data: dict): | |
|
||
if host not in self._total_results: | ||
self._total_results[host] = data | ||
else: | ||
return | ||
|
||
# Ensure we append any custom fields, rather than overwriting them | ||
if 'custom_fields' in data and 'custom_fields' in self._total_results[host]: | ||
combined_custom_fields = {**self._total_results[host]['custom_fields'], **data['custom_fields']} | ||
data['custom_fields'].update(combined_custom_fields) | ||
self._total_results[host].update(data) | ||
return | ||
|
||
self._total_results[host].update(data) | ||
|
||
def v2_runner_on_ok(self, result): | ||
self._plugins.ok_callback(self, result) | ||
|
@@ -222,6 +229,9 @@ def v2_runner_on_ok(self, result): | |
"storage_allocated_gb": storage_allocated_gb(facts), | ||
"storage_used_gb": storage_used_gb(facts), | ||
"cpu_count": cpu_count(facts), | ||
"custom_fields": { | ||
"CPU_LogicalProcessors": cpu_logical_processors(facts) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Aside: how would you feel about making this a default server field? |
||
}, | ||
"operating_system": facts["ansible_distribution"], | ||
"operating_system_version": facts["ansible_distribution_version"], | ||
"cpu_name": cpu_name(facts["ansible_processor"]), | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -167,7 +167,8 @@ $ServerStats = { | |
CPU_Description = $cpu.Description | ||
CPU_Manufacturer = $cpu.Manufacturer | ||
CPU_L2CacheSize = $cpu.L2CacheSize | ||
CPU_L3CacheSize = $cpu.L3CacheSize | ||
CPU_L3CacheSize = $cpu.L3CacheSize | ||
CPU_LogicalProcessors = $cpu.NumberOfLogicalProcessors | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. As we discussed, I was just following the naming conventions I established, but I agree. We should normalize on snake_case There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fixed |
||
CPU_SocketDesignation = $cpu.SocketDesignation | ||
TotalVisible_Memory_GB = $OSTotalVisibleMemory | ||
TotalVirtual_Memory_GB = $OSTotalVirtualMemory | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not able to get this result in my testing, I believe this custom_fields key/value is being overwritten here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The core of the issue was actually here - the
update_results
function was just replacing the entirecustom_fields
key in the result hash. Since CPU stats are taken last, they were overwriting the custom field added here. I've taken the liberty of pushing up a commit to this branch which fixes it - feel free to use or revert at your discretion if you don't agree with the approach.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's weird; thanks for the deep dive into this.