diff --git a/deploy/backend-watchdog-task.xml b/deploy/backend-watchdog-task.xml index b58a9cf..88f59d2 100644 --- a/deploy/backend-watchdog-task.xml +++ b/deploy/backend-watchdog-task.xml @@ -17,11 +17,17 @@ PT10M - + + + 2026-01-01T00:00:00 PT2M + P3650D + false - + diff --git a/deploy/watchdog.ps1 b/deploy/watchdog.ps1 index 404211f..3dde3d8 100644 --- a/deploy/watchdog.ps1 +++ b/deploy/watchdog.ps1 @@ -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 "状态文件写入失败: $_" +} diff --git a/fruitshorts-admin-api/src/main/resources/application.yml b/fruitshorts-admin-api/src/main/resources/application.yml index 41372e4..2930a0c 100644 --- a/fruitshorts-admin-api/src/main/resources/application.yml +++ b/fruitshorts-admin-api/src/main/resources/application.yml @@ -14,6 +14,12 @@ spring: url: ${DB_URL:jdbc:postgresql://127.0.0.1:5432/fruitshorts} username: ${DB_USER:fruitshorts} password: ${DB_PASSWORD:fruitshorts} + data: + redis: + # 与 app-api 共用同一个 Redis 实例;容器内必须显式指定 host, + # 否则 Spring Boot 默认连 127.0.0.1(容器内即自身)导致健康检查报 DOWN。 + host: ${REDIS_HOST:127.0.0.1} + port: ${REDIS_PORT:6379} jackson: date-format: yyyy-MM-dd HH:mm:ss time-zone: Asia/Shanghai