def enable(self): try: self.card_name = self._fetch_card_name() result = utils.get_stdout('%s --version' % NVIDIA_SETTINGS) assert 'NVIDIA' in result, 'nvidia-settings not found.' super(Plugin, self).enable() except Exception as err: log.warning('NVIDIA plugin disabled: %s', err) return self.disable()
def update(self): self.data['card'] = self.card_name or 'Unknown' output = utils.get_stdout(NVIDIA_QUERY) for attr, value in self._parse_attributes(output): self.data[attr] = value # Calculate used and percent memory mem_total = utils.to_int(self.data['totaldedicatedgpumemory'], 0) mem_used = utils.to_int(self.data['useddedicatedgpumemory'], 0) self.data['freededicatedgpumemory'] = mem_total - mem_used self.data['percentuseddedicatedgpumemory'] = utils.percent(mem_used, mem_total, 0) super(Plugin, self).update()
def update(self): self.data['card'] = self.card_name or 'Unknown' output = utils.get_stdout(NVIDIA_QUERY) for attr, value in self._parse_attributes(output): self.data[attr] = value # Calculate used and percent memory mem_total = utils.to_int(self.data['totaldedicatedgpumemory'], 0) mem_used = utils.to_int(self.data['useddedicatedgpumemory'], 0) self.data['freededicatedgpumemory'] = mem_total - mem_used self.data['percentuseddedicatedgpumemory'] = utils.percent( mem_used, mem_total, 0) super(Plugin, self).update()
def _fetch_card_name(self): for line in utils.get_stdout('%s --glxinfo' % NVIDIA_SETTINGS).split('\n'): if line.strip().lower().startswith('opengl renderer string:'): return line.split(':', 1)[1].split('/')[0].strip()