Remove unsupported Influx/Grafana analytics code
This commit is contained in:
parent
c15eddcfa1
commit
2f728e09aa
@ -7,7 +7,6 @@ services:
|
|||||||
- bot_main.py
|
- bot_main.py
|
||||||
depends_on:
|
depends_on:
|
||||||
- db
|
- db
|
||||||
- influx
|
|
||||||
environment:
|
environment:
|
||||||
- CLIENT_ID
|
- CLIENT_ID
|
||||||
- TOKEN
|
- TOKEN
|
||||||
@ -17,9 +16,6 @@ services:
|
|||||||
- "DATABASE_NAME=postgres"
|
- "DATABASE_NAME=postgres"
|
||||||
- "DATABASE_HOST=db"
|
- "DATABASE_HOST=db"
|
||||||
- "DATABASE_PORT=5432"
|
- "DATABASE_PORT=5432"
|
||||||
- "INFLUX_HOST=influx"
|
|
||||||
- "INFLUX_PORT=8086"
|
|
||||||
- "INFLUX_DB=pluralkit"
|
|
||||||
restart: always
|
restart: always
|
||||||
api:
|
api:
|
||||||
build: src/
|
build: src/
|
||||||
@ -42,22 +38,6 @@ services:
|
|||||||
volumes:
|
volumes:
|
||||||
- "db_data:/var/lib/postgresql/data"
|
- "db_data:/var/lib/postgresql/data"
|
||||||
restart: always
|
restart: always
|
||||||
influx:
|
|
||||||
image: influxdb:alpine
|
|
||||||
volumes:
|
|
||||||
- "influx_data:/var/lib/influxdb:Z"
|
|
||||||
restart: always
|
|
||||||
grafana:
|
|
||||||
build: grafana
|
|
||||||
depends_on:
|
|
||||||
- influx
|
|
||||||
ports:
|
|
||||||
- "2938:3000"
|
|
||||||
environment:
|
|
||||||
GF_SECURITY_ADMIN_USER: "${GRAFANA_USERNAME}"
|
|
||||||
GF_SECURITY_ADMIN_PASSWORD: "${GRAFANA_PASSWORD}"
|
|
||||||
restart: always
|
|
||||||
|
|
||||||
volumes:
|
volumes:
|
||||||
db_data:
|
db_data:
|
||||||
influx_data:
|
|
@ -11,7 +11,6 @@ import discord
|
|||||||
|
|
||||||
from pluralkit import db
|
from pluralkit import db
|
||||||
from pluralkit.bot import channel_logger, commands, proxy, embeds
|
from pluralkit.bot import channel_logger, commands, proxy, embeds
|
||||||
from pluralkit.stats import InfluxStatCollector, NullStatCollector
|
|
||||||
|
|
||||||
logging.basicConfig(level=logging.INFO, format="[%(asctime)s] [%(name)s] [%(levelname)s] %(message)s")
|
logging.basicConfig(level=logging.INFO, format="[%(asctime)s] [%(name)s] [%(levelname)s] %(message)s")
|
||||||
|
|
||||||
@ -29,13 +28,9 @@ class PluralKitBot:
|
|||||||
self.client.event(self.on_message)
|
self.client.event(self.on_message)
|
||||||
self.client.event(self.on_socket_raw_receive)
|
self.client.event(self.on_socket_raw_receive)
|
||||||
|
|
||||||
self.stats = NullStatCollector()
|
|
||||||
|
|
||||||
self.channel_logger = channel_logger.ChannelLogger(self.client)
|
self.channel_logger = channel_logger.ChannelLogger(self.client)
|
||||||
|
|
||||||
# "stats" passed here will be a NullStatsCollector, will get overwritten inside
|
self.proxy = proxy.Proxy(self.client, token, self.channel_logger)
|
||||||
# the Proxy object when the actual connection occurs
|
|
||||||
self.proxy = proxy.Proxy(self.client, token, self.channel_logger, self.stats)
|
|
||||||
|
|
||||||
async def on_error(self, evt, *args, **kwargs):
|
async def on_error(self, evt, *args, **kwargs):
|
||||||
self.logger.exception("Error while handling event {} with arguments {}:".format(evt, args))
|
self.logger.exception("Error while handling event {} with arguments {}:".format(evt, args))
|
||||||
@ -110,12 +105,6 @@ class PluralKitBot:
|
|||||||
|
|
||||||
await self.client.send_message(channel, "```python\n{}```".format(traceback.format_exc()), embed=embed)
|
await self.client.send_message(channel, "```python\n{}```".format(traceback.format_exc()), embed=embed)
|
||||||
|
|
||||||
async def periodical_stat_timer(self, pool):
|
|
||||||
async with pool.acquire() as conn:
|
|
||||||
while True:
|
|
||||||
await self.stats.report_periodical_stats(conn)
|
|
||||||
await asyncio.sleep(30)
|
|
||||||
|
|
||||||
async def run(self):
|
async def run(self):
|
||||||
try:
|
try:
|
||||||
self.logger.info("Connecting to database...")
|
self.logger.info("Connecting to database...")
|
||||||
@ -131,20 +120,6 @@ class PluralKitBot:
|
|||||||
async with self.pool.acquire() as conn:
|
async with self.pool.acquire() as conn:
|
||||||
await db.create_tables(conn)
|
await db.create_tables(conn)
|
||||||
|
|
||||||
if "INFLUX_HOST" in os.environ:
|
|
||||||
self.logger.info("Connecting to InfluxDB...")
|
|
||||||
self.stats = await InfluxStatCollector.connect(
|
|
||||||
os.environ["INFLUX_HOST"],
|
|
||||||
os.environ["INFLUX_PORT"],
|
|
||||||
os.environ["INFLUX_DB"]
|
|
||||||
)
|
|
||||||
|
|
||||||
# Overwrite the NullCollector passed to proxy
|
|
||||||
self.proxy.stats = self.stats
|
|
||||||
|
|
||||||
self.logger.info("Starting periodical stat reporting...")
|
|
||||||
asyncio.get_event_loop().create_task(self.periodical_stat_timer(self.pool))
|
|
||||||
|
|
||||||
self.logger.info("Connecting to Discord...")
|
self.logger.info("Connecting to Discord...")
|
||||||
await self.client.start(self.token)
|
await self.client.start(self.token)
|
||||||
finally:
|
finally:
|
||||||
|
@ -9,7 +9,6 @@ import discord
|
|||||||
|
|
||||||
from pluralkit import db
|
from pluralkit import db
|
||||||
from pluralkit.bot import channel_logger, utils, embeds
|
from pluralkit.bot import channel_logger, utils, embeds
|
||||||
from pluralkit.stats import StatCollector
|
|
||||||
|
|
||||||
logger = logging.getLogger("pluralkit.bot.proxy")
|
logger = logging.getLogger("pluralkit.bot.proxy")
|
||||||
|
|
||||||
@ -87,13 +86,12 @@ class DeletionPermissionError(Exception):
|
|||||||
|
|
||||||
|
|
||||||
class Proxy:
|
class Proxy:
|
||||||
def __init__(self, client: discord.Client, token: str, logger: channel_logger.ChannelLogger, stats: StatCollector):
|
def __init__(self, client: discord.Client, token: str, logger: channel_logger.ChannelLogger):
|
||||||
self.logger = logging.getLogger("pluralkit.bot.proxy")
|
self.logger = logging.getLogger("pluralkit.bot.proxy")
|
||||||
self.session = aiohttp.ClientSession()
|
self.session = aiohttp.ClientSession()
|
||||||
self.client = client
|
self.client = client
|
||||||
self.token = token
|
self.token = token
|
||||||
self.channel_logger = logger
|
self.channel_logger = logger
|
||||||
self.stats = stats
|
|
||||||
|
|
||||||
async def save_channel_webhook(self, conn, channel: discord.Channel, id: str, token: str) -> (str, str):
|
async def save_channel_webhook(self, conn, channel: discord.Channel, id: str, token: str) -> (str, str):
|
||||||
await db.add_webhook(conn, channel.id, id, token)
|
await db.add_webhook(conn, channel.id, id, token)
|
||||||
@ -172,9 +170,6 @@ class Proxy:
|
|||||||
if resp.status == 200:
|
if resp.status == 200:
|
||||||
message = await resp.json()
|
message = await resp.json()
|
||||||
|
|
||||||
# Report webhook stats to Influx
|
|
||||||
await self.stats.report_webhook(time.perf_counter() - time_before, True)
|
|
||||||
|
|
||||||
await db.add_message(conn, message["id"], message["channel_id"], member.id, original_message.author.id)
|
await db.add_message(conn, message["id"], message["channel_id"], member.id, original_message.author.id)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
@ -212,9 +207,6 @@ class Proxy:
|
|||||||
message["timestamp"]),
|
message["timestamp"]),
|
||||||
message_id=message["id"])
|
message_id=message["id"])
|
||||||
elif resp.status == 404 and not has_already_retried:
|
elif resp.status == 404 and not has_already_retried:
|
||||||
# Report webhook stats to Influx
|
|
||||||
await self.stats.report_webhook(time.perf_counter() - time_before, False)
|
|
||||||
|
|
||||||
# Webhook doesn't exist. Delete it from the DB, create, and add a new one
|
# Webhook doesn't exist. Delete it from the DB, create, and add a new one
|
||||||
self.logger.warning("Webhook registered in DB doesn't exist, deleting hook from DB, re-adding, and trying again (channel={}, hook={})".format(original_message.channel.id, hook_id))
|
self.logger.warning("Webhook registered in DB doesn't exist, deleting hook from DB, re-adding, and trying again (channel={}, hook={})".format(original_message.channel.id, hook_id))
|
||||||
await db.delete_webhook(conn, original_message.channel.id)
|
await db.delete_webhook(conn, original_message.channel.id)
|
||||||
@ -223,9 +215,6 @@ class Proxy:
|
|||||||
# Then try again all over, making sure to not retry again and go in a loop should it continually fail
|
# Then try again all over, making sure to not retry again and go in a loop should it continually fail
|
||||||
return await self.do_proxy_message(conn, member, original_message, text, attachment_url, has_already_retried=True)
|
return await self.do_proxy_message(conn, member, original_message, text, attachment_url, has_already_retried=True)
|
||||||
else:
|
else:
|
||||||
# Report webhook stats to Influx
|
|
||||||
await self.stats.report_webhook(time.perf_counter() - time_before, False)
|
|
||||||
|
|
||||||
raise discord.HTTPException(resp, await resp.text())
|
raise discord.HTTPException(resp, await resp.text())
|
||||||
|
|
||||||
async def try_proxy_message(self, conn, message: discord.Message):
|
async def try_proxy_message(self, conn, message: discord.Message):
|
||||||
|
@ -8,7 +8,6 @@ import asyncpg
|
|||||||
import asyncpg.exceptions
|
import asyncpg.exceptions
|
||||||
from discord.utils import snowflake_time
|
from discord.utils import snowflake_time
|
||||||
|
|
||||||
from pluralkit import stats
|
|
||||||
from pluralkit.system import System
|
from pluralkit.system import System
|
||||||
from pluralkit.member import Member
|
from pluralkit.member import Member
|
||||||
|
|
||||||
@ -29,12 +28,8 @@ def db_wrap(func):
|
|||||||
after = time.perf_counter()
|
after = time.perf_counter()
|
||||||
|
|
||||||
logger.debug(" - DB call {} took {:.2f} ms".format(func.__name__, (after - before) * 1000))
|
logger.debug(" - DB call {} took {:.2f} ms".format(func.__name__, (after - before) * 1000))
|
||||||
# TODO: find some way to give this func access to the bot's stats object
|
|
||||||
#await stats.report_db_query(func.__name__, after - before, True)
|
|
||||||
|
|
||||||
return res
|
return res
|
||||||
except asyncpg.exceptions.PostgresError:
|
except asyncpg.exceptions.PostgresError:
|
||||||
#await stats.report_db_query(func.__name__, time.perf_counter() - before, False)
|
|
||||||
logger.exception("Error from database query {}".format(func.__name__))
|
logger.exception("Error from database query {}".format(func.__name__))
|
||||||
return inner
|
return inner
|
||||||
|
|
||||||
|
@ -1,69 +0,0 @@
|
|||||||
from aioinflux import InfluxDBClient
|
|
||||||
|
|
||||||
|
|
||||||
class StatCollector:
|
|
||||||
async def report_db_query(self, query_name, time, success):
|
|
||||||
pass
|
|
||||||
|
|
||||||
async def report_command(self, command_name, execution_time, response_time):
|
|
||||||
pass
|
|
||||||
|
|
||||||
async def report_webhook(self, time, success):
|
|
||||||
pass
|
|
||||||
|
|
||||||
async def report_periodical_stats(self, conn):
|
|
||||||
pass
|
|
||||||
|
|
||||||
|
|
||||||
class NullStatCollector(StatCollector):
|
|
||||||
pass
|
|
||||||
|
|
||||||
|
|
||||||
class InfluxStatCollector(StatCollector):
|
|
||||||
@staticmethod
|
|
||||||
async def connect(host: str, port: int, db: str):
|
|
||||||
client = InfluxDBClient(host=host, port=port, db=db)
|
|
||||||
await client.create_database(db=db)
|
|
||||||
|
|
||||||
return InfluxStatCollector(client)
|
|
||||||
|
|
||||||
def __init__(self, client):
|
|
||||||
self.client = client
|
|
||||||
|
|
||||||
async def report_db_query(self, query_name, time, success):
|
|
||||||
await self.client.write({
|
|
||||||
"measurement": "database_query",
|
|
||||||
"tags": {"query": query_name},
|
|
||||||
"fields": {"response_time": time, "success": int(success)}
|
|
||||||
})
|
|
||||||
|
|
||||||
async def report_command(self, command_name, execution_time, response_time):
|
|
||||||
await self.client.write({
|
|
||||||
"measurement": "command",
|
|
||||||
"tags": {"command": command_name},
|
|
||||||
"fields": {"execution_time": execution_time, "response_time": response_time}
|
|
||||||
})
|
|
||||||
|
|
||||||
async def report_webhook(self, time, success):
|
|
||||||
await self.client.write({
|
|
||||||
"measurement": "webhook",
|
|
||||||
"fields": {"response_time": time, "success": int(success)}
|
|
||||||
})
|
|
||||||
|
|
||||||
async def report_periodical_stats(self, conn):
|
|
||||||
from pluralkit import db
|
|
||||||
|
|
||||||
systems = await db.system_count(conn)
|
|
||||||
members = await db.member_count(conn)
|
|
||||||
messages = await db.message_count(conn)
|
|
||||||
accounts = await db.account_count(conn)
|
|
||||||
|
|
||||||
await self.client.write({
|
|
||||||
"measurement": "stats",
|
|
||||||
"fields": {
|
|
||||||
"systems": systems,
|
|
||||||
"members": members,
|
|
||||||
"messages": messages,
|
|
||||||
"accounts": accounts
|
|
||||||
}
|
|
||||||
})
|
|
Loading…
Reference in New Issue
Block a user