Skip to content

Commit

Permalink
Raspberry PI - CPU info is not correct #2616
Browse files Browse the repository at this point in the history
  • Loading branch information
nicolargo committed Jun 1, 2024
1 parent b2e5cb5 commit 65f84fd
Showing 1 changed file with 13 additions and 6 deletions.
19 changes: 13 additions & 6 deletions glances/cpu_percent.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ def __init__(self, cached_timer_cpu=3):
self.percpu_percent = []

# Get CPU name
self.__get_cpu_name()
self.cpu_info['cpu_name'] = self.__get_cpu_name()

# cached_timer_cpu is the minimum time interval between stats updates
# since last update is passed (will retrieve old cached info instead)
Expand Down Expand Up @@ -71,12 +71,19 @@ def get_info(self):

def __get_cpu_name(self):
# Get the CPU name once from the /proc/cpuinfo file
# TODO: Multisystem...
# Linux/Unix only
# Read the first line with the "model name"
ret = 'CPU'
try:
self.cpu_info['cpu_name'] = open('/proc/cpuinfo').readlines()[4].split(':')[1].strip()
except (FileNotFoundError, PermissionError, IndexError, KeyError, AttributeError):
self.cpu_info['cpu_name'] = 'CPU'
return self.cpu_info['cpu_name']
cpuinfo_file = open('/proc/cpuinfo').readlines()
except (FileNotFoundError, PermissionError):
pass
else:
for line in cpuinfo_file:
if line.startswith('model name'):
ret = line.split(':')[1].strip()
break
return ret

def __get_cpu(self):
"""Update and/or return the CPU using the psutil library."""
Expand Down

0 comments on commit 65f84fd

Please sign in to comment.