配置文件
配置使用 YAML,默认路径为 /etc/svcwatch/config.yaml,
可通过 -c 或环境变量覆盖。
文件结构
listen: 127.0.0.1:9090
interval: 30s
timeout: 5s
retries: 3
log_level: info
notify:
channel: webhook
url: https://hooks.example.com/svcwatch
repeat: 30m
labels:
env: production
region: us-west
targets:
- name: web
type: http
url: https://example.com/healthz
expect_status: 200
expect_body: /"status":"ok"/
tls_expiry_warn: 336h
- name: cache
type: tcp
address: 127.0.0.1:6379
- name: disk-usage
type: exec
command: ["df", "-P", "/"]
expect_exit: 0全局选项
| 字段 | 类型 | 默认值 | 说明 |
|---|---|---|---|
listen | string | 127.0.0.1:9090 | 指标端点监听地址 |
interval | duration | 60s | 检查轮次间隔,最小 5s |
timeout | duration | 5s | 单次探测超时 |
retries | int | 3 | 连续失败多少次判定为 down |
log_level | string | info | debug / info / warn / error |
labels | map | 空 | 附加到所有指标的静态标签 |
目标定义
每个目标至少需要 name 与 type,其余字段随类型不同。
各类型的专属字段见检查类型。
| 字段 | 说明 |
|---|---|
name | 唯一标识,会作为 name 标签值;不可重复 |
type | http / tcp / exec / dns |
labels | 目标级附加标签,与全局标签合并,同名时以目标为准 |
disabled | 设为 true 可临时跳过该目标而不删除配置 |
name 会直接出现在指标标签中,且 Prometheus 的标签值区分大小写。
重命名一个目标的 name 等同于新建一条时间序列,旧序列不会自动清理。
环境变量
适合在容器或 systemd 单元里覆盖敏感项,优先级高于配置文件:
| 变量 | 对应字段 |
|---|---|
SVCWATCH_CONFIG | 配置文件路径 |
SVCWATCH_LISTEN | listen |
SVCWATCH_LOG_LEVEL | log_level |
SVCWATCH_NOTIFY_URL | notify.url |
热加载
修改配置后不需要中断服务,发送 SIGHUP 即可重新读取:
sudo systemctl reload svcwatch # 等价于 kill -HUP $(pidof svcwatch)热加载会重置轮次计时器,但不会清空已有的失败计数。若新配置校验失败,
进程会保留原配置并输出一条 error 级别日志。