From 52ecd2dc531a05c8fe37c53bb83d192ea78a8ecf Mon Sep 17 00:00:00 2001 From: Swapnil Date: Mon, 24 Jun 2024 20:06:21 +0530 Subject: [PATCH] Use parsed data in cpu count --- agent.py | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/agent.py b/agent.py index 23cc027..978ec7a 100644 --- a/agent.py +++ b/agent.py @@ -101,15 +101,11 @@ class ServerData: def get_cpu_count(self): cpu_count = 0 - if os.path.isfile('/usr/sbin/dmidecode'): - try: - output = subprocess.check_output(['sudo', '/usr/sbin/dmidecode', '-t', 'processor']).decode('utf-8') - core_match = re.search(r'Core Count: (\d+)', output) - thread_match = re.search(r'Thread Count: (\d+)', output) - if core_match and thread_match: - cpu_count = int(core_match.group(1)) * int(thread_match.group(1)) - except subprocess.CalledProcessError: - pass + for section in self.dmidecode_data: + if section['DMIType'] == 4: # 4 corresponds to processor + core_count = int(section.get('Core Count', '0')) + thread_count = int(section.get('Thread Count', '0')) + cpu_count = core_count * thread_count if cpu_count == 0: with open('/proc/cpuinfo', 'r') as f: cpuinfo = f.read()