mirror of
https://github.com/PluralKit/PluralKit.git
synced 2026-02-12 16:50:10 +00:00
Add InfluxDB/Grafana monitoring
This commit is contained in:
parent
9c0811afe8
commit
0b8488606b
11 changed files with 668 additions and 23 deletions
|
|
@ -3,9 +3,9 @@ import time
|
|||
import asyncpg
|
||||
import asyncpg.exceptions
|
||||
|
||||
from pluralkit import stats
|
||||
from pluralkit.bot import logger
|
||||
|
||||
|
||||
async def connect():
|
||||
while True:
|
||||
try:
|
||||
|
|
@ -17,11 +17,17 @@ async def connect():
|
|||
def db_wrap(func):
|
||||
async def inner(*args, **kwargs):
|
||||
before = time.perf_counter()
|
||||
res = await func(*args, **kwargs)
|
||||
after = time.perf_counter()
|
||||
try:
|
||||
res = await func(*args, **kwargs)
|
||||
after = time.perf_counter()
|
||||
|
||||
logger.debug(" - DB call {} took {:.2f} ms".format(func.__name__, (after - before) * 1000))
|
||||
return res
|
||||
logger.debug(" - DB call {} took {:.2f} ms".format(func.__name__, (after - before) * 1000))
|
||||
await stats.report_db_query(func.__name__, after - before, True)
|
||||
|
||||
return res
|
||||
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__))
|
||||
return inner
|
||||
|
||||
@db_wrap
|
||||
|
|
@ -223,6 +229,14 @@ async def update_server(conn, server_id: str, logging_channel_id: str):
|
|||
logger.debug("Updating server settings (id={}, log_channel={})".format(server_id, logging_channel_id))
|
||||
await conn.execute("insert into servers (id, log_channel) values ($1, $2) on conflict (id) do update set log_channel = $2", int(server_id), logging_channel_id)
|
||||
|
||||
@db_wrap
|
||||
async def member_count(conn):
|
||||
return await conn.fetchval("select count(*) from members")
|
||||
|
||||
@db_wrap
|
||||
async def system_count(conn):
|
||||
return await conn.fetchval("select count(*) from systems")
|
||||
|
||||
async def create_tables(conn):
|
||||
await conn.execute("""create table if not exists systems (
|
||||
id serial primary key,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue