added base64 and json
parent
db20d179c6
commit
0b8459b276
|
@ -9,6 +9,8 @@ import argparse
|
||||||
import logging
|
import logging
|
||||||
import sys
|
import sys
|
||||||
import subprocess
|
import subprocess
|
||||||
|
import base64
|
||||||
|
import json
|
||||||
|
|
||||||
from hetrixtools_freebsd import __version__
|
from hetrixtools_freebsd import __version__
|
||||||
|
|
||||||
|
@ -75,9 +77,65 @@ 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
|
||||||
"""
|
"""
|
||||||
ncpu = self.callCommand(['sysctl', 'hw.ncpu']).split("\n")[0].split(" ")[1]
|
self.cpusockets = self.callCommand(['sysctl', 'hw.ncpu']).split("\n")[0].split(" ")[1]
|
||||||
cpuspeed = self.callCommand(['sysctl', 'hw.clockrate']).split("\n")[0].split(" ")[1]
|
self.cpuspeed = self.callCommand(['sysctl', 'hw.clockrate']).split("\n")[0].split(" ")[1]
|
||||||
print(f"ncpu = {ncpu}, cpuspeed = {cpuspeed}")
|
self.cputhreads = self.callCommand(['sysctl', 'kern.smp.threads_per_core']).split("\n")[0].split(" ")[1]
|
||||||
|
self.cpucores = self.callCommand(['sysctl', 'kern.smp.cores']).split("\n")[0].split(" ")[1]
|
||||||
|
self.cpumodel = self.callCommand(['sysctl', 'hw.model']).split("\n")[0].split(" ")[1]
|
||||||
|
self.cpumodel = base64.b64encode(self.cpumodel.encode()).decode('utf-8')
|
||||||
|
|
||||||
|
print(f"cpusockets = {self.cpusockets}, cpuspeed = {self.cpuspeed}")
|
||||||
|
print(f"cputhreads = {self.cputhreads}, cpucores = {self.cpucores}")
|
||||||
|
print(f"cpumodel = {self.cpumodel}")
|
||||||
|
|
||||||
|
def toJsonString(self):
|
||||||
|
"""Return the object as a JSON string."""
|
||||||
|
retval = {
|
||||||
|
version : self.version ,
|
||||||
|
SID : self.SID ,
|
||||||
|
agent : self.agent ,
|
||||||
|
user : self.user ,
|
||||||
|
os : self.os ,
|
||||||
|
kernel : self.kernel ,
|
||||||
|
hostname : self.hostname ,
|
||||||
|
time : self.time ,
|
||||||
|
reqreboot : self.reqreboot ,
|
||||||
|
uptime : self.uptime ,
|
||||||
|
cpumodel : self.cpumodel ,
|
||||||
|
cpusockets : self.cpusockets ,
|
||||||
|
cpucores : self.cpucores ,
|
||||||
|
cputhreads : self.cputhreads ,
|
||||||
|
cpuspeed : self.cpuspeed ,
|
||||||
|
cpu : self.cpu ,
|
||||||
|
wa : self.wa ,
|
||||||
|
st : self.st ,
|
||||||
|
us : self.us ,
|
||||||
|
sy : self.sy ,
|
||||||
|
load1 : self.load1 ,
|
||||||
|
load5 : self.load5 ,
|
||||||
|
load15 : self.load15 ,
|
||||||
|
ramsize : self.ramsize ,
|
||||||
|
ram : self.ram ,
|
||||||
|
ramswapsize : self.ramswapsize,
|
||||||
|
ramswap : self.ramswap ,
|
||||||
|
rambuff : self.rambuff ,
|
||||||
|
ramcache : self.ramcache ,
|
||||||
|
disks : self.disks ,
|
||||||
|
inodes : self.inodes ,
|
||||||
|
iops : self.iops ,
|
||||||
|
raid : self.raid ,
|
||||||
|
dh : self.dh ,
|
||||||
|
nics : self.nics ,
|
||||||
|
ipv4 : self.ipv4 ,
|
||||||
|
ipv6 : self.ipv6 ,
|
||||||
|
conn : self.conn ,
|
||||||
|
temp : self.temp ,
|
||||||
|
serv : self.serv ,
|
||||||
|
cust : self.cust ,
|
||||||
|
rps1 : self.rps1 ,
|
||||||
|
rps2 : self.rps2 ,
|
||||||
|
}
|
||||||
|
return json.dumps(retval)
|
||||||
|
|
||||||
# ---- Python API ----
|
# ---- Python API ----
|
||||||
|
|
||||||
|
@ -85,6 +143,8 @@ def go():
|
||||||
"""Run the command."""
|
"""Run the command."""
|
||||||
update = Update()
|
update = Update()
|
||||||
update.getCPUInfo()
|
update.getCPUInfo()
|
||||||
|
output = update.toJsonString()
|
||||||
|
print(f"{output}")
|
||||||
|
|
||||||
def parse_args(args):
|
def parse_args(args):
|
||||||
"""Parse command line parameters
|
"""Parse command line parameters
|
||||||
|
|
Loading…
Reference in New Issue