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.reqreboot = ""
self.uptime = ""
self.cpumodel = ""
self.cpusockets = ""
self.cpucores = ""
self.cputhreads = ""
self.cpuspeed = ""
self.cpumodel = "" # getSysCtlInfo
self.cpusockets = "" # getSysCtlInfo
self.cpucores = "" # getSysCtlInfo
self.cputhreads = "" # getSysCtlInfo
self.cpuspeed = "" # getSysCtlInfo
self.cpu = ""
self.wa = ""
self.st = ""
self.us = ""
self.sy = ""
self.load1 = ""
self.load5 = ""
self.load15 = ""
self.ramsize = ""
self.load1 = "" # getSysCtlInfo
self.load5 = "" # getSysCtlInfo
self.load15 = "" # getSysCtlInfo
self.ramsize = "" # getSysCtlInfo
self.ram = ""
self.ramswapsize = ""
self.ramswap = ""
@ -83,12 +83,16 @@ class Update:
result = subprocess.run(command, stdout=subprocess.PIPE)
return result.stdout.decode(encoding="utf-8")
def getCPUInfo(self):
""" Calls commands and sets
self.cpumodel self.cpusockets self.cpucores self.cputhreads self.cpuspeed
def getSysCtlInfo(self):
""" Parses all the things that can be gotten from sysctl and sets all the
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.cputhreads = self.sysctl.get('kern.smp.threads_per_core', "")
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"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):
"""Return the object as a JSON string."""
retval = {
@ -156,7 +167,7 @@ def go():
update.getSysCtlAll()
if( update.sysctl is not None ):
# _logger.debug(f"{update.sysctl}")
update.getCPUInfo()
update.getSysCtlInfo()
else:
_logger.fatal("Failed to get output from sysctl")
_logger.info(f"Done fetching results")