added getting data for bmminer and cgminer

This commit is contained in:
UpstreamData
2022-05-05 11:19:11 -06:00
parent a13f5dd2d1
commit 64b5e6c032
4 changed files with 167 additions and 8 deletions

View File

@@ -46,13 +46,13 @@ class BaseMiner:
)
return conn
except Exception as e:
logging.warning(f"{self} raised an exception: {e}")
# logging.warning(f"{self} raised an exception: {e}")
raise e
except OSError:
logging.warning(f"Connection refused: {self}")
return None
except Exception as e:
logging.warning(f"{self} raised an exception: {e}")
# logging.warning(f"{self} raised an exception: {e}")
raise e
async def send_file(self, src, dest):

View File

@@ -133,7 +133,75 @@ class BMMiner(BaseMiner):
"Pool 2": "",
"Pool 2 User": "",
}
data = await self.api.multicommand(
"summary", "devs", "temps", "tunerstatus", "pools", "stats"
)
print(data)
miner_data = await self.api.multicommand("summary", "pools", "stats")
model = await self.get_model()
hostname = await self.get_hostname()
summary = miner_data.get("summary")[0]
pools = miner_data.get("pools")[0]
stats = miner_data.get("stats")[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("GHS av")
if hr:
data["Hashrate"] = round(hr / 1000, 2)
if stats:
temp = stats.get("STATS")
if temp:
if len(temp) > 1:
for item in ["temp2", "temp1", "temp3"]:
temperature = temp[1].get(item)
if temperature and not temperature == 0.0:
data["Temperature"] = temperature
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["Split"] = quota

View File

@@ -28,11 +28,15 @@ class CGMiner(BaseMiner):
return None
async def get_hostname(self) -> str:
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")
return data.stdout.strip()
host = data.stdout.strip()
self.hostname = host
return self.hostname
else:
return "?"
except Exception:
@@ -88,3 +92,91 @@ class CGMiner(BaseMiner):
result = await conn.run(command, check=True)
self.config = result.stdout
print(str(self.config))
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": "",
}
miner_data = await self.api.multicommand("summary", "pools", "stats")
model = await self.get_model()
hostname = await self.get_hostname()
summary = miner_data.get("summary")[0]
pools = miner_data.get("pools")[0]
stats = miner_data.get("stats")[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("GHS av")
if hr:
data["Hashrate"] = round(hr / 1000, 2)
if stats:
temp = stats.get("STATS")
if temp:
if len(temp) > 1:
for item in ["temp2", "temp1", "temp3"]:
temperature = temp[1].get(item)
if temperature and not temperature == 0.0:
data["Temperature"] = temperature
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["Split"] = quota

View File

@@ -265,7 +265,6 @@ class MinerFactory:
and not version.get("VERSION") == []
):
model = version["VERSION"][0]["Type"]
print("done")
return model, api
async def _validate_command(self, data: dict) -> tuple: