2
0
mirror of https://github.com/Nick80835/microbot synced 2025-08-29 05:29:16 +00:00

add db statistics command

This commit is contained in:
Nick80835 2023-10-12 19:45:15 -04:00
parent 05a3b5a14e
commit b5c9ecdb62
2 changed files with 29 additions and 3 deletions

View File

@ -121,6 +121,9 @@ class ChatWrapper():
class Database():
cached_chat_wrappers = {}
chat_table = Chat
blacklisted_user_table = BlacklistedUser
sudo_user_table = SudoUser
db = DATABASE
# returns a ChatWrapper for a given chat ID

View File

@ -2,6 +2,7 @@ import asyncio
import inspect
import io
import os
import sys
from datetime import timedelta
from platform import python_version
from time import time
@ -125,12 +126,34 @@ async def sysd(event):
async def alive(event):
alive_format = "**Telethon version:** {0}\n" \
"**Python version:** {1}\n" \
"**Memory usage:** {2}MiB\n" \
"**Memory usage:** {2} MiB\n" \
"**Uptime:** {3}"
mem_usage = int(psutil.Process(os.getpid()).memory_info().rss / 1048576)
await event.reply(
alive_format.format(
version.__version__,
python_version(),
int(psutil.Process(os.getpid()).memory_info().rss / 1048576),
timedelta(seconds=int(time() - startup_time))
)
)
await event.reply(alive_format.format(version.__version__, python_version(), mem_usage, timedelta(seconds=int(time() - startup_time))))
@ldr.add("dbstat", owner=True, hide_help=True)
async def dbstat(event):
dbstat_format = "**Size on disk:** {0} MiB\n" \
"**Chat count:** {1}\n" \
"**Cache memory usage:** {2} MiB\n" \
"**Cached chat count:** {3}"
await event.reply(
dbstat_format.format(
round(os.stat("database.sqlite").st_size / 1048576, 2),
ldr.db.chat_table.select().count(),
round(sys.getsizeof(ldr.db.cached_chat_wrappers) / 1048576, 2),
len(ldr.db.cached_chat_wrappers)
)
)
@ldr.add("shutdown", pattern_extra="(f|)", owner=True, hide_help=True)