added getting data for btminer
This commit is contained in:
@@ -82,3 +82,20 @@ class BaseMiner:
|
|||||||
|
|
||||||
async def send_config(self, yaml_config):
|
async def send_config(self, yaml_config):
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
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": "",
|
||||||
|
}
|
||||||
|
return data
|
||||||
|
|||||||
@@ -205,3 +205,5 @@ class BMMiner(BaseMiner):
|
|||||||
|
|
||||||
if quota:
|
if quota:
|
||||||
data["Split"] = quota
|
data["Split"] = quota
|
||||||
|
|
||||||
|
return data
|
||||||
|
|||||||
@@ -27,12 +27,15 @@ class BTMiner(BaseMiner):
|
|||||||
return None
|
return None
|
||||||
|
|
||||||
async def get_hostname(self) -> str:
|
async def get_hostname(self) -> str:
|
||||||
|
if self.hostname:
|
||||||
|
return self.hostname
|
||||||
try:
|
try:
|
||||||
host_data = await self.api.get_miner_info()
|
host_data = await self.api.get_miner_info()
|
||||||
if host_data:
|
if host_data:
|
||||||
host = host_data["Msg"]["hostname"]
|
host = host_data["Msg"]["hostname"]
|
||||||
logging.debug(f"Found hostname for {self.ip}: {host}")
|
logging.debug(f"Found hostname for {self.ip}: {host}")
|
||||||
return host
|
self.hostname = host
|
||||||
|
return self.hostname
|
||||||
except APIError:
|
except APIError:
|
||||||
logging.warning(f"Failed to get hostname for miner: {self}")
|
logging.warning(f"Failed to get hostname for miner: {self}")
|
||||||
return "?"
|
return "?"
|
||||||
@@ -70,3 +73,97 @@ class BTMiner(BaseMiner):
|
|||||||
print(board)
|
print(board)
|
||||||
logging.debug(f"Found board data for {self}: {boards}")
|
logging.debug(f"Found board data for {self}: {boards}")
|
||||||
return boards
|
return boards
|
||||||
|
|
||||||
|
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", "devs", "pools")
|
||||||
|
summary = miner_data.get("summary")[0]
|
||||||
|
devs = miner_data.get("devs")[0]
|
||||||
|
pools = miner_data.get("pools")[0]
|
||||||
|
|
||||||
|
if model:
|
||||||
|
data["Model"] = model
|
||||||
|
|
||||||
|
if hostname:
|
||||||
|
data["Hostname"] = hostname
|
||||||
|
|
||||||
|
if summary:
|
||||||
|
summary_data = summary.get("SUMMARY")
|
||||||
|
if summary_data:
|
||||||
|
if len(summary_data) > 0:
|
||||||
|
hr = summary_data[0].get("MHS av")
|
||||||
|
if hr:
|
||||||
|
data["Hashrate"] = round(hr / 1000000, 2)
|
||||||
|
|
||||||
|
wattage = summary_data[0].get("Power")
|
||||||
|
if wattage:
|
||||||
|
data["Wattage"] = round(wattage)
|
||||||
|
|
||||||
|
if devs:
|
||||||
|
temp_data = devs.get("DEVS")
|
||||||
|
if temp_data:
|
||||||
|
for board in temp_data:
|
||||||
|
temp = board.get("Chip Temp Avg")
|
||||||
|
if temp and not temp == 0.0:
|
||||||
|
data["Temperature"] = temp
|
||||||
|
break
|
||||||
|
|
||||||
|
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
|
||||||
|
|
||||||
|
print(data)
|
||||||
|
|||||||
@@ -180,3 +180,5 @@ class CGMiner(BaseMiner):
|
|||||||
|
|
||||||
if quota:
|
if quota:
|
||||||
data["Split"] = quota
|
data["Split"] = quota
|
||||||
|
|
||||||
|
return data
|
||||||
|
|||||||
@@ -62,155 +62,4 @@ async def get_miners_data(miners: list):
|
|||||||
|
|
||||||
|
|
||||||
async def _get_data(miner):
|
async def _get_data(miner):
|
||||||
warnings.filterwarnings("ignore")
|
return await miner.get_data()
|
||||||
miner_data = None
|
|
||||||
host = await miner.get_hostname()
|
|
||||||
try:
|
|
||||||
model = await miner.get_model()
|
|
||||||
except APIError:
|
|
||||||
model = "?"
|
|
||||||
if not model:
|
|
||||||
model = "?"
|
|
||||||
temps = 0
|
|
||||||
th5s = 0
|
|
||||||
wattage = 0
|
|
||||||
user = "?"
|
|
||||||
|
|
||||||
try:
|
|
||||||
miner_data = await miner.api.multicommand(
|
|
||||||
"summary", "devs", "temps", "tunerstatus", "pools", "stats"
|
|
||||||
)
|
|
||||||
except APIError:
|
|
||||||
try:
|
|
||||||
# no devs command, it will fail in this case
|
|
||||||
miner_data = await miner.api.multicommand(
|
|
||||||
"summary", "temps", "tunerstatus", "pools", "stats"
|
|
||||||
)
|
|
||||||
except APIError as e:
|
|
||||||
logging.warning(f"{str(miner.ip)}: {e}")
|
|
||||||
return {
|
|
||||||
"IP": str(miner.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": "Unknown",
|
|
||||||
"Pool 2 User": "Unknown",
|
|
||||||
}
|
|
||||||
if miner_data:
|
|
||||||
logging.info(f"Received miner data for miner: {miner.ip}")
|
|
||||||
# get all data from summary
|
|
||||||
if "summary" in miner_data.keys():
|
|
||||||
if (
|
|
||||||
not miner_data["summary"][0].get("SUMMARY") == []
|
|
||||||
and "SUMMARY" in miner_data["summary"][0].keys()
|
|
||||||
):
|
|
||||||
# temperature data, this is the idea spot to get this
|
|
||||||
if "Temperature" in miner_data["summary"][0]["SUMMARY"][0].keys():
|
|
||||||
if (
|
|
||||||
not round(miner_data["summary"][0]["SUMMARY"][0]["Temperature"])
|
|
||||||
== 0
|
|
||||||
):
|
|
||||||
temps = miner_data["summary"][0]["SUMMARY"][0]["Temperature"]
|
|
||||||
# hashrate data
|
|
||||||
if "MHS av" in miner_data["summary"][0]["SUMMARY"][0].keys():
|
|
||||||
th5s = format(
|
|
||||||
round(
|
|
||||||
miner_data["summary"][0]["SUMMARY"][0]["MHS av"] / 1000000,
|
|
||||||
2,
|
|
||||||
),
|
|
||||||
".2f",
|
|
||||||
).rjust(6, " ")
|
|
||||||
elif "GHS av" in miner_data["summary"][0]["SUMMARY"][0].keys():
|
|
||||||
if not miner_data["summary"][0]["SUMMARY"][0]["GHS av"] == "":
|
|
||||||
th5s = format(
|
|
||||||
round(
|
|
||||||
float(miner_data["summary"][0]["SUMMARY"][0]["GHS av"])
|
|
||||||
/ 1000,
|
|
||||||
2,
|
|
||||||
),
|
|
||||||
".2f",
|
|
||||||
).rjust(6, " ")
|
|
||||||
|
|
||||||
# alternate temperature data, for BraiinsOS
|
|
||||||
if "temps" in miner_data.keys():
|
|
||||||
if not miner_data["temps"][0].get("TEMPS") == []:
|
|
||||||
if "Chip" in miner_data["temps"][0]["TEMPS"][0].keys():
|
|
||||||
for board in miner_data["temps"][0]["TEMPS"]:
|
|
||||||
if board["Chip"] is not None and not board["Chip"] == 0.0:
|
|
||||||
temps = board["Chip"]
|
|
||||||
# alternate temperature data, for Whatsminers
|
|
||||||
if "devs" in miner_data.keys():
|
|
||||||
if not miner_data["devs"][0].get("DEVS") == []:
|
|
||||||
if "Chip Temp Avg" in miner_data["devs"][0]["DEVS"][0].keys():
|
|
||||||
for board in miner_data["devs"][0]["DEVS"]:
|
|
||||||
if (
|
|
||||||
board["Chip Temp Avg"] is not None
|
|
||||||
and not board["Chip Temp Avg"] == 0.0
|
|
||||||
):
|
|
||||||
temps = board["Chip Temp Avg"]
|
|
||||||
# alternate temperature data
|
|
||||||
if "stats" in miner_data.keys():
|
|
||||||
if not miner_data["stats"][0]["STATS"] == []:
|
|
||||||
for temp in ["temp2", "temp1", "temp3"]:
|
|
||||||
if temp in miner_data["stats"][0]["STATS"][1].keys():
|
|
||||||
if (
|
|
||||||
miner_data["stats"][0]["STATS"][1][temp] is not None
|
|
||||||
and not miner_data["stats"][0]["STATS"][1][temp] == 0.0
|
|
||||||
):
|
|
||||||
temps = miner_data["stats"][0]["STATS"][1][temp]
|
|
||||||
# alternate temperature data, for Avalonminers
|
|
||||||
miner_data["stats"][0]["STATS"][0].keys()
|
|
||||||
if any(
|
|
||||||
"MM ID" in string
|
|
||||||
for string in miner_data["stats"][0]["STATS"][0].keys()
|
|
||||||
):
|
|
||||||
temp_all = []
|
|
||||||
for key in [
|
|
||||||
string
|
|
||||||
for string in miner_data["stats"][0]["STATS"][0].keys()
|
|
||||||
if "MM ID" in string
|
|
||||||
]:
|
|
||||||
for value in [
|
|
||||||
string
|
|
||||||
for string in miner_data["stats"][0]["STATS"][0][key].split(" ")
|
|
||||||
if "TMax" in string
|
|
||||||
]:
|
|
||||||
temp_all.append(int(value.split("[")[1].replace("]", "")))
|
|
||||||
temps = round(sum(temp_all) / len(temp_all))
|
|
||||||
|
|
||||||
# pool information
|
|
||||||
if "pools" in miner_data.keys():
|
|
||||||
if not miner_data["pools"][0].get("POOLS") == []:
|
|
||||||
user = miner_data["pools"][0]["POOLS"][0]["User"]
|
|
||||||
|
|
||||||
else:
|
|
||||||
print(miner_data["pools"][0])
|
|
||||||
user = "Blank"
|
|
||||||
|
|
||||||
# braiins tuner status / wattage
|
|
||||||
if "tunerstatus" in miner_data.keys():
|
|
||||||
wattage = miner_data["tunerstatus"][0]["TUNERSTATUS"][0]["PowerLimit"]
|
|
||||||
|
|
||||||
elif "Power" in miner_data["summary"][0]["SUMMARY"][0].keys():
|
|
||||||
wattage = miner_data["summary"][0]["SUMMARY"][0]["Power"]
|
|
||||||
|
|
||||||
ret_data = {
|
|
||||||
"Hashrate": th5s,
|
|
||||||
"IP": str(miner.ip),
|
|
||||||
"Model": model,
|
|
||||||
"Temperature": round(temps),
|
|
||||||
"Hostname": host,
|
|
||||||
"Pool User": user,
|
|
||||||
"Pool 1 User": user,
|
|
||||||
"Wattage": wattage,
|
|
||||||
}
|
|
||||||
|
|
||||||
logging.debug(f"{ret_data}")
|
|
||||||
|
|
||||||
return ret_data
|
|
||||||
|
|||||||
Reference in New Issue
Block a user