feat: remove power monitoring feature
This commit is contained in:
1 parent
593b8011c6
commit
e49a2f8f03
6 files changed
+3
-123
No files matched your search
@@ -43,17 +43,6 @@ def _fmt_uptime(seconds: float) -> str:
|
||||
return f"{d}天{h}小时{m}分" if d else f"{h}小时{m}分"
|
||||
|
||||
|
||||
def _power_str(p: dict) -> str:
|
||||
if p["total_watts"] is not None:
|
||||
src = {"battery": "电池", "rapl": "RAPL"}.get(p["source"], p["source"])
|
||||
extra = f" (电池 {p['battery']}W)" if p["battery"] is not None and p["source"] == "rapl" else ""
|
||||
return f"{p['total_watts']}W [{src}]{extra}"
|
||||
if p.get("battery_percent") is not None:
|
||||
state = "充电中" if p.get("plugged") else "放电中"
|
||||
return f"电量 {p['battery_percent']}% ({state}),功率不可测"
|
||||
return "不支持(需要电池或Intel RAPL)"
|
||||
|
||||
|
||||
def _hottest(temps: dict):
|
||||
flat = [t for entries in temps.values() for t in entries]
|
||||
return max(flat, key=lambda t: t["current"]) if flat else None
|
||||
@@ -66,7 +55,6 @@ def fmt_status(s: dict) -> str:
|
||||
d = s["disk"][0] if s["disk"] else None
|
||||
return templates.render(
|
||||
"status",
|
||||
power=_power_str(s["power"]),
|
||||
cpu_total=f"{sum(c['per_core']):.1f}%",
|
||||
cpu_max=f"{c['cores'] * 100}%",
|
||||
cpu_avg=f"{c['percent']}",
|
||||
@@ -83,26 +71,6 @@ def fmt_status(s: dict) -> str:
|
||||
)
|
||||
|
||||
|
||||
def fmt_power(s: dict) -> str:
|
||||
p = s["power"]
|
||||
if p["total_watts"] is None and p["battery"] is None and p.get("battery_percent") is None:
|
||||
return templates.render(
|
||||
"power",
|
||||
power=("未获取到功耗数据。支持的来源:笔记本电池 /sys/class/power_supply 或系统电池接口,"
|
||||
"Intel RAPL /sys/class/powercap (AMD/多数虚拟机/台式机不支持)。"),
|
||||
)
|
||||
lines = []
|
||||
if p["battery"] is not None:
|
||||
lines.append(f"电池功率: {p['battery']}W")
|
||||
if p.get("battery_percent") is not None:
|
||||
state = "充电中" if p.get("plugged") else "放电中"
|
||||
lines.append(f"电量: {p['battery_percent']}% ({state})")
|
||||
if p["domains"]:
|
||||
lines.append("RAPL 域:")
|
||||
lines += [f" {name}: {watts}W" for name, watts in p["domains"].items()]
|
||||
return templates.render("power", power="\n".join(lines) or "无数据")
|
||||
|
||||
|
||||
def fmt_top(s: dict) -> str:
|
||||
if not s["top"]:
|
||||
return templates.render("top", top_n=10, top_list="无数据")
|
||||
@@ -133,7 +101,6 @@ def fmt_net(net: dict) -> str:
|
||||
# 命令别名 -> 动作;只有此表内的词会触发,其他消息一律忽略
|
||||
COMMANDS = {
|
||||
"status": "status", "状态": "status",
|
||||
"power": "power", "功耗": "power",
|
||||
"top": "top", "进程": "top",
|
||||
"temp": "temp", "温度": "temp",
|
||||
"net": "net", "网络": "net",
|
||||
@@ -234,8 +201,6 @@ class Bot:
|
||||
try:
|
||||
if action == "status":
|
||||
return fmt_status(monitor.get_status())
|
||||
if action == "power":
|
||||
return fmt_power({"power": monitor.get_power()})
|
||||
if action == "top":
|
||||
return fmt_top({"top": monitor.get_top_processes(10)})
|
||||
if action == "temp":
|
||||
|
||||
Reference in new issue
Block a user