Add docker stats view

This commit is contained in:
2026-02-08 01:59:59 +03:00
parent c8db1be2d8
commit 9ced16cfbd
2 changed files with 36 additions and 1 deletions

View File

@@ -77,6 +77,41 @@ async def ds(msg: Message):
await cmd_docker_status(msg) await cmd_docker_status(msg)
@dp.message(F.text == "📈 Stats")
async def dstats(msg: Message):
if not is_admin_msg(msg):
return
if not DOCKER_MAP:
await msg.answer(
"⚠️ DOCKER_MAP пуст.\n"
"Контейнеры не обнаружены.",
reply_markup=docker_kb,
)
return
names = list(DOCKER_MAP.values())
fmt = "{{.Name}}|{{.CPUPerc}}|{{.MemUsage}}|{{.NetIO}}|{{.BlockIO}}"
rc, out = await docker_cmd(["stats", "--no-stream", "--format", fmt] + names)
if rc != 0:
await msg.answer(out, reply_markup=docker_kb)
return
lines = [line.strip() for line in out.splitlines() if line.strip()]
if not lines:
await msg.answer("📈 Stats\n\n(no data)", reply_markup=docker_kb)
return
rows = []
for line in lines:
parts = line.split("|")
if len(parts) != 5:
continue
name, cpu, mem, net, blk = parts
rows.append(f"{name}: CPU {cpu}, MEM {mem}, NET {net}, IO {blk}")
body = "\n".join(rows) if rows else "(no data)"
await msg.answer(f"📈 **Docker stats**\n```\n{body}\n```", reply_markup=docker_kb, parse_mode="Markdown")
@dp.message(F.text, F.func(lambda msg: msg.from_user and msg.from_user.id in LOG_FILTER_PENDING)) @dp.message(F.text, F.func(lambda msg: msg.from_user and msg.from_user.id in LOG_FILTER_PENDING))
async def log_filter_input(msg: Message): async def log_filter_input(msg: Message):
if not is_admin_msg(msg): if not is_admin_msg(msg):

View File

@@ -20,7 +20,7 @@ docker_kb = ReplyKeyboardMarkup(
keyboard=[ keyboard=[
[KeyboardButton(text="🐳 Status"), KeyboardButton(text="🧰 Arcane")], [KeyboardButton(text="🐳 Status"), KeyboardButton(text="🧰 Arcane")],
[KeyboardButton(text="🔄 Restart"), KeyboardButton(text="📜 Logs")], [KeyboardButton(text="🔄 Restart"), KeyboardButton(text="📜 Logs")],
[KeyboardButton(text="⬅️ Назад")], [KeyboardButton(text="📈 Stats"), KeyboardButton(text="⬅️ Назад")],
], ],
resize_keyboard=True, resize_keyboard=True,
) )