mirror of
https://github.com/LiteyukiStudio/LiteyukiBot.git
synced 2024-11-11 05:17:24 +08:00
📝 添加字体原有版权声明
This commit is contained in:
parent
a38e2b887c
commit
5db29c7e2c
@ -146,6 +146,20 @@ async def get_bots_data(self_id: str = "0") -> dict:
|
||||
|
||||
async def get_hardware_data() -> dict:
|
||||
mem = psutil.virtual_memory()
|
||||
all_processes = psutil.Process().children(recursive=True)
|
||||
all_processes.append(psutil.Process())
|
||||
|
||||
mem_used_bot = 0
|
||||
process_mem = {}
|
||||
for process in all_processes:
|
||||
try:
|
||||
ps_name = process.name().replace(".exe", "")
|
||||
if ps_name not in process_mem:
|
||||
process_mem[ps_name] = 0
|
||||
process_mem[ps_name] += process.memory_info().rss
|
||||
mem_used_bot += process.memory_info().rss
|
||||
except Exception:
|
||||
pass
|
||||
swap = psutil.swap_memory()
|
||||
cpu_brand_raw = cpuinfo.get_cpu_info().get("brand_raw", "Unknown")
|
||||
if "AMD" in cpu_brand_raw:
|
||||
@ -157,13 +171,16 @@ async def get_hardware_data() -> dict:
|
||||
result = {
|
||||
"cpu" : {
|
||||
"percent": psutil.cpu_percent(),
|
||||
"name" : f"{brand} {cpuinfo.get_cpu_info().get('arch', 'Unknown')}"
|
||||
"name" : f"{brand} {cpuinfo.get_cpu_info().get('arch', 'Unknown')}",
|
||||
"cores" : psutil.cpu_count(logical=False),
|
||||
"threads": psutil.cpu_count(logical=True),
|
||||
"freq" : psutil.cpu_freq().current # MHz
|
||||
},
|
||||
"mem" : {
|
||||
"memory" : {
|
||||
"percent": mem.percent,
|
||||
"total" : mem.total,
|
||||
"used" : mem.used,
|
||||
"free" : mem.free
|
||||
"free" : mem.free,
|
||||
},
|
||||
"swap": {
|
||||
"percent": swap.percent,
|
||||
|
@ -59,6 +59,32 @@ function createPieChartOption(title, data) {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
function convertSize(size, precision = 2, addUnit = true, suffix = " XiB"): string {
|
||||
let isNegative = size < 0;
|
||||
size = Math.abs(size);
|
||||
let units = ["", "K", "M", "G", "T", "P", "E", "Z"];
|
||||
let unit = "";
|
||||
|
||||
for (let i = 0; i < units.length; i++) {
|
||||
if (size < 1024) {
|
||||
unit = units[i];
|
||||
break;
|
||||
}
|
||||
size /= 1024;
|
||||
}
|
||||
|
||||
if (isNegative) {
|
||||
size = -size;
|
||||
}
|
||||
|
||||
if (addUnit) {
|
||||
return size.toFixed(precision) + suffix.replace('X', unit);
|
||||
} else {
|
||||
return size;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建磁盘用量柱状图
|
||||
* @param title
|
||||
@ -141,6 +167,29 @@ function main() {
|
||||
document.body.insertBefore(liteyukiInfoDiv, document.getElementById('hardware-info')) // 插入对象
|
||||
|
||||
// 添加硬件信息
|
||||
const cpuData = hardwareData['cpu']
|
||||
const memData = hardwareData['memory']
|
||||
const swapData = hardwareData['swap']
|
||||
|
||||
const cpuTagArray = [
|
||||
cpuData['name'],
|
||||
`${cpuData['cores']}C ${cpuData['threads']}T`,
|
||||
`${(cpuData['freq'] / 1000).toFixed(2)}GHz`
|
||||
]
|
||||
|
||||
const memTagArray = [
|
||||
`Bot ${convertSize(memData['bot'])}`,
|
||||
`${localData['used']} ${convertSize(memData['used'])}`,
|
||||
`${localData['free']} ${convertSize(memData['free'])}`,
|
||||
`${localData['total']} ${convertSize(memData['total'])}`
|
||||
]
|
||||
|
||||
const swapTagArray = [
|
||||
`${localData['used']} ${convertSize(swapData['used'])}`,
|
||||
`${localData['free']} ${convertSize(swapData['free'])}`,
|
||||
`${localData['total']} ${convertSize(swapData['total'])}`
|
||||
]
|
||||
|
||||
}
|
||||
|
||||
main()
|
@ -4,14 +4,13 @@ colored==2.2.4
|
||||
dash==2.16.1
|
||||
GitPython==3.1.42
|
||||
httpx==0.27.0
|
||||
jieba==0.42.1
|
||||
nb-cli==1.4.1
|
||||
nonebot2[fastapi,httpx,websockets]==2.2.1
|
||||
nonebot-plugin-htmlrender==0.3.1
|
||||
nonebot-adapter-onebot==2.4.3
|
||||
nonebot-plugin-alconna==0.43.0
|
||||
nonebot_plugin_apscheduler==0.4.0
|
||||
packaging==21.4
|
||||
packaging==23.1
|
||||
playwright==1.17.2
|
||||
psutil==5.9.8
|
||||
py-cpuinfo==9.0.0
|
||||
|
Loading…
Reference in New Issue
Block a user