From 4de517f792920f7eec1d6af03db3e9e60bcaac57 Mon Sep 17 00:00:00 2001 From: Paco Hope Date: Wed, 4 Oct 2023 19:51:43 -0400 Subject: [PATCH] switched to all sysctl and added CPU and swap --- src/hetrixtools_freebsd/cli.py | 39 ++++++++++++++++++++++------------ 1 file changed, 25 insertions(+), 14 deletions(-) diff --git a/src/hetrixtools_freebsd/cli.py b/src/hetrixtools_freebsd/cli.py index dfbe18d..17023a9 100644 --- a/src/hetrixtools_freebsd/cli.py +++ b/src/hetrixtools_freebsd/cli.py @@ -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")