feat: 重构为多类型 checker 通用框架,支持 HTTP 与命令检查
- 引入 typed target 判别联合,支持 http 与 command 两种 checker - expect 重构为有序规则数组,按配置顺序快速失败并生成结构化 failure - 新增 command runner,支持 exec + args 本地命令执行 - 引入全局并发限制 maxConcurrentChecks 和 size 解析 (KB/MB/GB) - HTTP/command 各自独立 expect pipeline,应用领域默认成功语义 - SQLite schema、API、Dashboard 全链路调整为 checker 通用契约 - 补充完整测试覆盖(192 tests),更新 README 与示例配置
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
import type {
|
||||
ApiErrorResponse,
|
||||
CheckFailure,
|
||||
CheckResult,
|
||||
HealthResponse,
|
||||
RuntimeMode,
|
||||
@@ -136,7 +137,7 @@ function handleTrend(idStr: string, url: URL, method: string, store: ProbeStore,
|
||||
|
||||
const trend: TrendPoint[] = store.getTrend(id, hours).map((row) => ({
|
||||
hour: row.hour,
|
||||
avgLatencyMs: row.avgLatencyMs,
|
||||
avgDurationMs: row.avgDurationMs,
|
||||
availability: Math.round(row.availability * 100) / 100,
|
||||
totalChecks: row.totalChecks,
|
||||
}));
|
||||
@@ -150,7 +151,7 @@ function createSummaryResponse(store: ProbeStore): SummaryResponse {
|
||||
total: summary.total,
|
||||
up: summary.up,
|
||||
down: summary.down,
|
||||
avgLatencyMs: summary.avgLatencyMs,
|
||||
avgDurationMs: summary.avgDurationMs,
|
||||
lastCheckTime: summary.lastCheckTime,
|
||||
};
|
||||
}
|
||||
@@ -165,29 +166,34 @@ function createTargetsResponse(store: ProbeStore): TargetStatus[] {
|
||||
return {
|
||||
id: target.id,
|
||||
name: target.name,
|
||||
url: target.url,
|
||||
method: target.method,
|
||||
type: target.type,
|
||||
target: target.target,
|
||||
interval: formatDuration(target.interval_ms),
|
||||
latestCheck: latest ? mapCheckResult(latest) : null,
|
||||
sparkline: store.getSparkline(target.id),
|
||||
stats: {
|
||||
totalChecks: stats.totalChecks,
|
||||
availability: stats.availability,
|
||||
avgLatencyMs: stats.avgLatencyMs,
|
||||
p99LatencyMs: stats.p99LatencyMs,
|
||||
avgDurationMs: stats.avgDurationMs,
|
||||
p99DurationMs: stats.p99DurationMs,
|
||||
},
|
||||
};
|
||||
});
|
||||
}
|
||||
|
||||
function mapCheckResult(row: StoredCheckResult): CheckResult {
|
||||
let failure: CheckFailure | null = null;
|
||||
if (row.failure) {
|
||||
failure = JSON.parse(row.failure) as CheckFailure;
|
||||
}
|
||||
|
||||
return {
|
||||
timestamp: row.timestamp,
|
||||
success: row.success === 1,
|
||||
statusCode: row.status_code,
|
||||
latencyMs: row.latency_ms,
|
||||
error: row.error,
|
||||
matched: row.matched === 1,
|
||||
durationMs: row.duration_ms,
|
||||
statusDetail: row.status_detail,
|
||||
failure,
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user