返回教程列表

預警通知接入(Telegram Bot)

把礦機預警 POST 到 webhook。接收端可以是 Telegram、釘釘或飛書。

HashRelay 自己不会调用 Telegram Bot API。预警会写入数据库、打到日志,并在你打开开关后,把 JSON POST 到一个 webhook 地址。Telegram、钉钉、飞书都只是这个地址另一头的接收方。

打开检测

矿池必须打开协议镜像,否则没有 share 和算力事件可供判断。然后再打开全局预警开关。

toml
[sniffing.alerts]
enabled = true
reject_rate_threshold = 0.10      # 10% over the last N shares
reject_rate_window = 50
offline_threshold = 300           # seconds
hashrate_drop_threshold = 0.50    # vs the 15-minute average
hashrate_zero_periods = 3
consecutive_stale_threshold = 5
high_latency_threshold_ms = 5000
reconnect_window = 300
reconnect_threshold = 3
alert_cooldown = 600              # seconds, same type + pool + worker

[sniffing.alerts.webhook]
enabled = true
url = "https://your-bridge.example/hashrelay"
timeout = 10
# [sniffing.alerts.webhook.headers]
# Authorization = "Bearer xxx"

POST 的内容

Webhook 以 Content-Type: application/json 发送。严重级别是调试名称,所以是 "Warning" 或 "Critical",不是数字。非 2xx 只会记日志,不会打断其他预警。

json
{
  "alert_type": "high_reject_rate",
  "severity": "Warning",
  "pool_name": "F2Pool-BTC",
  "worker": "user.worker01",
  "message": "...",
  "context": { "reject_rate": 0.18 },
  "timestamp": "2026-11-04T10:00:00Z"
}

检测器会发出的 alert_type 包括 high_reject_rate、difficulty_spike、hashrate_drop、hashrate_zero、auth_failure、high_latency、high_avg_latency。同一组(类型、矿池、矿工)在 alert_cooldown 秒内不会重复发送,默认 600 秒。

送到 Telegram

把 url 指到你自己的一个小桥接服务:收到这份 JSON 后,再用你的 bot token 调用 Telegram 的 sendMessage。不要把 bot token 直接写进 server.toml,除非它只是你自己桥接服务的请求头。也可以事后用 GET /api/v1/alerts 查看,并用 POST /api/v1/alerts/:id/resolve 标记已处理。