Skip to content

Commit

Permalink
Update server-info API
Browse files Browse the repository at this point in the history
  • Loading branch information
DoroWolf committed Dec 31, 2024
1 parent 64e8b37 commit cfddda6
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 1 deletion.
37 changes: 37 additions & 0 deletions bots/api/bot.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
import os
import psutil
import platform
import sys
import time
import uuid
from cpuinfo import get_cpu_info
from datetime import datetime, timedelta, UTC

import jwt
Expand Down Expand Up @@ -170,6 +173,40 @@ async def change_password(request: Request):
raise HTTPException(status_code=400, detail="bad request")


@app.get("/server-info")
async def server_info():
return {
"message": "success",
"os": {
"system": platform.system(),
"version": platform.version(),
"machine": platform.machine(),
"boot_time": psutil.boot_time(),
},
"bot": {
"running_time": (datetime.now() - started_time).total_seconds(),
"python_version": platform.python_version(),
"version": Info.version,
"web_render_local_status": Info.web_render_local_status,
"web_render_status": Info.web_render_status,
},
"cpu": {
"cpu_brand": get_cpu_info()["brand_raw"],
"cpu_percent": psutil.cpu_percent(interval=1), # 获取 CPU 使用率
},
"memory": {
"total": psutil.virtual_memory().total / (1024 * 1024), # 总内存
"used": psutil.virtual_memory().used / (1024 * 1024), # 已用内存
"percent": psutil.virtual_memory().percent, # 内存使用百分比
},
"disk": {
"total": psutil.disk_usage('/').total / (1024 * 1024 * 1024), # 磁盘总容量
"used": psutil.disk_usage('/').used / (1024 * 1024 * 1024), # 磁盘已使用容量
"percent": psutil.disk_usage('/').percent, # 磁盘使用百分比
}
}


@app.get("/config")
async def get_config_list():
try:
Expand Down
2 changes: 1 addition & 1 deletion core/bot_init.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

async def init_async(start_scheduler=True) -> None:
try:
Info.version = os.popen("git rev-parse HEAD", "r").read()
Info.version = os.popen("git rev-parse HEAD", "r").read().strip('\n')
except Exception:
Logger.warning("Failed to get Git commit hash, is it a Git repository?")
load_modules()
Expand Down

0 comments on commit cfddda6

Please sign in to comment.