diff --git a/glances/exports/glances_statsd.py b/glances/exports/glances_statsd.py index f9740f4b1fe9feb54b0ea62697fe8d9581ea8e5a..4ab88e9c222059854f564e1de59f850355f8fb6f 100644 --- a/glances/exports/glances_statsd.py +++ b/glances/exports/glances_statsd.py @@ -76,18 +76,19 @@ class Export(GlancesExport): stat_name = '{}.{}'.format(name, columns[i]) stat_value = points[i] try: - self.client.gauge(self._normalize(stat_name), + self.client.gauge(normalize(stat_name), stat_value) except Exception as e: logger.error("Can not export stats to Statsd (%s)" % e) logger.debug("Export {} stats to Statsd".format(name)) - def _normalize(self, name): - """Normalize name for the Statsd convention""" - # Name should not contain some specials chars (issue #1068) - ret = name.replace(':', '') - ret = ret.replace('%', '') - ret = ret.replace(' ', '_') +def normalize(name): + """Normalize name for the Statsd convention""" - return ret + # Name should not contain some specials chars (issue #1068) + ret = name.replace(':', '') + ret = ret.replace('%', '') + ret = ret.replace(' ', '_') + + return ret diff --git a/glances/plugins/glances_gpu.py b/glances/plugins/glances_gpu.py index af67620f34946f2fb5820a6b48d5e8f90ec2418d..d7eba7f3634dd7f5a56eb1efbc5d1c4730945186 100644 --- a/glances/plugins/glances_gpu.py +++ b/glances/plugins/glances_gpu.py @@ -62,7 +62,7 @@ class Plugin(GlancesPlugin): try: pynvml.nvmlInit() - self.device_handles = self.get_device_handles() + self.device_handles = get_device_handles() self.nvml_ready = True except Exception: logger.debug("pynvml could not be initialized.") @@ -124,7 +124,7 @@ class Plugin(GlancesPlugin): return True - def msg_curse(self, args=None): + def msg_curse(self, args=None, max_width=None): """Return the dict to display in the curse interface.""" # Init the return message ret = [] @@ -209,12 +209,6 @@ class Plugin(GlancesPlugin): return ret - def get_device_handles(self): - """ - Returns a list of NVML device handles, one per device. Can throw NVMLError. - """ - return [pynvml.nvmlDeviceGetHandleByIndex(i) for i in range(pynvml.nvmlDeviceGetCount())] - def get_device_stats(self): """Get GPU stats""" stats = [] @@ -226,37 +220,15 @@ class Plugin(GlancesPlugin): # GPU id (for multiple GPU, start at 0) device_stats['gpu_id'] = index # GPU name - device_stats['name'] = self.get_device_name(device_handle) + device_stats['name'] = get_device_name(device_handle) # Memory consumption in % (not available on all GPU) - device_stats['mem'] = self.get_mem(device_handle) + device_stats['mem'] = get_mem(device_handle) # Processor consumption in % - device_stats['proc'] = self.get_proc(device_handle) + device_stats['proc'] = get_proc(device_handle) stats.append(device_stats) return stats - def get_device_name(self, device_handle): - """Get GPU device name""" - try: - return pynvml.nvmlDeviceGetName(device_handle) - except pynvml.NVMlError: - return "NVIDIA" - - def get_mem(self, device_handle): - """Get GPU device memory consumption in percent""" - try: - memory_info = pynvml.nvmlDeviceGetMemoryInfo(device_handle) - return memory_info.used * 100.0 / memory_info.total - except pynvml.NVMLError: - return None - - def get_proc(self, device_handle): - """Get GPU device CPU consumption in percent""" - try: - return pynvml.nvmlDeviceGetUtilizationRates(device_handle).gpu - except pynvml.NVMLError: - return None - def exit(self): """Overwrite the exit method to close the GPU API""" if self.nvml_ready: @@ -267,3 +239,35 @@ class Plugin(GlancesPlugin): # Call the father exit method super(Plugin, self).exit() + + +def get_device_handles(): + """ + Returns a list of NVML device handles, one per device. Can throw NVMLError. + """ + return [pynvml.nvmlDeviceGetHandleByIndex(i) for i in range(pynvml.nvmlDeviceGetCount())] + + +def get_device_name(device_handle): + """Get GPU device name""" + try: + return pynvml.nvmlDeviceGetName(device_handle) + except pynvml.NVMlError: + return "NVIDIA" + + +def get_mem(device_handle): + """Get GPU device memory consumption in percent""" + try: + memory_info = pynvml.nvmlDeviceGetMemoryInfo(device_handle) + return memory_info.used * 100.0 / memory_info.total + except pynvml.NVMLError: + return None + + +def get_proc(device_handle): + """Get GPU device CPU consumption in percent""" + try: + return pynvml.nvmlDeviceGetUtilizationRates(device_handle).gpu + except pynvml.NVMLError: + return None diff --git a/glances/plugins/glances_ports.py b/glances/plugins/glances_ports.py index 67c392e1dc8d2b32c4453ddf4e45ee53bdc4fc32..55cd4d95b51bdbe4c57288678d00a120307285be 100644 --- a/glances/plugins/glances_ports.py +++ b/glances/plugins/glances_ports.py @@ -107,7 +107,7 @@ class Plugin(GlancesPlugin): return 'OK' - def msg_curse(self, args=None): + def msg_curse(self, args=None, max_width=None): """Return the dict to display in the curse interface.""" # Init the return message # Only process if stats exist and display plugin enable...