39 lines
1.9 KiB
Python
39 lines
1.9 KiB
Python
from __future__ import annotations
|
|
|
|
from app.core.db import get_db
|
|
from app.services.runtime_status_service import get_runtime_status
|
|
|
|
|
|
def fetch_overview() -> dict:
|
|
queries = {
|
|
"domains_total": "select count(*) from domains",
|
|
"pending_total": "select count(*) from domains where detect_status = 0",
|
|
"completed_total": "select count(*) from domains where detect_status = 1",
|
|
"running_total": "select count(*) from domains where detect_status = 2",
|
|
"blacklist_total": "select count(*) from domains where detect_status = 3",
|
|
"failed_total": "select count(*) from domains where detect_status = 4",
|
|
"sensitive_words_total": "select count(*) from sensitive_words",
|
|
}
|
|
result: dict[str, int | str] = {}
|
|
with get_db() as conn:
|
|
with conn.cursor() as cur:
|
|
for key, query in queries.items():
|
|
try:
|
|
cur.execute(query)
|
|
result[key] = cur.fetchone()[0]
|
|
except Exception:
|
|
result[key] = 0
|
|
runtime = get_runtime_status()
|
|
cluster_summary = ((runtime.get("cluster") or {}).get("summary") or {})
|
|
online_worker_nodes = int(cluster_summary.get("online_worker_nodes", 0) or 0)
|
|
dedicated_online_worker_nodes = int(cluster_summary.get("dedicated_online_worker_nodes", 0) or 0)
|
|
result["worker_status"] = "online" if runtime["worker"]["running"] else "offline"
|
|
result["local_worker_status"] = result["worker_status"]
|
|
result["cluster_worker_status"] = "online" if online_worker_nodes > 0 else "offline"
|
|
result["cluster_online_worker_nodes"] = online_worker_nodes
|
|
result["cluster_dedicated_online_worker_nodes"] = dedicated_online_worker_nodes
|
|
result["cluster_online_control_nodes"] = int(cluster_summary.get("online_control_nodes", 0) or 0)
|
|
result["api_status"] = "online"
|
|
result["worker_mode"] = runtime["worker"]["mode"]
|
|
return result
|