started adding some basic logging functionality

This commit is contained in:
UpstreamData
2022-03-14 15:52:46 -06:00
parent 2380b94db1
commit c22be7ded8
7 changed files with 82 additions and 16 deletions

12
logger/__init__.py Normal file
View File

@@ -0,0 +1,12 @@
import logging
from settings import DEBUG
logging.basicConfig()
logger = logging.getLogger()
if DEBUG:
logger.setLevel(logging.DEBUG)
else:
logger.setLevel(logging.INFO)
logging.getLogger("asyncssh").setLevel(logging.WARNING)

View File

@@ -22,7 +22,7 @@ async def get_bos_bad_tuners(ip: str = "192.168.1.0", mask: int = 24):
# run all the tuner status commands
tuner_status = await asyncio.gather(*tuner_tasks)
# create a list of all miners with bad board tuner status'
# create a list of all miners with bad board tuner status
bad_tuner_miners = []
for item in tuner_status:
# loop through and get each miners' bad board count

View File

@@ -16,6 +16,10 @@ class MinerNetwork:
def __len__(self):
return len([item for item in self.get_network().hosts()])
def __repr__(self):
return str(self.network)
def get_network(self) -> ipaddress.ip_network:
"""Get the network using the information passed to the MinerNetwork or from cache."""
# if we have a network cached already, use that

View File

@@ -1,27 +1,46 @@
import toml
import os
NETWORK_PING_RETRIES: int = 3
NETWORK_PING_TIMEOUT: int = 5
NETWORK_SCAN_THREADS: int = 300
CFG_UTIL_REBOOT_THREADS: int = 300
CFG_UTIL_CONFIG_THREADS: int = 300
MINER_FACTORY_GET_VERSION_RETRIES: int = 3
WHATSMINER_PWD = "admin"
DEBUG = False
try:
with open(os.path.join(os.getcwd(), "settings.toml"), "r") as settings_file:
with open(os.path.join(os.path.dirname(__file__), "settings.toml"), "r") as settings_file:
settings = toml.loads(settings_file.read())
except:
pass
settings_keys = settings.keys()
if "ping_retries" in settings_keys:
NETWORK_PING_RETRIES: int = settings["ping_retries"]
if "ping_timeout" in settings_keys:
NETWORK_PING_TIMEOUT: int = settings["ping_timeout"]
if "scan_threads" in settings_keys:
NETWORK_SCAN_THREADS: int = settings["scan_threads"]
if "reboot_threads" in settings_keys:
CFG_UTIL_REBOOT_THREADS: int = settings["reboot_threads"]
if "config_threads" in settings_keys:
CFG_UTIL_CONFIG_THREADS: int = settings["config_threads"]
if "get_version_retries" in settings_keys:
MINER_FACTORY_GET_VERSION_RETRIES: int = settings["get_version_retries"]
if "whatsminer_pwd" in settings_keys:
WHATSMINER_PWD: str = settings["whatsminer_pwd"]
except:
NETWORK_PING_RETRIES: int = 3
NETWORK_PING_TIMEOUT: int = 5
NETWORK_SCAN_THREADS: int = 300
CFG_UTIL_REBOOT_THREADS: int = 300
CFG_UTIL_CONFIG_THREADS: int = 300
MINER_FACTORY_GET_VERSION_RETRIES: int = 3
WHATSMINER_PWD = "admin"
if "debug" in settings_keys:
DEBUG: int = settings["debug"]

View File

@@ -12,3 +12,9 @@ reboot_threads = 300
# If you change the password, you can pass that password here.
whatsminer_pwd = "admin"
### DEBUG MODE ###
# change this to debug = true
# to enable debug mode.
# debug = false
debug = true

View File

@@ -1,9 +1,15 @@
# TODO: Add Logging
from tools.cfg_util.cfg_util_sg.ui import ui
import asyncio
import sys
import logging
from tools.cfg_util.cfg_util_sg.ui import ui
# initialize logger and get settings
from logger import logger
logger.info("Initializing logger for CFG Util.")
# Fix bug with some whatsminers and asyncio because of a socket not being shut down:
if sys.version_info[0] == 3 and sys.version_info[1] >= 8 and sys.platform.startswith('win'):
@@ -11,5 +17,7 @@ if sys.version_info[0] == 3 and sys.version_info[1] >= 8 and sys.platform.starts
def main():
logging.info("Starting CFG Util.")
loop = asyncio.new_event_loop()
loop.run_until_complete(ui())
logging.info("Closing CFG Util.")

View File

@@ -2,6 +2,7 @@ import asyncio
import ipaddress
import time
import warnings
import logging
from API import APIError
from tools.cfg_util.cfg_util_sg.func.parse_data import safe_parse_api_data
@@ -15,10 +16,12 @@ from settings import CFG_UTIL_CONFIG_THREADS as CONFIG_THREADS, CFG_UTIL_REBOOT_
async def import_config(idx):
await update_ui_with_data("status", "Importing")
logging.debug(f"{window['ip_table'].Values[idx[0]][0]}: Importing config.")
miner = await miner_factory.get_miner(ipaddress.ip_address(window["ip_table"].Values[idx[0]][0]))
await miner.get_config()
config = miner.config
await update_ui_with_data("config", str(config))
logging.debug(f"{window['ip_table'].Values[idx[0]][0]}: Config import completed.")
await update_ui_with_data("status", "")
@@ -287,6 +290,9 @@ async def scan_and_get_data(network):
await update_ui_with_data("ip_table", [])
network_size = len(network)
miner_generator = network.scan_network_generator()
logging.info(f"Scanning network: {str(network)}")
await set_progress_bar_len(3 * network_size)
progress_bar_len = 0
miners = []
@@ -299,6 +305,8 @@ async def scan_and_get_data(network):
# window["ip_table"].update([["Identifying..."] for miner in miners])
progress_bar_len += 1
asyncio.create_task(update_prog_bar(progress_bar_len))
logging.info(f"Found {len(miners)} Miners")
logging.debug(f"Found miners: {miners}")
progress_bar_len += network_size - len(miners)
asyncio.create_task(update_prog_bar(progress_bar_len))
get_miner_genenerator = miner_factory.get_miner_generator(miners)
@@ -309,6 +317,8 @@ async def scan_and_get_data(network):
window["ip_table"].update([[str(miner.ip)] for miner in all_miners])
progress_bar_len += 1
asyncio.create_task(update_prog_bar(progress_bar_len))
logging.info(f"Resolved {len(all_miners)} Miners")
logging.debug(f"Resolved to miner types: {all_miners}")
await update_ui_with_data("ip_count", str(len(all_miners)))
data_gen = asyncio.as_completed([get_formatted_data(miner) for miner in miners])
ip_table_data = window["ip_table"].Values
@@ -316,6 +326,7 @@ async def scan_and_get_data(network):
progress_bar_len += (network_size - len(miners))
asyncio.create_task(update_prog_bar(progress_bar_len))
await update_ui_with_data("status", "Getting Data")
logging.debug("Getting data on miners.")
for all_data in data_gen:
data_point = await all_data
if data_point["IP"] in ordered_all_ips:
@@ -336,6 +347,7 @@ async def scan_and_get_data(network):
async def get_formatted_data(ip: ipaddress.ip_address):
miner = await miner_factory.get_miner(ip)
logging.debug(f"Getting data for miner: {miner.ip}")
warnings.filterwarnings('ignore')
miner_data = None
host = await miner.get_hostname()
@@ -357,10 +369,11 @@ async def get_formatted_data(ip: ipaddress.ip_address):
# no devs command, it will fail in this case
miner_data = await miner.api.multicommand("summary", "temps", "tunerstatus", "pools", "stats")
except APIError as e:
print(e)
logging.warning(f"{str(ip)}: {e}")
return {'TH/s': 0, 'IP': str(miner.ip), 'model': 'Unknown', 'temp': 0, 'host': 'Unknown', 'user': 'Unknown',
'wattage': 0}
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():
@@ -422,10 +435,14 @@ async def get_formatted_data(ip: ipaddress.ip_address):
elif "Power" in miner_data["summary"][0]["SUMMARY"][0].keys():
wattage = await safe_parse_api_data(miner_data, "summary", 0, 'SUMMARY', 0, "Power")
return {'TH/s': th5s, 'IP': str(miner.ip), 'model': model,
ret_data = {'TH/s': th5s, 'IP': str(miner.ip), 'model': model,
'temp': round(temps), 'host': host, 'user': user,
'wattage': wattage}
logging.debug(f"{ret_data}")
return ret_data
async def generate_config(username, workername, v2_allowed):
if username and workername: