mirror of
https://github.com/Nick80835/microbot
synced 2025-08-30 05:58:23 +00:00
add db statistics command
This commit is contained in:
parent
05a3b5a14e
commit
b5c9ecdb62
@ -121,6 +121,9 @@ class ChatWrapper():
|
|||||||
|
|
||||||
class Database():
|
class Database():
|
||||||
cached_chat_wrappers = {}
|
cached_chat_wrappers = {}
|
||||||
|
chat_table = Chat
|
||||||
|
blacklisted_user_table = BlacklistedUser
|
||||||
|
sudo_user_table = SudoUser
|
||||||
db = DATABASE
|
db = DATABASE
|
||||||
|
|
||||||
# returns a ChatWrapper for a given chat ID
|
# returns a ChatWrapper for a given chat ID
|
||||||
|
@ -2,6 +2,7 @@ import asyncio
|
|||||||
import inspect
|
import inspect
|
||||||
import io
|
import io
|
||||||
import os
|
import os
|
||||||
|
import sys
|
||||||
from datetime import timedelta
|
from datetime import timedelta
|
||||||
from platform import python_version
|
from platform import python_version
|
||||||
from time import time
|
from time import time
|
||||||
@ -125,12 +126,34 @@ async def sysd(event):
|
|||||||
async def alive(event):
|
async def alive(event):
|
||||||
alive_format = "**Telethon version:** {0}\n" \
|
alive_format = "**Telethon version:** {0}\n" \
|
||||||
"**Python version:** {1}\n" \
|
"**Python version:** {1}\n" \
|
||||||
"**Memory usage:** {2}MiB\n" \
|
"**Memory usage:** {2} MiB\n" \
|
||||||
"**Uptime:** {3}"
|
"**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)
|
@ldr.add("shutdown", pattern_extra="(f|)", owner=True, hide_help=True)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user