Add hardware info in system
This commit is contained in:
@@ -4,7 +4,7 @@ from aiogram.types import Message, CallbackQuery, InlineKeyboardMarkup, InlineKe
|
||||
from app import dp, cfg
|
||||
from auth import is_admin_msg
|
||||
from keyboards import system_kb
|
||||
from system_checks import security, disks
|
||||
from system_checks import security, disks, hardware
|
||||
from services.http_checks import get_url_checks, check_url
|
||||
from services.queue import enqueue
|
||||
from services.updates import list_updates, apply_updates
|
||||
@@ -113,6 +113,12 @@ async def reboot_request(msg: Message):
|
||||
await msg.answer("⚠️ Confirm reboot?", reply_markup=kb)
|
||||
|
||||
|
||||
@dp.message(F.text == "🧱 Hardware")
|
||||
async def hw(msg: Message):
|
||||
if is_admin_msg(msg):
|
||||
await msg.answer(hardware(), reply_markup=system_kb)
|
||||
|
||||
|
||||
def _updates_kb(page: int, total_pages: int) -> InlineKeyboardMarkup:
|
||||
buttons = []
|
||||
if total_pages > 1:
|
||||
|
||||
@@ -57,8 +57,7 @@ system_kb = ReplyKeyboardMarkup(
|
||||
[KeyboardButton(text="💽 Disks"), KeyboardButton(text="🔐 Security")],
|
||||
[KeyboardButton(text="🌐 URLs"), KeyboardButton(text="📈 Metrics")],
|
||||
[KeyboardButton(text="📦 Updates"), KeyboardButton(text="⬆️ Upgrade")],
|
||||
[KeyboardButton(text="🔄 Reboot")],
|
||||
[KeyboardButton(text="⬅️ Назад")],
|
||||
[KeyboardButton(text="🧱 Hardware"), KeyboardButton(text="🔄 Reboot"), KeyboardButton(text="⬅️ Назад")],
|
||||
],
|
||||
resize_keyboard=True,
|
||||
)
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import subprocess
|
||||
import os
|
||||
|
||||
|
||||
def _cmd(cmd: str) -> str:
|
||||
@@ -144,3 +145,44 @@ def disks() -> str:
|
||||
lines.append(f"{icon} {d} — {health}, 🌡 {temp}")
|
||||
|
||||
return "\n".join(lines)
|
||||
|
||||
|
||||
def hardware() -> str:
|
||||
cpu_model = "n/a"
|
||||
try:
|
||||
with open("/proc/cpuinfo", "r") as f:
|
||||
for line in f:
|
||||
if line.lower().startswith("model name"):
|
||||
cpu_model = line.split(":", 1)[1].strip()
|
||||
break
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
mem_total = "n/a"
|
||||
swap_total = "n/a"
|
||||
try:
|
||||
with open("/proc/meminfo", "r") as f:
|
||||
for line in f:
|
||||
if line.startswith("MemTotal:"):
|
||||
mem_kb = int(line.split()[1])
|
||||
mem_total = f"{mem_kb / (1024**2):.2f} GiB"
|
||||
if line.startswith("SwapTotal:"):
|
||||
swap_kb = int(line.split()[1])
|
||||
swap_total = f"{swap_kb / (1024**2):.2f} GiB"
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
cores = os.cpu_count() or "n/a"
|
||||
uname = os.uname()
|
||||
|
||||
lines = [
|
||||
"🧱 Hardware",
|
||||
"",
|
||||
f"🧠 CPU: {cpu_model}",
|
||||
f"🧩 Cores: {cores}",
|
||||
f"💾 RAM: {mem_total}",
|
||||
f"🌀 Swap: {swap_total}",
|
||||
f"🧬 Arch: {uname.machine}",
|
||||
f"🐧 Kernel: {uname.release}",
|
||||
]
|
||||
return "\n".join(lines)
|
||||
|
||||
Reference in New Issue
Block a user