diff --git a/handlers/docker.py b/handlers/docker.py index f5190b7..3c18583 100644 --- a/handlers/docker.py +++ b/handlers/docker.py @@ -77,6 +77,41 @@ async def ds(msg: Message): 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)) async def log_filter_input(msg: Message): if not is_admin_msg(msg): diff --git a/keyboards.py b/keyboards.py index 4bdb9a7..54c3b8d 100644 --- a/keyboards.py +++ b/keyboards.py @@ -20,7 +20,7 @@ docker_kb = ReplyKeyboardMarkup( keyboard=[ [KeyboardButton(text="🐳 Status"), KeyboardButton(text="🧰 Arcane")], [KeyboardButton(text="🔄 Restart"), KeyboardButton(text="📜 Logs")], - [KeyboardButton(text="⬅️ Назад")], + [KeyboardButton(text="📈 Stats"), KeyboardButton(text="⬅️ Назад")], ], resize_keyboard=True, )