28 lines
949 B
Python
28 lines
949 B
Python
|
|
import psutil
|
||
|
|
import time
|
||
|
|
|
||
|
|
class MeetingRoom:
|
||
|
|
def __init__(self):
|
||
|
|
self.agents = {
|
||
|
|
"飞行侠": "监测到云端气流平稳,负载指数:{cpu}%。",
|
||
|
|
"道童": "禀告老师,内存净土尚余 {mem}%,宜开炉炼丹。",
|
||
|
|
"守望者": "吾在此守望,暂无幽灵进程侵扰。"
|
||
|
|
}
|
||
|
|
|
||
|
|
def get_status(self):
|
||
|
|
cpu = psutil.cpu_percent()
|
||
|
|
mem = psutil.virtual_memory().percent
|
||
|
|
# 气运流转:按秒取模决定谁说话
|
||
|
|
agent_names = list(self.agents.keys())
|
||
|
|
current = agent_names[int(time.time()) % len(agent_names)]
|
||
|
|
|
||
|
|
# 填充角色的独门台词
|
||
|
|
raw_msg = self.agents[current]
|
||
|
|
msg = raw_msg.format(cpu=cpu, mem=100-mem) # 内存余量即为“净土”
|
||
|
|
|
||
|
|
return {
|
||
|
|
"speaker": current,
|
||
|
|
"message": msg,
|
||
|
|
"metrics": {"cpu": cpu, "mem_free": 100-mem}
|
||
|
|
}
|