nvidia-smi: not loop mode (#7372)
* add non loop mode
Ilya Mashchenko committed
Nov 28, 2019 at 11:54 UTC
d8ee63fcc9d9b46a59d6ee7f5dfb56e06122fbd0
3 files changed
+24
-7
collectors/python.d.plugin/nvidia_smi/README.md
+4
-1
@@ -16,6 +16,8 @@ This module monitors the `nvidia-smi` cli tool.
16
17
- Make sure `netdata` user can execute `/usr/bin/nvidia-smi` or wherever your binary is.
18
19
+- If `nvidia-smi` process [is not killed after netdata restart](https://github.com/netdata/netdata/issues/7143) you need to off `loop_mode`.
20
+
21
- `poll_seconds` is how often in seconds the tool is polled for as an integer.
22
23
It produces:
@@ -36,7 +38,8 @@ It produces:
38
Sample:
39
40
```yaml
39
-poll_seconds: 1
41
+loop_mode : yes
42
+poll_seconds : 1
43
```
44
45
[](<>)
collectors/python.d.plugin/nvidia_smi/nvidia_smi.chart.py
+18
-5
@@ -7,12 +7,11 @@ import subprocess
7
import threading
8
import xml.etree.ElementTree as et
9
10
-from bases.collection import find_binary
10
from bases.FrameworkServices.SimpleService import SimpleService
11
+from bases.collection import find_binary
12
13
disabled_by_default = True
14
15
-
15
NVIDIA_SMI = 'nvidia-smi'
16
17
BAD_VALUE = 'N/A'
@@ -76,7 +75,8 @@ def gpu_charts(gpu):
75
]
76
},
77
ENCODER_UTIL: {
79
- 'options': [None, 'Encoder/Decoder Utilization', 'percentage', fam, 'nvidia_smi.encoder_utilization', 'line'],
78
+ 'options': [None, 'Encoder/Decoder Utilization', 'percentage', fam, 'nvidia_smi.encoder_utilization',
79
+ 'line'],
80
'lines': [
81
['encoder_util', 'encoder'],
82
['decoder_util', 'decoder'],
@@ -212,6 +212,7 @@ def handle_attr_error(method):
212
return method(*args, **kwargs)
213
except AttributeError:
214
return None
215
+
216
return on_call
217
218
@@ -221,6 +222,7 @@ def handle_value_error(method):
222
return method(*args, **kwargs)
223
except ValueError:
224
return None
225
+
226
return on_call
227
228
@@ -342,10 +344,11 @@ class Service(SimpleService):
344
super(Service, self).__init__(configuration=configuration, name=name)
345
self.order = list()
346
self.definitions = dict()
347
+ self.loop_mode = configuration.get('loop_mode', True)
348
poll = int(configuration.get('poll_seconds', 1))
349
self.poller = NvidiaSMIPoller(poll)
350
348
- def get_data(self):
351
+ def get_data_loop_mode(self):
352
if not self.poller.is_started():
353
self.poller.start()
354
@@ -353,7 +356,17 @@ class Service(SimpleService):
356
self.debug('poller is off')
357
return None
358
356
- last_data = self.poller.data()
359
+ return self.poller.data()
360
+
361
+ def get_data_normal_mode(self):
362
+ return self.poller.run_once()
363
+
364
+ def get_data(self):
365
+ if self.loop_mode:
366
+ last_data = self.get_data_loop_mode()
367
+ else:
368
+ last_data = self.get_data_normal_mode()
369
+
370
if not last_data:
371
return None
372
collectors/python.d.plugin/nvidia_smi/nvidia_smi.conf
+2
-1
@@ -61,6 +61,7 @@
61
#
62
# Additionally to the above, example also supports the following:
63
#
64
-# poll_seconds: SECONDS # default is 1. Sets the frequency of seconds the nvidia-smi tool is polled.
64
+# loop_mode: yes/no # default is yes. If set to yes `nvidia-smi` is executed in a separate thread using `-l` option.
65
+# poll_seconds: SECONDS # default is 1. Sets the frequency of seconds the nvidia-smi tool is polled in loop mode.
66
#
67
# ----------------------------------------------------------------------