Added jc parsing of sysctl -a

main
Paco Hope 2023-10-04 17:31:33 -04:00
parent 4b559fb57b
commit 338eea67aa
1 changed files with 12 additions and 10 deletions

View File

@ -73,8 +73,8 @@ class Update:
it 20 times and parsing each one, we just call it once, and then parse the it 20 times and parsing each one, we just call it once, and then parse the
various keys that it produces various keys that it produces
""" """
rawtext = subprocess.run(['sysctl', '-a'], subprocess.PIPE) rawtext = subprocess.check_output(['sysctl', '-a'], subprocess.PIPE, text=True )
self.sysctl = jc.parse('sysctl', cmd_output) self.sysctl = jc.parse(parser_mod_name="sysctl", data=rawtext)
def callCommand(self, command=[]): def callCommand(self, command=[]):
"""Given a command and args in a list, run the command and return its """Given a command and args in a list, run the command and return its
@ -87,12 +87,12 @@ class Update:
""" Calls commands and sets """ Calls commands and sets
self.cpumodel self.cpusockets self.cpucores self.cputhreads self.cpuspeed self.cpumodel self.cpusockets self.cpucores self.cputhreads self.cpuspeed
""" """
self.cpusockets = self.callCommand(['sysctl', 'hw.ncpu']).split("\n")[0].split(" ")[1]
self.cpuspeed = self.callCommand(['sysctl', 'hw.clockrate']).split("\n")[0].split(" ")[1] self.cpusockets = self.sysctl.get('hw.ncpu', "garbage")
self.cputhreads = self.callCommand(['sysctl', 'kern.smp.threads_per_core']).split("\n")[0].split(" ")[1] self.cpuspeed = self.sysctl.get('hw.clockrate', "")
self.cpucores = self.callCommand(['sysctl', 'kern.smp.cores']).split("\n")[0].split(" ")[1] self.cputhreads = self.sysctl.get('kern.smp.threads_per_core', "")
self.cpumodel = self.callCommand(['sysctl', 'hw.model']).split("\n")[0].split(" ")[1] self.cpucores = self.sysctl.get('kern.smp.cores', "")
self.cpumodel = base64.b64encode(self.cpumodel.encode()).decode('utf-8') self.cpumodel = base64.b64encode(self.sysctl.get('hw.model', "").encode()).decode('utf-8')
self.logger.debug(f"cpusockets = {self.cpusockets}, cpuspeed = {self.cpuspeed}") self.logger.debug(f"cpusockets = {self.cpusockets}, cpuspeed = {self.cpuspeed}")
self.logger.debug(f"cputhreads = {self.cputhreads}, cpucores = {self.cpucores}") self.logger.debug(f"cputhreads = {self.cputhreads}, cpucores = {self.cpucores}")
@ -155,8 +155,10 @@ def go():
_logger.info(f"Starting to fetch results") _logger.info(f"Starting to fetch results")
update.getSysCtlAll() update.getSysCtlAll()
if( update.sysctl is not None ): if( update.sysctl is not None ):
_logger.info(f"{update.sysctl}") # _logger.debug(f"{update.sysctl}")
update.getCPUInfo() update.getCPUInfo()
else:
_logger.fatal("Failed to get output from sysctl")
_logger.info(f"Done fetching results") _logger.info(f"Done fetching results")
output = update.toJsonString() output = update.toJsonString()
_logger.debug(f"{output}") _logger.debug(f"{output}")