summaryrefslogtreecommitdiff
path: root/ATRI/plugins
diff options
context:
space:
mode:
authorKyomotoi <[email protected]>2022-12-02 08:53:23 +0800
committerKyomotoi <[email protected]>2022-12-02 08:53:23 +0800
commit4436fa3b6ea4bb54198c0fcc247e48d75942f829 (patch)
tree0cddecd5a60a596c9546aa2d017d50e1e7a5f5be /ATRI/plugins
parent1ee2eae499b79bf0d22212184bffd57d873826cc (diff)
downloadATRI-4436fa3b6ea4bb54198c0fcc247e48d75942f829.tar.gz
ATRI-4436fa3b6ea4bb54198c0fcc247e48d75942f829.tar.bz2
ATRI-4436fa3b6ea4bb54198c0fcc247e48d75942f829.zip
🔥 删除弃用的代码
Diffstat (limited to 'ATRI/plugins')
-rw-r--r--ATRI/plugins/status/__init__.py45
-rw-r--r--ATRI/plugins/status/data_source.py88
2 files changed, 0 insertions, 133 deletions
diff --git a/ATRI/plugins/status/__init__.py b/ATRI/plugins/status/__init__.py
deleted file mode 100644
index 08e099c..0000000
--- a/ATRI/plugins/status/__init__.py
+++ /dev/null
@@ -1,45 +0,0 @@
-from nonebot import get_bot
-
-from ATRI import conf
-from ATRI.log import log
-from ATRI.service import Service
-from ATRI.utils.apscheduler import scheduler
-
-from .data_source import Status
-
-
-plugin = Service("状态").document("检查自身状态")
-
-
-ping = plugin.on_command("/ping", "检测bot简单信息处理速度")
-
-
-async def _():
- await ping.finish(Status.ping())
-
-
-status = plugin.on_command("/status", "查看运行资源占用")
-
-
-async def _():
- msg, _ = Status.get_status()
- await status.finish(msg)
-
-
-info_msg = "アトリは高性能ですから!"
-
-
[email protected]_job("interval", name="状态检查", minutes=10, misfire_grace_time=15) # type: ignore
-async def _():
- log.info("开始检查资源消耗...")
- msg, stat = Status.get_status()
- if not stat:
- log.warning(msg)
-
- bot = get_bot()
- for super in conf.BotConfig.superusers:
- await bot.send_private_msg(user_id=super, message=msg)
-
- log.info("资源消耗正常")
diff --git a/ATRI/plugins/status/data_source.py b/ATRI/plugins/status/data_source.py
deleted file mode 100644
index 10093c4..0000000
--- a/ATRI/plugins/status/data_source.py
+++ /dev/null
@@ -1,88 +0,0 @@
-import os
-import time
-import psutil
-from datetime import datetime
-
-from ATRI.message import MessageBuilder
-from ATRI.exceptions import GetStatusError
-
-
-_STATUS_MSG = (
- MessageBuilder("[Status Overview]")
- .text("[CPU: {b_cpu}% of {p_cpu}%]")
- .text("[Memory: {b_mem} of {p_mem}%]")
- .text("[Disk usage: {p_disk}%]")
- .text("")
- .text("[Net sent: {inteSENT}MB]")
- .text("[Net recv: {inteRECV}MB]")
- .text("")
- .text("[Run Duration]")
- .text("[Bot: {bot_time}]")
- .text("[Platform: {boot_time}]")
- .text("{msg}")
- .done()
-)
-
-
-class Status:
- @staticmethod
- def ping() -> str:
- return "I'm fine."
-
- @staticmethod
- def get_status() -> tuple:
- try:
- cpu = psutil.cpu_percent(interval=1)
- mem = psutil.virtual_memory().percent
- disk = psutil.disk_usage("/").percent
- inte_send = psutil.net_io_counters().bytes_sent / 1000000 # type: ignore
- inte_recv = psutil.net_io_counters().bytes_recv / 1000000 # type: ignore
-
- process = psutil.Process(os.getpid())
- b_cpu = process.cpu_percent(interval=1)
- b_mem = process.memory_percent(memtype="rss")
-
- now = time.time()
- boot = psutil.boot_time()
- b = process.create_time()
- boot_time = str(
- datetime.utcfromtimestamp(now).replace(microsecond=0)
- - datetime.utcfromtimestamp(boot).replace(microsecond=0)
- )
- bot_time = str(
- datetime.utcfromtimestamp(now).replace(microsecond=0)
- - datetime.utcfromtimestamp(b).replace(microsecond=0)
- )
- except Exception:
- raise GetStatusError("Failed to get status.")
-
- msg = "アトリは、高性能ですから!"
- if cpu > 90: # type: ignore
- msg = "咱感觉有些头晕..."
- is_ok = False
- if mem > 90:
- msg = "咱感觉有点头晕并且有点累..."
- is_ok = False
- elif mem > 90:
- msg = "咱感觉有点累..."
- is_ok = False
- elif disk > 90:
- msg = "咱感觉身体要被塞满了..."
- is_ok = False
- else:
- is_ok = True
-
- msg0 = _STATUS_MSG.format(
- p_cpu=cpu,
- p_mem=mem,
- p_disk=disk,
- b_cpu=b_cpu,
- b_mem="%.1f%%" % b_mem,
- inteSENT=inte_send,
- inteRECV=inte_recv,
- bot_time=bot_time,
- boot_time=boot_time,
- msg=msg,
- )
-
- return msg0, is_ok