python.d/nvidia_smi: fix gpu data filtering (#10312)
Ilya Mashchenko committed
Dec 3, 2020 at 13:20 UTC
fae19246df3c8768c8207372d46828a9afe788d4
1 file changed
+13
-6
collectors/python.d.plugin/nvidia_smi/nvidia_smi.chart.py
+13
-6
@@ -18,8 +18,6 @@ disabled_by_default = True
18
19
NVIDIA_SMI = 'nvidia-smi'
20
21
-BAD_VALUE = 'N/A'
22
-
21
EMPTY_ROW = ''
22
EMPTY_ROW_LIMIT = 500
23
POLLER_BREAK_ROW = '</nvidia_smi_log>'
@@ -423,9 +421,7 @@ class GPU:
421
data[key] = p['used_memory']
422
data['user_num'] = len(users)
423
426
- return dict(
427
- ('gpu{0}_{1}'.format(self.num, k), v) for k, v in data.items() if v is not None and v != BAD_VALUE
428
- )
424
+ return dict(('gpu{0}_{1}'.format(self.num, k), v) for k, v in data.items())
425
426
427
class Service(SimpleService):
@@ -467,7 +463,10 @@ class Service(SimpleService):
463
data = dict()
464
for idx, root in enumerate(parsed.findall('gpu')):
465
gpu = GPU(idx, root, self.exclude_zero_memory_users)
470
- data.update(gpu.data())
466
+ gpu_data = gpu.data()
467
+ # self.debug(gpu_data)
468
+ gpu_data = dict((k, v) for k, v in gpu_data.items() if is_gpu_data_value_valid(v))
469
+ data.update(gpu_data)
470
self.update_processes_mem_chart(gpu)
471
self.update_processes_user_mem_chart(gpu)
472
@@ -541,3 +540,11 @@ class Service(SimpleService):
540
order, charts = gpu_charts(GPU(idx, root))
541
self.order.extend(order)
542
self.definitions.update(charts)
543
+
544
+
545
+def is_gpu_data_value_valid(value):
546
+ try:
547
+ int(value)
548
+ except (TypeError, ValueError):
549
+ return False
550
+ return True