Add ZFS vdev exposure in API and frontend
This commit is contained in:
@@ -264,7 +264,7 @@ function TableView({ enclosure, onSelect, selectedSerial, t }) {
|
|||||||
<table style={{ width: "100%", borderCollapse: "separate", borderSpacing: "0 4px", fontSize: 13 }}>
|
<table style={{ width: "100%", borderCollapse: "separate", borderSpacing: "0 4px", fontSize: 13 }}>
|
||||||
<thead>
|
<thead>
|
||||||
<tr style={{ textAlign: "left", color: t.textSecondary, fontSize: 11, textTransform: "uppercase", letterSpacing: 0.8 }}>
|
<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>
|
<th key={h} style={{ padding: "6px 10px", fontWeight: 600, borderBottom: `2px solid ${t.divider}` }}>{h}</th>
|
||||||
))}
|
))}
|
||||||
</tr>
|
</tr>
|
||||||
@@ -304,6 +304,16 @@ function TableView({ enclosure, onSelect, selectedSerial, t }) {
|
|||||||
<span style={{ fontSize: 11, color: t.textMuted, fontStyle: "italic" }}>{"\u2014"}</span>
|
<span style={{ fontSize: 11, color: t.textMuted, fontStyle: "italic" }}>{"\u2014"}</span>
|
||||||
)}
|
)}
|
||||||
</td>
|
</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", 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", 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>
|
<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}
|
{d.zfs_pool}
|
||||||
</span>
|
</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={{
|
<span style={{
|
||||||
fontSize: 10, fontWeight: 600, color: t.health.healthy.text, opacity: 0.7,
|
fontSize: 10, fontWeight: 600, color: t.health.healthy.text, opacity: 0.7,
|
||||||
background: t.health.healthy.border + "33", padding: "2px 6px", borderRadius: 4,
|
background: t.health.healthy.border + "33", padding: "2px 6px", borderRadius: 4,
|
||||||
|
|||||||
@@ -33,6 +33,7 @@ class DriveDetail(BaseModel):
|
|||||||
uncorrectable_errors: int | None = None
|
uncorrectable_errors: int | None = None
|
||||||
wear_leveling_percent: int | None = None
|
wear_leveling_percent: int | None = None
|
||||||
zfs_pool: str | None = None
|
zfs_pool: str | None = None
|
||||||
|
zfs_vdev: str | None = None
|
||||||
smart_attributes: list[dict] = []
|
smart_attributes: list[dict] = []
|
||||||
|
|
||||||
|
|
||||||
@@ -51,6 +52,7 @@ class DriveHealthSummary(BaseModel):
|
|||||||
pending_sectors: int | None = None
|
pending_sectors: int | None = None
|
||||||
uncorrectable_errors: int | None = None
|
uncorrectable_errors: int | None = None
|
||||||
zfs_pool: str | None = None
|
zfs_pool: str | None = None
|
||||||
|
zfs_vdev: str | None = None
|
||||||
health_status: str = "healthy"
|
health_status: str = "healthy"
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -19,6 +19,9 @@ async def get_drive_detail(device: str):
|
|||||||
raise HTTPException(status_code=502, detail=data["error"])
|
raise HTTPException(status_code=502, detail=data["error"])
|
||||||
|
|
||||||
pool_map = await get_zfs_pool_map()
|
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)
|
return DriveDetail(**data)
|
||||||
|
|||||||
@@ -93,7 +93,8 @@ async def get_overview():
|
|||||||
reallocated_sectors=sd.get("reallocated_sectors"),
|
reallocated_sectors=sd.get("reallocated_sectors"),
|
||||||
pending_sectors=sd.get("pending_sectors"),
|
pending_sectors=sd.get("pending_sectors"),
|
||||||
uncorrectable_errors=sd.get("uncorrectable_errors"),
|
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,
|
health_status=health_status,
|
||||||
)
|
)
|
||||||
elif s["populated"]:
|
elif s["populated"]:
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
import asyncio
|
import asyncio
|
||||||
import os
|
import os
|
||||||
import logging
|
import logging
|
||||||
|
import re
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
@@ -8,10 +9,11 @@ logger = logging.getLogger(__name__)
|
|||||||
ZPOOL_BIN = os.environ.get("ZPOOL_BIN", "zpool")
|
ZPOOL_BIN = os.environ.get("ZPOOL_BIN", "zpool")
|
||||||
|
|
||||||
|
|
||||||
async def get_zfs_pool_map() -> dict[str, str]:
|
async def get_zfs_pool_map() -> dict[str, dict]:
|
||||||
"""Return a dict mapping device names to ZFS pool names.
|
"""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 = {}
|
pool_map = {}
|
||||||
try:
|
try:
|
||||||
@@ -33,19 +35,49 @@ async def get_zfs_pool_map() -> dict[str, str]:
|
|||||||
return pool_map
|
return pool_map
|
||||||
|
|
||||||
current_pool = None
|
current_pool = None
|
||||||
|
current_vdev = None
|
||||||
|
in_config = False
|
||||||
|
|
||||||
for line in stdout.decode().splitlines():
|
for line in stdout.decode().splitlines():
|
||||||
stripped = line.strip()
|
stripped = line.strip()
|
||||||
|
|
||||||
if stripped.startswith("pool:"):
|
if stripped.startswith("pool:"):
|
||||||
current_pool = stripped.split(":", 1)[1].strip()
|
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()
|
parts = stripped.split()
|
||||||
dev_path = parts[0]
|
dev_path = parts[0]
|
||||||
try:
|
try:
|
||||||
real = os.path.realpath(dev_path)
|
real = os.path.realpath(dev_path)
|
||||||
dev_name = os.path.basename(real)
|
dev_name = os.path.basename(real)
|
||||||
# Strip partition numbers (sda1 -> sda)
|
# Strip partition numbers (sda1 -> sda)
|
||||||
dev_name = dev_name.rstrip("0123456789")
|
dev_name = re.sub(r'\d+$', '', dev_name)
|
||||||
pool_map[dev_name] = current_pool
|
pool_map[dev_name] = {
|
||||||
|
"pool": current_pool,
|
||||||
|
"vdev": current_vdev or current_pool,
|
||||||
|
}
|
||||||
except Exception:
|
except Exception:
|
||||||
pass
|
pass
|
||||||
except FileNotFoundError:
|
except FileNotFoundError:
|
||||||
|
|||||||
Reference in New Issue
Block a user