added hostname logging and a generalized get dta function for braiins OS

This commit is contained in:
UpstreamData
2022-05-05 10:35:47 -06:00
parent af37850289
commit e6ea8d3e16
2 changed files with 104 additions and 1 deletions

View File

@@ -21,6 +21,7 @@ class BaseMiner:
self.api_type = None
self.model = None
self.light = None
self.hostname = None
self.nominal_chips = 1
async def _get_ssh_connection(self) -> asyncssh.connect:

View File

@@ -90,13 +90,16 @@ class BOSMiner(BaseMiner):
:return: The hostname of the miner as a string or "?"
"""
if self.hostname:
return self.hostname
try:
async with (await self._get_ssh_connection()) as conn:
if conn is not None:
data = await conn.run("cat /proc/sys/kernel/hostname")
host = data.stdout.strip()
logging.debug(f"Found hostname for {self.ip}: {host}")
return host
self.hostname = host
return self.hostname
else:
logging.warning(f"Failed to get hostname for miner: {self}")
return "?"
@@ -222,3 +225,102 @@ class BOSMiner(BaseMiner):
bad += 1
if not bad > 0:
return str(self.ip)
async def get_data(self):
data = {
"IP": str(self.ip),
"Model": "Unknown",
"Hostname": "Unknown",
"Hashrate": 0,
"Temperature": 0,
"Pool User": "Unknown",
"Wattage": 0,
"Split": 0,
"Pool 1": "Unknown",
"Pool 1 User": "Unknown",
"Pool 2": "",
"Pool 2 User": "",
}
model = await self.get_model()
hostname = await self.get_hostname()
miner_data = await self.api.multicommand(
"summary", "temps", "tunerstatus", "pools"
)
summary = miner_data.get("summary")[0]
temps = miner_data.get("temps")[0]
tunerstatus = miner_data.get("tunerstatus")[0]
pools = miner_data.get("pools")[0]
if model:
data["Model"] = model
if hostname:
data["Hostname"] = hostname
if summary:
hr = summary.get("SUMMARY")
if hr:
if len(hr) > 0:
hr = hr[0].get("MHS av")
if hr:
data["Hashrate"] = round(hr / 1000000, 2)
if temps:
temp = temps.get("TEMPS")
if temp:
if len(temp) > 0:
temp = temp[0].get("Chip")
if temp:
data["Temperature"] = round(temp, 2)
if pools:
pool_1 = None
pool_2 = None
pool_1_user = None
pool_2_user = None
pool_1_quota = 1
pool_2_quota = 1
quota = 0
for pool in pools.get("POOLS"):
if not pool_1_user:
pool_1_user = pool.get("User")
pool_1 = pool["URL"]
pool_1_quota = pool["Quota"]
elif not pool_2_user:
pool_2_user = pool.get("User")
pool_2 = pool["URL"]
pool_2_quota = pool["Quota"]
if not pool.get("User") == pool_1_user:
if not pool_2_user == pool.get("User"):
pool_2_user = pool.get("User")
pool_2 = pool["URL"]
pool_2_quota = pool["Quota"]
if pool_2_user and not pool_2_user == pool_1_user:
quota = f"{pool_1_quota}/{pool_2_quota}"
if pool_1:
data["Pool 1"] = pool_1
if pool_1_user:
data["Pool 1 User"] = pool_1_user
data["Pool User"] = pool_1_user
if pool_2:
data["Pool 2"] = pool_2
if pool_2_user:
data["Pool 2 User"] = pool_2_user
if quota:
data["Quota"] = quota
if tunerstatus:
tuner = tunerstatus.get("TUNERSTATUS")
if tuner:
if len(tuner) > 0:
wattage = tuner[0].get("PowerLimit")
if wattage:
data["Wattage"] = wattage
return data