This commit is contained in:
Your Name
2026-04-17 15:13:46 +08:00
parent fe87c7b343
commit 0e096947fc
19 changed files with 791 additions and 151 deletions

View File

@@ -24,8 +24,11 @@
<span class="status-pill" :class="runtime.apiOnline ? 'online' : 'offline'">
API {{ runtime.apiOnline ? "在线" : "离线" }}
</span>
<span class="status-pill" :class="runtime.workerOnline ? 'online' : 'offline'">
Worker {{ runtime.workerOnline ? "在线" : "离线" }}
<span class="status-pill" :class="runtime.localWorkerOnline ? 'online' : 'offline'">
本机 Worker {{ runtime.localWorkerOnline ? "在线" : "离线" }}
</span>
<span class="status-pill" :class="runtime.effectiveWorkerNodes > 0 ? 'online' : 'offline'">
有效执行节点 {{ runtime.effectiveWorkerNodes }}
</span>
<span class="status-pill neutral">{{ runtime.workerMode }}</span>
</div>
@@ -53,7 +56,8 @@ const authStore = useAuthStore();
const runtime = ref({
apiOnline: false,
workerOnline: false,
localWorkerOnline: false,
effectiveWorkerNodes: 0,
workerMode: "windows-local"
});
let timer: number | null = null;
@@ -77,15 +81,18 @@ const title = computed(() => String(route.meta?.title || "概览"));
const loadRuntimeSummary = async () => {
try {
const response = await runtimeApi.status();
const summary = response.data?.cluster?.summary || {};
runtime.value = {
apiOnline: Boolean(response.data?.api?.pid),
workerOnline: Boolean(response.data?.worker?.running),
localWorkerOnline: Boolean(response.data?.worker?.running),
effectiveWorkerNodes: Number(summary.online_worker_nodes || 0),
workerMode: response.data?.worker?.mode || "windows-local"
};
} catch {
runtime.value = {
apiOnline: false,
workerOnline: false,
localWorkerOnline: false,
effectiveWorkerNodes: 0,
workerMode: "unknown"
};
}

View File

@@ -50,7 +50,8 @@ const stats = ref([
{ label: "待检测", value: "--", note: "当前待处理域名" },
{ label: "黑名单", value: "--", note: "命中风险域名" },
{ label: "API", value: "离线", note: "当前 API 运行状态" },
{ label: "Worker", value: "离线", note: "当前 Worker 运行状态" },
{ label: "本机 Worker", value: "离线", note: "当前节点本机 Worker 运行状态" },
{ label: "有效执行节点", value: "离线", note: "当前集群可承担检测任务的在线节点" },
{ label: "模式", value: "--", note: "当前 Worker 运行模式" }
]);
@@ -84,7 +85,12 @@ const loadOverview = async (showError = true) => {
{ label: "待检测", value: String(data.pending_total), note: "当前待处理域名" },
{ label: "黑名单", value: String(data.blacklist_total), note: "命中风险域名" },
{ label: "API", value: data.api_status, note: "当前 API 运行状态" },
{ label: "Worker", value: data.worker_status, note: "当前 Worker 运行状态" },
{ label: "本机 Worker", value: data.local_worker_status || data.worker_status, note: "当前节点本机 Worker 运行状态" },
{
label: "有效执行节点",
value: `${data.cluster_worker_status || "offline"} / ${data.cluster_online_worker_nodes || 0}`,
note: `可执行检测的在线节点,独立 Worker ${data.cluster_dedicated_online_worker_nodes || 0},控制面 ${data.cluster_online_control_nodes || 0}`
},
{ label: "模式", value: data.worker_mode, note: "当前 Worker 运行模式" }
];
loadError.value = false;

View File

@@ -5,6 +5,11 @@
<el-button :loading="actionLoading === 'stop'" @click="invoke('stop')">停止检测</el-button>
<el-button plain :loading="loading" @click="loadStatus">刷新状态</el-button>
<el-button plain @click="goRuntime">前往运行中心</el-button>
<el-button-group>
<el-button plain :type="status.worker_log_sync_enabled ? '' : 'primary'" @click="updateWorkerLogSync(false, 'key')">关闭回传</el-button>
<el-button plain :type="status.worker_log_sync_enabled && status.worker_log_sync_mode === 'key' ? 'primary' : ''" @click="updateWorkerLogSync(true, 'key')">关键回传</el-button>
<el-button plain :type="status.worker_log_sync_enabled && status.worker_log_sync_mode === 'full' ? 'primary' : ''" @click="updateWorkerLogSync(true, 'full')">全量回传</el-button>
</el-button-group>
<el-switch v-model="autoRefresh" inline-prompt active-text="自动刷新" inactive-text="手动" />
<span class="updated-at">最近同步{{ lastUpdatedAt || "暂无" }}</span>
</div>
@@ -19,7 +24,7 @@
/>
<el-descriptions :column="2" border>
<el-descriptions-item label="Worker 在线">{{ status.worker_online ? "是" : "否" }}</el-descriptions-item>
<el-descriptions-item label="本机 Worker 在线">{{ status.worker_online ? "是" : "否" }}</el-descriptions-item>
<el-descriptions-item label="运行模式">{{ status.worker_mode || "windows-local" }}</el-descriptions-item>
<el-descriptions-item label="Worker 服务">{{ status.worker_service_name || "-" }}</el-descriptions-item>
<el-descriptions-item label="API 服务">{{ status.api_service_name || "-" }}</el-descriptions-item>
@@ -35,6 +40,8 @@
<el-descriptions-item label="最近代理刷新">{{ status.proxy_last_refresh_time || "暂无" }}</el-descriptions-item>
<el-descriptions-item label="最近 Worker 日志时间">{{ status.last_worker_log_time || "暂无" }}</el-descriptions-item>
<el-descriptions-item label="最近启动时间">{{ status.worker_latest_start_time || "暂无" }}</el-descriptions-item>
<el-descriptions-item label="远端日志回传">{{ status.worker_log_sync_enabled ? "已开启" : "已关闭" }}</el-descriptions-item>
<el-descriptions-item label="回传级别">{{ status.worker_log_sync_enabled ? (status.worker_log_sync_mode === "full" ? "全量" : "关键") : "-" }}</el-descriptions-item>
</el-descriptions>
<el-alert
@@ -90,7 +97,7 @@
:closable="false"
show-icon
type="info"
:title="`当前检测状态:${currentPhaseLabel}Worker ${status.worker_online ? '在线' : '离线'}。`"
:title="`当前检测状态:${currentPhaseLabel}本机 Worker ${status.worker_online ? '在线' : '离线'}。`"
style="margin-top: 12px"
/>
@@ -261,7 +268,7 @@
<div class="task-detail-meta">
<el-switch v-model="logAutoFollow" inline-prompt active-text="跟随日志" inactive-text="暂停跟随" size="small" />
<el-button text size="small" @click="scrollLogToBottom(true)">回到底部</el-button>
<span>Worker{{ status.worker_online ? "在线" : "离线" }}</span>
<span>本机 Worker{{ status.worker_online ? "在线" : "离线" }}</span>
<span v-if="selectedRun?.phase_label">阶段{{ selectedRun.phase_label }}</span>
<span>运行中{{ status.progress.running || 0 }}</span>
<span>线程{{ threadCountSummary }}</span>
@@ -284,7 +291,7 @@ import { computed, nextTick, onBeforeUnmount, onMounted, ref, watch } from "vue"
import { useRouter } from "vue-router";
import { ElMessage } from "element-plus";
import PageCard from "@/components/PageCard.vue";
import { detectApi } from "@/api/modules";
import { detectApi, settingsApi } from "@/api/modules";
const DETECT_LAST_ACTION_KEY = "domaincheck:detect:last-action";
const router = useRouter();
@@ -320,7 +327,10 @@ const status = ref({
proxy_last_refresh_time: "",
dependency_alerts: [] as any[],
log_lines: [] as string[],
remote_log_lines: [] as string[],
runs: [] as any[],
worker_log_sync_enabled: false,
worker_log_sync_mode: "key",
progress_percent: 0,
active_job: null as any,
progress: {
@@ -424,13 +434,44 @@ const phaseHistory = computed(() => {
if (!Array.isArray(items)) return [];
return [...items].reverse();
});
const selectedRunIsLatest = computed(() => {
if (!selectedRun.value || !runs.value.length) {
return false;
}
return selectedRun.value.run_id === runs.value[0]?.run_id;
});
const dedupeConsecutiveLines = (lines: string[]) => {
const result: string[] = [];
for (const rawLine of lines) {
const line = String(rawLine || "");
if (!line) {
continue;
}
if (result[result.length - 1] === line) {
continue;
}
result.push(line);
}
return result;
};
const selectedLogText = computed(() => {
const runLogs = selectedRun.value?.logs;
const mergedLines: string[] = [];
if (Array.isArray(runLogs) && runLogs.length) {
return runLogs.join("\n");
mergedLines.push(...runLogs);
}
const remoteLogLines = status.value.remote_log_lines || [];
const canAppendRemoteLogs = !selectedRun.value || selectedRunIsLatest.value;
if (canAppendRemoteLogs && Array.isArray(remoteLogLines) && remoteLogLines.length) {
mergedLines.push(...remoteLogLines);
}
if (mergedLines.length) {
return dedupeConsecutiveLines(mergedLines).join("\n");
}
const liveLogs = status.value.log_lines || [];
return liveLogs.length ? liveLogs.join("\n") : "暂无检测日志";
return liveLogs.length ? dedupeConsecutiveLines(liveLogs).join("\n") : "暂无检测日志";
});
const proxyAlertType = computed<"success" | "warning" | "info" | "error">(() => {
if (status.value.proxy_runtime_state === "healthy") return "success";
@@ -580,18 +621,35 @@ const invoke = async (action: "start" | "stop") => {
actionLoading.value = action;
try {
const response = action === "start" ? await detectApi.start() : await detectApi.stop();
ElMessage.success(response.message);
const responseMessage = String(response.message || "");
const uiLevel = String(response.data?.ui_level || "").trim().toLowerCase();
const actionType: "success" | "warning" | "error" =
uiLevel === "error" ? "error" : uiLevel === "warning" ? "warning" : "success";
if (actionType === "error") {
ElMessage.error(responseMessage);
} else if (actionType === "warning") {
ElMessage.warning(responseMessage);
} else {
ElMessage.success(responseMessage);
}
lastAction.value = {
label: action === "start" ? "检测启动" : "检测停止",
message: response.message,
message: responseMessage,
at: new Date().toLocaleString("zh-CN", { hour12: false }),
type: "success"
type: actionType
};
persistLastAction();
const pollDelaySeconds = Number(response.data?.poll_after_seconds || 2);
window.setTimeout(() => {
loadStatus(false);
}, pollDelaySeconds * 1000);
await loadStatus(false);
const pollSchedule = Array.isArray(response.data?.poll_schedule_seconds)
? response.data.poll_schedule_seconds
: [Number(response.data?.poll_after_seconds || 2)];
[...new Set(pollSchedule.map((item: unknown) => Number(item || 0)).filter((item: number) => item > 0))]
.sort((a, b) => a - b)
.forEach((seconds) => {
window.setTimeout(() => {
loadStatus(false);
}, seconds * 1000);
});
} catch (error: any) {
const message = error?.message || `${action === "start" ? "启动" : "停止"}操作失败`;
lastAction.value = {
@@ -615,6 +673,25 @@ const goRuntime = () => {
router.push("/runtime");
};
const updateWorkerLogSync = async (enabled: boolean, mode: "key" | "full") => {
try {
const current = await settingsApi.getSettings();
const payload = {
...current.data,
runtime_settings: {
...(current.data?.runtime_settings || {}),
worker_log_sync_enabled: enabled,
worker_log_sync_mode: mode
}
};
await settingsApi.updateSettings(payload);
ElMessage.success(`远端日志回传已${enabled ? `切到${mode === "full" ? "全量" : "关键"}模式` : "关闭"}`);
await loadStatus();
} catch {
ElMessage.error("更新远端日志回传开关失败");
}
};
watch(autoRefresh, ensureRefreshTimer);
watch(selectedLogText, async (current, previous) => {
if (current === previous) {

View File

@@ -22,9 +22,9 @@
<el-tag :type="runtime.api?.pid ? 'success' : 'info'">{{ runtime.api?.pid ? "运行中" : "未知" }}</el-tag>
</div>
<div class="summary-card">
<div class="summary-title">Worker 状态</div>
<div class="summary-title">本机 Worker</div>
<div class="summary-value">{{ runtime.worker?.service_name || "-" }}</div>
<el-tag :type="runtime.worker?.running ? 'success' : 'danger'">{{ runtime.worker?.running ? "在线" : "离线" }}</el-tag>
<el-tag :type="runtime.worker?.running ? 'success' : 'danger'">{{ runtime.worker?.running ? "本机在线" : "本机离线" }}</el-tag>
</div>
<div class="summary-card">
<div class="summary-title">运行模式</div>
@@ -68,10 +68,12 @@
<div class="summary-note">当前已接入控制面与执行面节点总数</div>
</div>
<div class="summary-card">
<div class="summary-title">在线 Worker</div>
<div class="summary-title">有效执行节点</div>
<div class="summary-value">{{ runtime.cluster?.summary?.online_worker_nodes || 0 }}</div>
<div class="summary-note">
控制面 {{ runtime.cluster?.summary?.online_control_nodes || 0 }}
可承担检测任务的在线节点
/ 独立 Worker {{ runtime.cluster?.summary?.dedicated_online_worker_nodes || 0 }}
/ 控制面 {{ runtime.cluster?.summary?.online_control_nodes || 0 }}
/ 忙碌 {{ runtime.cluster?.summary?.status_counts?.busy || 0 }}
</div>
</div>
@@ -117,7 +119,10 @@
API {{ runtime.api?.pid ? "运行中" : "未知" }}
</span>
<span class="status-chip" :class="runtime.worker?.running ? 'ok' : 'danger'">
Worker {{ runtime.worker?.running ? "在线" : "离线" }}
本机 Worker {{ runtime.worker?.running ? "在线" : "离线" }}
</span>
<span class="status-chip" :class="(runtime.cluster?.summary?.online_worker_nodes || 0) > 0 ? 'ok' : 'danger'">
有效执行节点 {{ runtime.cluster?.summary?.online_worker_nodes || 0 }}
</span>
<span class="status-chip" :class="preflight.ok ? 'ok' : 'danger'">
预检 {{ preflight.ok ? "通过" : "异常" }}
@@ -196,7 +201,7 @@
show-icon
type="info"
style="margin-top: 12px"
:title="`当前 Worker 状态${runtime.worker?.running ? '运行中' : '未运行'};当前 API 状态:${runtime.api?.pid ? '运行中' : '未知'}Sync Agent${runtime.sync_agent?.running ? '运行中' : '未运行'}。`"
:title="`当前本机 Worker${runtime.worker?.running ? '运行中' : '未运行'}有效执行节点:${runtime.cluster?.summary?.online_worker_nodes || 0};独立 Worker${runtime.cluster?.summary?.dedicated_online_worker_nodes || 0}当前 API 状态:${runtime.api?.pid ? '运行中' : '未知'}Sync Agent${runtime.sync_agent?.running ? '运行中' : '未运行'}。`"
/>
<el-alert
v-if="!runtime.sync_agent?.expected_on_this_node"
@@ -275,10 +280,10 @@
<div class="history-panel">
<div class="history-header">
<h3>扩容建议</h3>
<span class="history-note">基于当前积压近窗吞吐和在线 Worker 数自动估算</span>
<span class="history-note">基于当前积压近窗吞吐和有效执行节点数自动估算</span>
</div>
<div class="cluster-summary">
<span class="cluster-summary-item">在线 Worker {{ runtime.detect?.capacity_plan?.online_worker_nodes || 0 }}</span>
<span class="cluster-summary-item">有效执行节点 {{ runtime.detect?.capacity_plan?.online_worker_nodes || 0 }}</span>
<span class="cluster-summary-item">当前吞吐 {{ runtime.detect?.capacity_plan?.current_processed_per_hour || 0 }}/小时</span>
<span class="cluster-summary-item">预计剩余 {{ runtime.detect?.capacity_plan?.estimated_hours_remaining || 0 }} 小时</span>
<span class="cluster-summary-item">建议总 Worker {{ runtime.detect?.capacity_plan?.recommended_total_workers || 1 }}</span>
@@ -377,7 +382,7 @@
</div>
<div class="cluster-summary">
<span class="cluster-summary-item">在线控制面 {{ runtime.cluster?.summary?.online_control_nodes || 0 }}</span>
<span class="cluster-summary-item">在线 Worker {{ runtime.cluster?.summary?.online_worker_nodes || 0 }}</span>
<span class="cluster-summary-item">有效执行节点 {{ runtime.cluster?.summary?.online_worker_nodes || 0 }}</span>
<span class="cluster-summary-item">独立 Worker {{ runtime.cluster?.summary?.dedicated_online_worker_nodes || 0 }}</span>
<span class="cluster-summary-item">忙碌 {{ runtime.cluster?.summary?.status_counts?.busy || 0 }}</span>
<span class="cluster-summary-item">失活 {{ runtime.cluster?.summary?.status_counts?.stale || 0 }}</span>
@@ -803,17 +808,19 @@ const clusterIssueCount = computed(() => {
const clusterAlertText = computed(() => {
const summary = runtime.cluster?.summary || {};
const busy = Array.isArray(summary.busy_nodes) ? summary.busy_nodes.join("、") : "";
const stale = Array.isArray(summary.stale_nodes) ? summary.stale_nodes.join("、") : "";
const offline = Array.isArray(summary.offline_nodes) ? summary.offline_nodes.join("、") : "";
const parts = [];
const staleNodes = Array.isArray(summary.stale_nodes) ? summary.stale_nodes : [];
const offlineNodes = Array.isArray(summary.offline_nodes) ? summary.offline_nodes : [];
const parts = [
`当前有效执行节点 ${summary.online_worker_nodes || 0},其中独立 Worker ${summary.dedicated_online_worker_nodes || 0}`
];
if (busy) {
parts.push(`忙碌节点:${busy}`);
}
if (stale) {
parts.push(`失活节点${stale}`);
if (staleNodes.length) {
parts.push(`失活节点 ${staleNodes.length}${staleNodes.length <= 2 ? `${staleNodes.join("、")}` : ",详见下方节点表"}`);
}
if (offline) {
parts.push(`离线节点${offline}`);
if (offlineNodes.length) {
parts.push(`离线节点 ${offlineNodes.length}${offlineNodes.length <= 2 ? `${offlineNodes.join("、")}` : ",详见下方节点表"}`);
}
return parts.join("");
});
@@ -824,7 +831,8 @@ const participatingNodesAlertText = computed(() => {
return "当前没有节点正在领任务、执行任务或产生近窗吞吐。";
}
const names = rows.map((item: Record<string, any>) => String(item.node_code || "-")).join("、");
return `当前参与检测节点 ${rows.length} 台:${names}`;
const effectiveCount = rows.filter((item: Record<string, any>) => Boolean(item.is_effective_worker)).length;
return `当前参与检测节点 ${rows.length} 台,其中有效执行节点 ${effectiveCount} 台:${names}`;
});
const syncAlertText = computed(() => {
@@ -1034,18 +1042,36 @@ const invokeAction = async (action: "start_worker" | "stop_worker" | "restart_ap
stop_sync_agent: "停止 Sync Agent",
push_sync: "立即同步"
};
const responseMessage = String(response.message || "");
const uiLevel = String(response.data?.ui_level || "").trim().toLowerCase();
const actionType: "success" | "warning" | "error" =
uiLevel === "error" ? "error" : uiLevel === "warning" ? "warning" : "success";
lastAction.value = {
label: labelMap[action],
message: response.message,
message: responseMessage,
at: new Date().toLocaleString("zh-CN", { hour12: false }),
type: "success"
type: actionType
};
persistLastAction();
appendActionHistory(lastAction.value);
ElMessage.success(response.message);
window.setTimeout(() => {
loadAll(false);
}, Number(response.data?.poll_after_seconds || 2) * 1000);
if (actionType === "error") {
ElMessage.error(responseMessage);
} else if (actionType === "warning") {
ElMessage.warning(responseMessage);
} else {
ElMessage.success(responseMessage);
}
await loadAll(false);
const pollSchedule = Array.isArray(response.data?.poll_schedule_seconds)
? response.data.poll_schedule_seconds
: [Number(response.data?.poll_after_seconds || 2)];
[...new Set(pollSchedule.map((item: unknown) => Number(item || 0)).filter((item: number) => item > 0))]
.sort((a, b) => a - b)
.forEach((seconds) => {
window.setTimeout(() => {
loadAll(false);
}, seconds * 1000);
});
} catch (error: any) {
const message = error?.message || "运行时动作执行失败";
const labelMap = {

View File

@@ -54,6 +54,25 @@
<el-form-item label="Sync Agent 服务名">
<el-input v-model="runtimeSettings.sync_agent_service_name" />
</el-form-item>
<el-form-item label="远端日志回传">
<el-switch v-model="runtimeSettings.worker_log_sync_enabled" />
</el-form-item>
<el-form-item label="回传级别">
<el-select v-model="runtimeSettings.worker_log_sync_mode" :disabled="!runtimeSettings.worker_log_sync_enabled">
<el-option label="关键" value="key" />
<el-option label="全量" value="full" />
</el-select>
</el-form-item>
<el-alert
:closable="false"
type="info"
show-icon
style="margin-top: 12px"
title="关闭时不追加远端日志镜像;关键模式回传阶段/代理/异常等关键过程;全量模式会追加更多执行过程,便于临时分析。"
/>
</el-form>
</PageCard>
@@ -232,7 +251,9 @@ const runtimeSettings = ref({
worker_mode: "windows-local",
worker_service_name: "domaincheck-worker",
api_service_name: "domaincheck-api",
sync_agent_service_name: "domaincheck-sync-agent"
sync_agent_service_name: "domaincheck-sync-agent",
worker_log_sync_enabled: false,
worker_log_sync_mode: "key"
});
const importInput = ref<HTMLInputElement | null>(null);
const juziseoLoggingIn = ref(false);
@@ -316,6 +337,10 @@ const normalizeNodeThreadOverrides = (payload: Record<string, number | string>)
.sort((a, b) => a.node_code.localeCompare(b.node_code));
};
const normalizeWorkerLogSyncMode = (value: unknown) => {
return String(value || "").trim().toLowerCase() === "full" ? "full" : "key";
};
const addNodeThreadOverride = () => {
nodeThreadOverrides.value.push({
node_code: "",
@@ -371,7 +396,9 @@ const loadSettings = async () => {
worker_mode: response.data.runtime_settings?.worker_mode || "windows-local",
worker_service_name: response.data.runtime_settings?.worker_service_name || "domaincheck-worker",
api_service_name: response.data.runtime_settings?.api_service_name || "domaincheck-api",
sync_agent_service_name: response.data.runtime_settings?.sync_agent_service_name || "domaincheck-sync-agent"
sync_agent_service_name: response.data.runtime_settings?.sync_agent_service_name || "domaincheck-sync-agent",
worker_log_sync_enabled: Boolean(response.data.runtime_settings?.worker_log_sync_enabled),
worker_log_sync_mode: normalizeWorkerLogSyncMode(response.data.runtime_settings?.worker_log_sync_mode)
};
} catch {
ElMessage.error("读取系统设置失败");