feat: show monitor availability column

This commit is contained in:
2026-06-09 16:09:26 +08:00
parent 16f50172ca
commit 98410b0fe0
5 changed files with 77 additions and 6 deletions
+22 -3
View File
@@ -263,6 +263,23 @@ def monitor_detail(row: dict[str, Any], status_payload: dict[str, Any]) -> str:
return detail
def monitor_availability(row: dict[str, Any], status_payload: dict[str, Any]) -> str:
item = matching_monitor(row, status_payload)
if not item:
return "-"
if item.get("enabled") is False:
return "disabled"
raw_status = str(item.get("latest_status") or "").strip().lower()
if not raw_status:
return "unknown"
kind = status_kind(raw_status)
if kind == "ok":
return "ok"
if kind == "failed":
return "failed"
return raw_status
def window_for(account: dict[str, Any], window_id: str) -> dict[str, Any]:
for window in account.get("windows") or []:
if isinstance(window, dict) and window.get("id") == window_id:
@@ -388,7 +405,7 @@ def print_once(payload: dict[str, Any], filter_text: str = "", status_payload: d
print(summary_line(payload))
if status_payload or status_error:
print(monitor_summary(status_payload or {}, status_error))
print("name provider group daily today tokens req kind 5h 7d reset status")
print("name provider group daily today tokens req kind 5h 7d reset status availability")
for row in normalize_account_rows(payload, filter_text):
print(
f"{row['name'][:30]:<30} "
@@ -402,7 +419,8 @@ def print_once(payload: dict[str, Any], filter_text: str = "", status_payload: d
f"{row['five_hour']:<9} "
f"{row['weekly']:<9} "
f"{row['reset']:<11} "
f"{row['status']}"
f"{row['status']:<10} "
f"{monitor_availability(row, status_payload or {})}"
)
@@ -449,7 +467,7 @@ def run_textual(api_url: str, status_url: str, refresh_seconds: int, timeout: in
table = self.query_one("#accounts", DataTable)
table.cursor_type = "row"
table.zebra_stripes = True
table.add_columns("Name", "Provider", "Group", "Daily", "Today", "Tokens", "Req", "Kind", "5h", "7d", "Reset", "Status")
table.add_columns("Name", "Provider", "Group", "Daily", "Today", "Tokens", "Req", "Kind", "5h", "7d", "Reset", "Status", "Availability")
self.refresh_data(refresh=True)
self.set_interval(refresh_seconds, self.refresh_data)
@@ -497,6 +515,7 @@ def run_textual(api_url: str, status_url: str, refresh_seconds: int, timeout: in
row["weekly"],
row["reset"],
row["status"],
monitor_availability(row, self.status_payload),
key=key,
)
self.query_one("#summary", Static).update(summary_line(self.payload))