|
|
|
@ -47,14 +47,7 @@ class MoonlightTester:
|
|
|
|
|
log_name = "moonlight-{:%m-%d-%Y}-{:%H-%M}-router-iperf.txt".format(date.today(), datetime.now())
|
|
|
|
|
log_location = os.path.join(LOG_DIR_PATH, log_name)
|
|
|
|
|
|
|
|
|
|
async def offline_log(msg):
|
|
|
|
|
with open(log_location, 'a') as log_file:
|
|
|
|
|
log_file.write(msg + "\n")
|
|
|
|
|
|
|
|
|
|
async def log(msg):
|
|
|
|
|
await offline_log(msg)
|
|
|
|
|
await context.bot.send_message(chat_id=update.effective_chat.id, text=msg,
|
|
|
|
|
message_thread_id=update.message.message_thread_id)
|
|
|
|
|
log = self.get_offline_first_log_fn(bot=context.bot, log_location=log_location)
|
|
|
|
|
|
|
|
|
|
if update.effective_chat.id != int(SECRETS["TELEGRAM_LOG_CHAT_ID"]):
|
|
|
|
|
await log("++ can only start iperf test from Moonlight Bot group")
|
|
|
|
@ -79,12 +72,7 @@ class MoonlightTester:
|
|
|
|
|
log_name = "moonlight-{:%m-%d-%Y}-{:%H-%M}-pi-iperf.txt".format(date.today(), datetime.now())
|
|
|
|
|
log_location = os.path.join(LOG_DIR_PATH, log_name)
|
|
|
|
|
|
|
|
|
|
async def offline_log(msg):
|
|
|
|
|
with open(log_location, 'a') as log_file:
|
|
|
|
|
log_file.write(msg + "\n")
|
|
|
|
|
async def log(msg):
|
|
|
|
|
await offline_log(msg)
|
|
|
|
|
await context.bot.send_message(chat_id=update.effective_chat.id, text=msg, message_thread_id=update.message.message_thread_id)
|
|
|
|
|
log = self.get_offline_first_log_fn(bot=context.bot, log_location=log_location)
|
|
|
|
|
|
|
|
|
|
if update.effective_chat.id != int(SECRETS["TELEGRAM_LOG_CHAT_ID"]):
|
|
|
|
|
await log("++ can only start iperf test from Moonlight Bot group")
|
|
|
|
@ -105,14 +93,7 @@ class MoonlightTester:
|
|
|
|
|
log_name = "moonlight-{:%m-%d-%Y}-{:%H-%M}-pi-speedtest.txt".format(date.today(), datetime.now())
|
|
|
|
|
log_location = os.path.join(LOG_DIR_PATH, log_name)
|
|
|
|
|
|
|
|
|
|
async def offline_log(msg):
|
|
|
|
|
with open(log_location, 'a') as log_file:
|
|
|
|
|
log_file.write(msg + "\n")
|
|
|
|
|
|
|
|
|
|
async def log(msg):
|
|
|
|
|
await offline_log(msg)
|
|
|
|
|
await context.bot.send_message(chat_id=update.effective_chat.id, text=msg,
|
|
|
|
|
message_thread_id=update.message.message_thread_id)
|
|
|
|
|
log = self.get_offline_first_log_fn(bot=context.bot, log_location=log_location)
|
|
|
|
|
|
|
|
|
|
if update.effective_chat.id != int(SECRETS["TELEGRAM_LOG_CHAT_ID"]):
|
|
|
|
|
await log("++ can only start test from Moonlight Bot group")
|
|
|
|
@ -162,80 +143,59 @@ class MoonlightTester:
|
|
|
|
|
text = self.help_message()
|
|
|
|
|
await context.bot.send_message(chat_id=update.effective_chat.id, text=text, message_thread_id=update.message.message_thread_id)
|
|
|
|
|
|
|
|
|
|
async def send_log(self, bot, chat_id, message_thread_id, log_location):
|
|
|
|
|
async def send_log(self, bot, log_location):
|
|
|
|
|
# send log file
|
|
|
|
|
chat_id = SECRETS["TELEGRAM_LOG_CHAT_ID"]
|
|
|
|
|
message_thread_id = SECRETS.get("TELEGRAM_LOG_MESSAGE_THREAD_ID")
|
|
|
|
|
document = open(log_location, 'rb')
|
|
|
|
|
bot.send_document(chat_id, document, message_thread_id=message_thread_id)
|
|
|
|
|
await bot.send_document(chat_id, document, message_thread_id=message_thread_id)
|
|
|
|
|
|
|
|
|
|
async def nightly_router_iperf(self, time=10):
|
|
|
|
|
token = SECRETS["TELEGRAM_TOKEN"]
|
|
|
|
|
application = ApplicationBuilder().token(token).build()
|
|
|
|
|
chat_id = SECRETS["TELEGRAM_LOG_CHAT_ID"]
|
|
|
|
|
message_thread_id = SECRETS.get("TELEGRAM_LOG_MESSAGE_THREAD_ID")
|
|
|
|
|
bot = application.bot
|
|
|
|
|
|
|
|
|
|
log_name = "moonlight-{:%M-%d-%Y}-{:%H:%m}-router-iperf.txt".format(datetime.today(), datetime.now())
|
|
|
|
|
log_name = "moonlight-{:%m-%d-%Y}-{:%H-%M}-router-iperf.txt".format(datetime.today(), datetime.now())
|
|
|
|
|
log_location = os.path.join(LOG_DIR_PATH, log_name)
|
|
|
|
|
|
|
|
|
|
async def offline_log(msg):
|
|
|
|
|
with open(log_location, 'a') as log_file:
|
|
|
|
|
log_file.write(msg)
|
|
|
|
|
|
|
|
|
|
async def log(msg):
|
|
|
|
|
await offline_log(msg)
|
|
|
|
|
try:
|
|
|
|
|
await bot.send_message(chat_id=chat_id, text=msg, message_thread_id=message_thread_id)
|
|
|
|
|
except:
|
|
|
|
|
pass
|
|
|
|
|
log = self.get_offline_first_log_fn(bot=bot, log_location=log_location)
|
|
|
|
|
|
|
|
|
|
await log("☾☾ starting nightly router-to-router iperf test with {time} seconds per test".format(time=time))
|
|
|
|
|
tester = CowmeshRouterIperfTester(log=log, time=time)
|
|
|
|
|
await tester.run_test()
|
|
|
|
|
await tester.output_results()
|
|
|
|
|
await self.send_log(bot=bot, log_location=log_location, chat_id=chat_id, message_thread_id=message_thread_id)
|
|
|
|
|
await self.send_log(bot=bot, log_location=log_location)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
async def nightly_pi_iperf(self, time=10):
|
|
|
|
|
token = SECRETS["TELEGRAM_TOKEN"]
|
|
|
|
|
application = ApplicationBuilder().token(token).build()
|
|
|
|
|
chat_id = SECRETS["TELEGRAM_LOG_CHAT_ID"]
|
|
|
|
|
message_thread_id = SECRETS.get("TELEGRAM_LOG_MESSAGE_THREAD_ID")
|
|
|
|
|
bot = application.bot
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
log_name = "moonlight-{:%M-%d-%Y}-{:%H:%m}-pi-iperf.txt".format(datetime.today(), datetime.now())
|
|
|
|
|
log_name = "moonlight-{:%m-%d-%Y}-{:%H-%M}-pi-iperf.txt".format(datetime.today(), datetime.now())
|
|
|
|
|
log_location = os.path.join(LOG_DIR_PATH, log_name)
|
|
|
|
|
|
|
|
|
|
async def offline_log(msg):
|
|
|
|
|
with open(log_location, 'a') as log_file:
|
|
|
|
|
log_file.write(msg)
|
|
|
|
|
|
|
|
|
|
async def log(msg):
|
|
|
|
|
await offline_log(msg)
|
|
|
|
|
try:
|
|
|
|
|
await bot.send_message(chat_id=chat_id, text=msg, message_thread_id=message_thread_id)
|
|
|
|
|
except:
|
|
|
|
|
pass
|
|
|
|
|
log = self.get_offline_first_log_fn(bot=bot, log_location=log_location)
|
|
|
|
|
|
|
|
|
|
await log("☾☾ starting nightly computer-to-computer iperf test with {} seconds per test".format(time))
|
|
|
|
|
tester = CowmeshPiIperfTester(log=log, time=time)
|
|
|
|
|
await tester.run_test()
|
|
|
|
|
await tester.output_results()
|
|
|
|
|
await self.send_log(bot=bot, log_location=log_location, chat_id=chat_id, message_thread_id=message_thread_id)
|
|
|
|
|
await self.send_log(bot=bot, log_location=log_location)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
async def nightly_pi_speedtest(self):
|
|
|
|
|
def get_bot(self):
|
|
|
|
|
token = SECRETS["TELEGRAM_TOKEN"]
|
|
|
|
|
application = ApplicationBuilder().token(token).build()
|
|
|
|
|
bot = application.bot
|
|
|
|
|
return bot
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def get_offline_first_log_fn(self, bot, log_location):
|
|
|
|
|
|
|
|
|
|
chat_id = SECRETS["TELEGRAM_LOG_CHAT_ID"]
|
|
|
|
|
message_thread_id = SECRETS.get("TELEGRAM_LOG_MESSAGE_THREAD_ID")
|
|
|
|
|
bot = application.bot
|
|
|
|
|
|
|
|
|
|
log_name = "moonlight-{:%M-%d-%Y}-{:%H:%m}-pi-iperf.txt".format(datetime.today(), datetime.now())
|
|
|
|
|
log_location = os.path.join(LOG_DIR_PATH, log_name)
|
|
|
|
|
|
|
|
|
|
async def offline_log(msg):
|
|
|
|
|
with open(log_location, 'a') as log_file:
|
|
|
|
|
log_file.write(msg)
|
|
|
|
@ -247,13 +207,55 @@ class MoonlightTester:
|
|
|
|
|
except:
|
|
|
|
|
pass
|
|
|
|
|
|
|
|
|
|
return log
|
|
|
|
|
|
|
|
|
|
async def nightly_pi_speedtest(self):
|
|
|
|
|
|
|
|
|
|
bot = self.get_bot()
|
|
|
|
|
|
|
|
|
|
log_name = "moonlight-{:%m-%d-%Y}-{:%H-%M}-pi-speedtest.txt".format(datetime.today(), datetime.now())
|
|
|
|
|
log_location = os.path.join(LOG_DIR_PATH, log_name)
|
|
|
|
|
|
|
|
|
|
log = self.get_offline_first_log_fn(bot=bot, log_location=log_location)
|
|
|
|
|
|
|
|
|
|
await log("☾☾ starting nightly speedtest-cli speedtest")
|
|
|
|
|
tester = CowmeshPiSpeedtestTester(log=log)
|
|
|
|
|
await tester.run_test()
|
|
|
|
|
await tester.output_results()
|
|
|
|
|
await self.send_log(bot=bot, log_location=log_location, chat_id=chat_id, message_thread_id=message_thread_id)
|
|
|
|
|
await self.send_log(bot=bot, log_location=log_location)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
async def start_iperf_servers(self, update: Update, context: ContextTypes.DEFAULT_TYPE):
|
|
|
|
|
|
|
|
|
|
bot = self.get_bot()
|
|
|
|
|
|
|
|
|
|
log_name = "moonlight-{:%m-%d-%Y}-{:%H-%M}-start-iperf-servers.txt".format(datetime.today(), datetime.now())
|
|
|
|
|
log_location = os.path.join(LOG_DIR_PATH, log_name)
|
|
|
|
|
|
|
|
|
|
log = self.get_offline_first_log_fn(bot=bot, log_location=log_location)
|
|
|
|
|
|
|
|
|
|
await log("++ ensuring that iperf servers are running")
|
|
|
|
|
|
|
|
|
|
tester = CowmeshRouterIperfTester(log=log)
|
|
|
|
|
for i in range(0, 2):
|
|
|
|
|
await tester.start_iperf_servers()
|
|
|
|
|
|
|
|
|
|
await log("++ iperf servers are now running")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
async def cleanup_iperf_servers(self, update: Update, context: ContextTypes.DEFAULT_TYPE):
|
|
|
|
|
|
|
|
|
|
bot = self.get_bot()
|
|
|
|
|
|
|
|
|
|
log_name = "moonlight-{:%m-%d-%Y}-{:%H-%M}-cleanup-iperf-servers.txt".format(datetime.today(), datetime.now())
|
|
|
|
|
log_location = os.path.join(LOG_DIR_PATH, log_name)
|
|
|
|
|
|
|
|
|
|
log = self.get_offline_first_log_fn(bot=bot, log_location=log_location)
|
|
|
|
|
|
|
|
|
|
tester = CowmeshRouterIperfTester(log=log)
|
|
|
|
|
for i in range(0, 2):
|
|
|
|
|
await tester.cleanup_iperf_servers()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def init_bot_listener(self):
|
|
|
|
|
token = SECRETS["TELEGRAM_TOKEN"]
|
|
|
|
@ -277,6 +279,12 @@ class MoonlightTester:
|
|
|
|
|
pi_iperf_handler = CommandHandler('pi_iperf', self.pi_iperf)
|
|
|
|
|
application.add_handler(pi_iperf_handler)
|
|
|
|
|
|
|
|
|
|
start_iperf_servers_handler = CommandHandler('start_iperf_servers', self.start_iperf_servers)
|
|
|
|
|
application.add_handler(start_iperf_servers_handler)
|
|
|
|
|
|
|
|
|
|
cleanup_iperf_servers_handler = CommandHandler('cleanup_iperf_servers', self.cleanup_iperf_servers)
|
|
|
|
|
application.add_handler(cleanup_iperf_servers_handler)
|
|
|
|
|
|
|
|
|
|
speedtest_handler = CommandHandler('speedtest', self.speedtest)
|
|
|
|
|
application.add_handler(speedtest_handler)
|
|
|
|
|
|
|
|
|
|