feat(monitoring): add http server for monitoring

This commit is contained in:
Mael G. 2019-12-29 22:19:26 +01:00
parent 425ff79c8d
commit fc06756363
2 changed files with 42 additions and 0 deletions

1
bot.py
View file

@ -38,6 +38,7 @@ l_extensions = (
'cogs.utility', 'cogs.utility',
'cogs.vocal', 'cogs.vocal',
'cogs.private', 'cogs.private',
'cogs.monitoring',
'jishaku' 'jishaku'
) )

41
cogs/monitoring.py Normal file
View file

@ -0,0 +1,41 @@
import asyncio
import threading
from aiohttp import web
from discord.ext import commands
from bot import TuxBot
class Monitoring(commands.Cog):
def __init__(self):
self.app = web.Application()
t = threading.Thread(
target=self.run_server,
args=(self.aiohttp_server(),)
)
t.start()
def aiohttp_server(self):
async def hi(request):
return web.Response(text="I'm alive !")
self.app.add_routes([web.get('/', hi)])
runner = web.AppRunner(self.app)
return runner
@staticmethod
def run_server(runner):
loop = asyncio.new_event_loop()
asyncio.set_event_loop(loop)
loop.run_until_complete(runner.setup())
site = web.TCPSite(runner, '0.0.0.0', 3389)
loop.run_until_complete(site.start())
loop.run_forever()
def setup(bot: TuxBot):
bot.add_cog(Monitoring())