fix(ops): 修复管理端 Redis 未配置与看门狗未真正周期巡检
- admin-api 的 application.yml 缺少 spring.data.redis 配置,容器内默认连 127.0.0.1 导致 /actuator/health 返回 DOWN(redis 组件不可用); 补齐后与 app-api 共用 REDIS_HOST/REDIS_PORT,健康检查恢复 UP - 计划任务原先用 BootTrigger 挂 Repetition,Windows 不生效(Next Run Time 为 N/A,9 小时只跑过一次),看门狗形同虚设;改为 TimeTrigger + PT2M 无限重复 + StartWhenAvailable,实测每 2 分钟稳定巡检 - watchdog.ps1 的连续失败计数改为落盘 watchdog-state.json,避免每轮进程 重启后清零导致「连续 3 次失败告警」永不触发
This commit is contained in:
1 parent
657190d5a8
commit
181b338780
3 files changed
+32
-3
No files matched your search
@@ -17,11 +17,17 @@
|
||||
<ExecutionTimeLimit>PT10M</ExecutionTimeLimit>
|
||||
</Settings>
|
||||
<Triggers>
|
||||
<BootTrigger>
|
||||
<!-- BootTrigger 上挂 <Repetition> 在 Windows 计划任务里不生效(导入后 Next Run Time 为 N/A,
|
||||
实际只在开机跑一次)。改成 TimeTrigger + 无限重复,配合 StartWhenAvailable
|
||||
保证开机后若错过也会立即补跑;这样才真正做到每 2 分钟巡检一次。 -->
|
||||
<TimeTrigger>
|
||||
<StartBoundary>2026-01-01T00:00:00</StartBoundary>
|
||||
<Repetition>
|
||||
<Interval>PT2M</Interval>
|
||||
<Duration>P3650D</Duration>
|
||||
<StopAtDurationEnd>false</StopAtDurationEnd>
|
||||
</Repetition>
|
||||
</BootTrigger>
|
||||
</TimeTrigger>
|
||||
</Triggers>
|
||||
<Actions Context="Author">
|
||||
<Exec>
|
||||
|
||||
+18
-1
@@ -91,8 +91,18 @@ $checks = @(
|
||||
@{ Name = "Prometheus"; Type = "http"; Url = "http://127.0.0.1:9090/-/healthy"; Service = "prometheus"; Container = "fruitshorts-prometheus" }
|
||||
)
|
||||
|
||||
# 跟踪每个服务的连续失败次数
|
||||
# 跟踪每个服务的连续失败次数。脚本由计划任务每 2 分钟拉起一次,
|
||||
# 进程内变量会跨轮丢失,因此计数持久化到状态文件,否则「连续 3 次告警」永远不触发。
|
||||
$StateFile = Join-Path $LogDir "watchdog-state.json"
|
||||
$failCounts = @{}
|
||||
if (Test-Path $StateFile) {
|
||||
try {
|
||||
(Get-Content $StateFile -Raw | ConvertFrom-Json).PSObject.Properties |
|
||||
ForEach-Object { $failCounts[$_.Name] = [int]$_.Value }
|
||||
} catch {
|
||||
Write-Log "状态文件损坏,重置连续失败计数"
|
||||
}
|
||||
}
|
||||
|
||||
foreach ($check in $checks) {
|
||||
$name = $check.Name
|
||||
@@ -168,3 +178,10 @@ if ($drive) {
|
||||
Send-Alert "磁盘告警" "C 盘使用率 ${pct}%,请清理日志或扩容"
|
||||
}
|
||||
}
|
||||
|
||||
# 落盘本轮结束时的连续失败计数,供下一轮接着累计
|
||||
try {
|
||||
$failCounts | ConvertTo-Json | Set-Content -Path $StateFile -Encoding UTF8
|
||||
} catch {
|
||||
Write-Log "状态文件写入失败: $_"
|
||||
}
|
||||
Reference in new issue
Block a user