mirror of
https://github.com/jumpserver/jumpserver.git
synced 2025-07-14 15:14:43 +00:00
perf: gather facts gpu info
This commit is contained in:
parent
d7bc6bb201
commit
1ad9616b7f
@ -1,3 +1,5 @@
|
|||||||
|
from collections import Counter
|
||||||
|
|
||||||
__all__ = ['FormatAssetInfo']
|
__all__ = ['FormatAssetInfo']
|
||||||
|
|
||||||
|
|
||||||
@ -7,13 +9,37 @@ class FormatAssetInfo:
|
|||||||
self.tp = tp
|
self.tp = tp
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def posix_format(info):
|
def get_cpu_model_count(cpus):
|
||||||
for cpu_model in info.get('cpu_model', []):
|
try:
|
||||||
if cpu_model.endswith('GHz') or cpu_model.startswith("Intel"):
|
models = [cpus[i + 1] + " " + cpus[i + 2] for i in range(0, len(cpus), 3)]
|
||||||
break
|
|
||||||
else:
|
model_counts = Counter(models)
|
||||||
cpu_model = ''
|
|
||||||
info['cpu_model'] = cpu_model[:48]
|
result = ', '.join([f"{model} x{count}" for model, count in model_counts.items()])
|
||||||
|
except Exception as e:
|
||||||
|
print(f"Error processing CPU model list: {e}")
|
||||||
|
result = ''
|
||||||
|
|
||||||
|
return result
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def get_gpu_model_count(gpus):
|
||||||
|
try:
|
||||||
|
model_counts = Counter(gpus)
|
||||||
|
|
||||||
|
result = ', '.join([f"{model} x{count}" for model, count in model_counts.items()])
|
||||||
|
except Exception as e:
|
||||||
|
print(f"Error processing GPU model list: {e}")
|
||||||
|
result = ''
|
||||||
|
|
||||||
|
return result
|
||||||
|
|
||||||
|
def posix_format(self, info):
|
||||||
|
cpus = self.get_cpu_model_count(info.get('cpu_model', []))
|
||||||
|
gpus = self.get_gpu_model_count(info.get('gpu_model', []))
|
||||||
|
|
||||||
|
info['gpu_model'] = gpus
|
||||||
|
info['cpu_model'] = cpus
|
||||||
info['cpu_count'] = info.get('cpu_count', 0)
|
info['cpu_count'] = info.get('cpu_count', 0)
|
||||||
return info
|
return info
|
||||||
|
|
||||||
|
@ -23,5 +23,16 @@
|
|||||||
arch: "{{ ansible_architecture }}"
|
arch: "{{ ansible_architecture }}"
|
||||||
kernel: "{{ ansible_kernel }}"
|
kernel: "{{ ansible_kernel }}"
|
||||||
|
|
||||||
|
|
||||||
|
- name: Get GPU info with nvidia-smi
|
||||||
|
shell: |
|
||||||
|
nvidia-smi --query-gpu=name,memory.total,driver_version --format=csv,noheader,nounits
|
||||||
|
register: gpu_info
|
||||||
|
ignore_errors: yes
|
||||||
|
|
||||||
|
- name: Merge GPU info into final info
|
||||||
|
set_fact:
|
||||||
|
info: "{{ info | combine({'gpu_model': gpu_info.stdout_lines | default([])}) }}"
|
||||||
|
|
||||||
- debug:
|
- debug:
|
||||||
var: info
|
var: info
|
||||||
|
@ -6,7 +6,7 @@ class HostGatheredInfoSerializer(serializers.Serializer):
|
|||||||
vendor = serializers.CharField(max_length=64, required=False, allow_blank=True, label=_('Vendor'))
|
vendor = serializers.CharField(max_length=64, required=False, allow_blank=True, label=_('Vendor'))
|
||||||
model = serializers.CharField(max_length=54, required=False, allow_blank=True, label=_('Model'))
|
model = serializers.CharField(max_length=54, required=False, allow_blank=True, label=_('Model'))
|
||||||
sn = serializers.CharField(max_length=128, required=False, allow_blank=True, label=_('Serial number'))
|
sn = serializers.CharField(max_length=128, required=False, allow_blank=True, label=_('Serial number'))
|
||||||
cpu_model = serializers.CharField(max_length=64, allow_blank=True, required=False, label=_('CPU model'))
|
cpu_model = serializers.CharField(allow_blank=True, required=False, label=_('CPU model'))
|
||||||
cpu_count = serializers.CharField(max_length=64, required=False, allow_blank=True, label=_('CPU count'))
|
cpu_count = serializers.CharField(max_length=64, required=False, allow_blank=True, label=_('CPU count'))
|
||||||
cpu_cores = serializers.CharField(max_length=64, required=False, allow_blank=True, label=_('CPU cores'))
|
cpu_cores = serializers.CharField(max_length=64, required=False, allow_blank=True, label=_('CPU cores'))
|
||||||
cpu_vcpus = serializers.CharField(max_length=64, required=False, allow_blank=True, label=_('CPU vcpus'))
|
cpu_vcpus = serializers.CharField(max_length=64, required=False, allow_blank=True, label=_('CPU vcpus'))
|
||||||
@ -17,6 +17,8 @@ class HostGatheredInfoSerializer(serializers.Serializer):
|
|||||||
distribution_version = serializers.CharField(max_length=16, allow_blank=True, required=False, label=_('OS version'))
|
distribution_version = serializers.CharField(max_length=16, allow_blank=True, required=False, label=_('OS version'))
|
||||||
arch = serializers.CharField(max_length=16, allow_blank=True, required=False, label=_('OS arch'))
|
arch = serializers.CharField(max_length=16, allow_blank=True, required=False, label=_('OS arch'))
|
||||||
|
|
||||||
|
gpu_model = serializers.CharField(allow_blank=True, required=False, label=_('GPU model'))
|
||||||
|
|
||||||
|
|
||||||
category_gathered_serializer_map = {
|
category_gathered_serializer_map = {
|
||||||
'host': HostGatheredInfoSerializer,
|
'host': HostGatheredInfoSerializer,
|
||||||
|
Loading…
Reference in New Issue
Block a user