switched to all sysctl and added CPU and swap

main
Paco Hope 2023-10-04 19:51:43 -04:00
parent 338eea67aa
commit 4de517f792
1 changed files with 25 additions and 14 deletions

View File

@ -33,20 +33,20 @@ class Update:
self.time = "" self.time = ""
self.reqreboot = "" self.reqreboot = ""
self.uptime = "" self.uptime = ""
self.cpumodel = "" self.cpumodel = "" # getSysCtlInfo
self.cpusockets = "" self.cpusockets = "" # getSysCtlInfo
self.cpucores = "" self.cpucores = "" # getSysCtlInfo
self.cputhreads = "" self.cputhreads = "" # getSysCtlInfo
self.cpuspeed = "" self.cpuspeed = "" # getSysCtlInfo
self.cpu = "" self.cpu = ""
self.wa = "" self.wa = ""
self.st = "" self.st = ""
self.us = "" self.us = ""
self.sy = "" self.sy = ""
self.load1 = "" self.load1 = "" # getSysCtlInfo
self.load5 = "" self.load5 = "" # getSysCtlInfo
self.load15 = "" self.load15 = "" # getSysCtlInfo
self.ramsize = "" self.ramsize = "" # getSysCtlInfo
self.ram = "" self.ram = ""
self.ramswapsize = "" self.ramswapsize = ""
self.ramswap = "" self.ramswap = ""
@ -83,12 +83,16 @@ class Update:
result = subprocess.run(command, stdout=subprocess.PIPE) result = subprocess.run(command, stdout=subprocess.PIPE)
return result.stdout.decode(encoding="utf-8") return result.stdout.decode(encoding="utf-8")
def getCPUInfo(self): def getSysCtlInfo(self):
""" Calls commands and sets """ Parses all the things that can be gotten from sysctl and sets all the
self.cpumodel self.cpusockets self.cpucores self.cputhreads self.cpuspeed values in the data structure. Other values can come from other places.
self.cpumodel self.cpusockets self.cpucores self.cputhreads self.cpuspeed
""" """
self.cpusockets = self.sysctl.get('hw.ncpu', "garbage") # CPU stuff first
self.cpusockets = self.sysctl.get('hw.ncpu', "")
self.cpuspeed = self.sysctl.get('hw.clockrate', "") self.cpuspeed = self.sysctl.get('hw.clockrate', "")
self.cputhreads = self.sysctl.get('kern.smp.threads_per_core', "") self.cputhreads = self.sysctl.get('kern.smp.threads_per_core', "")
self.cpucores = self.sysctl.get('kern.smp.cores', "") self.cpucores = self.sysctl.get('kern.smp.cores', "")
@ -98,6 +102,13 @@ class Update:
self.logger.debug(f"cputhreads = {self.cputhreads}, cpucores = {self.cpucores}") self.logger.debug(f"cputhreads = {self.cputhreads}, cpucores = {self.cpucores}")
self.logger.debug(f"cpumodel = {self.cpumodel}") self.logger.debug(f"cpumodel = {self.cpumodel}")
# Uptime
(self.load1, self.load5, self.load15) = self.sysctl.get('vm.loadavg').split(" ")[1:4]
# Memory and Swap
self.ramsize = int(self.sysctl.get('hw.physmem', 0)) / 1024
self.ramswapsize = int(self.sysctl.get('vm.swap_total', 0)) / 1024
def toJsonString(self): def toJsonString(self):
"""Return the object as a JSON string.""" """Return the object as a JSON string."""
retval = { retval = {
@ -156,7 +167,7 @@ def go():
update.getSysCtlAll() update.getSysCtlAll()
if( update.sysctl is not None ): if( update.sysctl is not None ):
# _logger.debug(f"{update.sysctl}") # _logger.debug(f"{update.sysctl}")
update.getCPUInfo() update.getSysCtlInfo()
else: else:
_logger.fatal("Failed to get output from sysctl") _logger.fatal("Failed to get output from sysctl")
_logger.info(f"Done fetching results") _logger.info(f"Done fetching results")