Add ZFS vdev exposure in API and frontend

This commit is contained in:
2026-03-07 04:14:14 +00:00
parent 10de5563b2
commit 3ef7061aa5
5 changed files with 65 additions and 9 deletions

View File

@@ -264,7 +264,7 @@ function TableView({ enclosure, onSelect, selectedSerial, t }) {
<table style={{ width: "100%", borderCollapse: "separate", borderSpacing: "0 4px", fontSize: 13 }}>
<thead>
<tr style={{ textAlign: "left", color: t.textSecondary, fontSize: 11, textTransform: "uppercase", letterSpacing: 0.8 }}>
{["Slot", "Device", "Model", "Serial", "WWN", "FW", "Capacity", "Pool", "Temp", "Hours", "Health"].map((h) => (
{["Slot", "Device", "Model", "Serial", "WWN", "FW", "Capacity", "Pool", "Vdev", "Temp", "Hours", "Health"].map((h) => (
<th key={h} style={{ padding: "6px 10px", fontWeight: 600, borderBottom: `2px solid ${t.divider}` }}>{h}</th>
))}
</tr>
@@ -304,6 +304,16 @@ function TableView({ enclosure, onSelect, selectedSerial, t }) {
<span style={{ fontSize: 11, color: t.textMuted, fontStyle: "italic" }}>{"\u2014"}</span>
)}
</td>
<td style={{ padding: "8px 10px" }}>
{d.zfs_vdev ? (
<span style={{
fontSize: 11, fontWeight: 500, color: t.textSecondary,
fontFamily: "'JetBrains Mono', monospace",
}}>{d.zfs_vdev}</span>
) : (
<span style={{ fontSize: 11, color: t.textMuted, fontStyle: "italic" }}>{"\u2014"}</span>
)}
</td>
<td style={{ padding: "8px 10px", fontWeight: 600, color: d.temperature_c >= 40 ? t.health.warning.text : t.text }}>{d.temperature_c != null ? `${d.temperature_c}\u00B0C` : "\u2014"}</td>
<td style={{ padding: "8px 10px", color: t.text }}>{formatHours(d.power_on_hours)}</td>
<td style={{ padding: "8px 10px", borderRadius: "0 6px 6px 0" }}><StatusPill status={healthStatus} t={t} /></td>
@@ -413,6 +423,14 @@ function DriveDetail({ slot, onClose, t }) {
}}>
{d.zfs_pool}
</span>
{d.zfs_vdev && (
<span style={{
fontSize: 12, fontWeight: 600, color: t.health.healthy.text, opacity: 0.85,
fontFamily: "'JetBrains Mono', monospace",
}}>
/ {d.zfs_vdev}
</span>
)}
<span style={{
fontSize: 10, fontWeight: 600, color: t.health.healthy.text, opacity: 0.7,
background: t.health.healthy.border + "33", padding: "2px 6px", borderRadius: 4,

View File

@@ -33,6 +33,7 @@ class DriveDetail(BaseModel):
uncorrectable_errors: int | None = None
wear_leveling_percent: int | None = None
zfs_pool: str | None = None
zfs_vdev: str | None = None
smart_attributes: list[dict] = []
@@ -51,6 +52,7 @@ class DriveHealthSummary(BaseModel):
pending_sectors: int | None = None
uncorrectable_errors: int | None = None
zfs_pool: str | None = None
zfs_vdev: str | None = None
health_status: str = "healthy"

View File

@@ -19,6 +19,9 @@ async def get_drive_detail(device: str):
raise HTTPException(status_code=502, detail=data["error"])
pool_map = await get_zfs_pool_map()
data["zfs_pool"] = pool_map.get(device)
zfs_info = pool_map.get(device)
if zfs_info:
data["zfs_pool"] = zfs_info["pool"]
data["zfs_vdev"] = zfs_info["vdev"]
return DriveDetail(**data)

View File

@@ -93,7 +93,8 @@ async def get_overview():
reallocated_sectors=sd.get("reallocated_sectors"),
pending_sectors=sd.get("pending_sectors"),
uncorrectable_errors=sd.get("uncorrectable_errors"),
zfs_pool=pool_map.get(sd["device"]),
zfs_pool=pool_map.get(sd["device"], {}).get("pool"),
zfs_vdev=pool_map.get(sd["device"], {}).get("vdev"),
health_status=health_status,
)
elif s["populated"]:

View File

@@ -1,6 +1,7 @@
import asyncio
import os
import logging
import re
logger = logging.getLogger(__name__)
@@ -8,10 +9,11 @@ logger = logging.getLogger(__name__)
ZPOOL_BIN = os.environ.get("ZPOOL_BIN", "zpool")
async def get_zfs_pool_map() -> dict[str, str]:
"""Return a dict mapping device names to ZFS pool names.
async def get_zfs_pool_map() -> dict[str, dict]:
"""Return a dict mapping device names to ZFS pool and vdev info.
e.g. {"sda": "tank", "sdb": "tank", "sdc": "fast"}
e.g. {"sda": {"pool": "tank", "vdev": "raidz2-0"},
"sdb": {"pool": "fast", "vdev": "mirror-0"}}
"""
pool_map = {}
try:
@@ -33,19 +35,49 @@ async def get_zfs_pool_map() -> dict[str, str]:
return pool_map
current_pool = None
current_vdev = None
in_config = False
for line in stdout.decode().splitlines():
stripped = line.strip()
if stripped.startswith("pool:"):
current_pool = stripped.split(":", 1)[1].strip()
elif current_pool and "/dev/" in stripped:
current_vdev = None
in_config = False
continue
if stripped.startswith("NAME") and "STATE" in stripped:
in_config = True
continue
if stripped.startswith("errors:") or stripped == "":
if stripped.startswith("errors:"):
in_config = False
continue
if not in_config or not current_pool:
continue
# Count leading tab depth to distinguish pool/vdev/device lines.
# Pool name = 1 tab, vdev = 2 tabs, device = 3+ tabs
tab_count = len(line) - len(line.lstrip('\t'))
if tab_count == 2 and "/dev/" not in stripped:
# This is a vdev line (mirror-0, raidz2-0, etc.)
current_vdev = stripped.split()[0]
elif "/dev/" in stripped:
parts = stripped.split()
dev_path = parts[0]
try:
real = os.path.realpath(dev_path)
dev_name = os.path.basename(real)
# Strip partition numbers (sda1 -> sda)
dev_name = dev_name.rstrip("0123456789")
pool_map[dev_name] = current_pool
dev_name = re.sub(r'\d+$', '', dev_name)
pool_map[dev_name] = {
"pool": current_pool,
"vdev": current_vdev or current_pool,
}
except Exception:
pass
except FileNotFoundError: