Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 50 additions & 0 deletions docs/MONITORING.md
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,50 @@ read -rsp 'Grafana admin password: ' GF_PASS && export GF_PASS
sudo --preserve-env=GF_ADMIN,GF_PASS ./ops/prometheus/install-grafana.sh
```

## Hub probe

Prometheus asks the Hub's `/healthz` through a blackbox exporter on
`127.0.0.1:9115`. `/healthz` answers HTTP 200 with `alive` while the Hub process
serves requests.

```bash
CLAWCTL_HUB_URL=https://hub.example.com ./ops/prometheus/install-hub-probe.sh --check
sudo CLAWCTL_HUB_URL=https://hub.example.com ./ops/prometheus/install-hub-probe.sh
sudo ./ops/prometheus/install-hub-probe.sh --remove
```

Set `CLAWCTL_HUB_URL` to an `http://` or `https://` address with a host and
optional port, without a path, credentials, query or fragment. One trailing
slash is accepted. `--check` prints the plan without changing configuration.
Install requires root and a Hub that answers HTTP 200 with exactly `alive`
or `alive` followed by one newline.

| Alert | Fires when | Severity |
|---|---|---|
| `HubNotAnswering` | The Hub probe gets no answer for 5 minutes | critical |
| `HubProbeNotRunning` | Prometheus gets no probe result for 10 minutes | warning |

For a first installation, the exporter stays masked until its loopback
listener and module file are configured. A failed installation can be retried
or cleaned up with `--remove`, including failures before the scrape job exists.
An exporter masked by the operator remains masked.

The installer installs `prometheus-blackbox-exporter` and these files:

| File | Effect |
|---|---|
| `/etc/prometheus/clawctl-blackbox.yml` | Defines the `/healthz` probe |
| `/etc/default/prometheus-blackbox-exporter` | Sets the module file and listener |
| `/etc/prometheus/scrape.d/clawctl-hub-healthz.yml` | Adds the Hub scrape job |
| `/etc/prometheus/rules/clawctl-hub-healthz.yml` | Adds both alerts |
| `/etc/prometheus/prometheus.yml` | Adds the scrape directory when absent |

Telegram delivery uses the Alertmanager of step 2 and its 5 minute grouping
delay. `--remove` deletes the scrape job and alert rules, reloads Prometheus,
and stops and disables the exporter. The package, module file, exporter
settings and `prometheus.yml` stay installed. If removal fails, repeat the
`--remove` command to complete the reload and exporter shutdown.

## Grafana without root

`ops/prometheus/install-grafana-docker.sh` runs Grafana in Docker
Expand All @@ -129,6 +173,7 @@ Grafana data, including the admin password, stays in the Docker volume
|---|---|
| Prometheus | `127.0.0.1:9090` |
| Alertmanager | `127.0.0.1:9093`, cluster listener off |
| Hub blackbox exporter | `127.0.0.1:9115` |
| node_exporter | `<address>:9100` |
| Grafana (APT, `install-grafana.sh`) | `<address>:3000` |
| Grafana (Docker) | `$CLAWCTL_GRAFANA_ADDR:$CLAWCTL_GRAFANA_PORT` |
Expand Down Expand Up @@ -160,3 +205,8 @@ if the whole metric is empty, the query or the scrape is wrong.
`CLAWCTL_REQUIRE_PROMTOOL=1` to fail when `promtool` is missing), that
`install.sh` calls existing stage scripts, the installers' refusals and
Grafana login checks, and the functions of `ops/prometheus/listen.sh`.

```bash
bash ops/prometheus/test-install-hub-probe.sh
promtool test rules ops/prometheus/hub-probe/rules_test.yml
```
13 changes: 13 additions & 0 deletions ops/prometheus/hub-probe/blackbox.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Blackbox exporter modules of ops/prometheus/install-hub-probe.sh.
modules:
# The Hub's GET /healthz answers 200 with the body "alive".
clawctl_hub_healthz:
prober: http
timeout: 10s
http:
method: GET
valid_status_codes: [200]
follow_redirects: false
preferred_ip_protocol: ip4
fail_if_body_not_matches_regexp:
- '^alive\n?$'
35 changes: 35 additions & 0 deletions ops/prometheus/hub-probe/rules.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# Alerts of the Hub probe. ops/prometheus/install-hub-probe.sh installs this
# file as /etc/prometheus/rules/clawctl-hub-healthz.yml.
#
# Both alerts carry machine="hub": Alertmanager groups by machine and the
# message title names it.

groups:
- name: clawctl-hub-healthz
interval: 60s
rules:
- alert: HubNotAnswering
expr: probe_success{job="clawctl-hub-healthz"} == 0
for: 5m
labels:
severity: critical
source: prometheus
machine: hub
annotations:
summary: 'Hub 沒有回應'
description: >-
{{ $labels.instance }} 連續 5 分鐘沒有回 200。主控台打不開,
經這個網址報到的機器也報不到。下一步:到 Hub 主機查 Hub 服務的狀態。

- alert: HubProbeNotRunning
expr: up{job="clawctl-hub-healthz"} == 0 or absent(up{job="clawctl-hub-healthz"})
for: 10m
labels:
severity: warning
source: prometheus
machine: hub
annotations:
summary: 'Hub 探測沒有在跑'
description: >-
Prometheus 連續 10 分鐘拿不到 Hub 探測的結果,這段時間沒有人在看 Hub 有沒有回應。
下一步:在觀測主機上跑 systemctl status prometheus-blackbox-exporter。
127 changes: 127 additions & 0 deletions ops/prometheus/hub-probe/rules_test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
# promtool test rules ops/prometheus/hub-probe/rules_test.yml
rule_files:
- rules.yml
evaluation_interval: 1m

tests:
# The Hub answers: neither alert fires.
- interval: 1m
input_series:
- series: 'probe_success{job="clawctl-hub-healthz", instance="https://hub.example.com/healthz"}'
values: '1x20'
- series: 'up{job="clawctl-hub-healthz", instance="https://hub.example.com/healthz"}'
values: '1x20'
alert_rule_test:
- eval_time: 20m
alertname: HubNotAnswering
exp_alerts: []
- eval_time: 20m
alertname: HubProbeNotRunning
exp_alerts: []

# Four failed probes, then an answer: HubNotAnswering does not fire.
- interval: 1m
input_series:
- series: 'probe_success{job="clawctl-hub-healthz", instance="https://hub.example.com/healthz"}'
values: '1 0 0 0 0 1 1 1 1 1 1 1'
- series: 'up{job="clawctl-hub-healthz", instance="https://hub.example.com/healthz"}'
values: '1x11'
alert_rule_test:
- eval_time: 5m
alertname: HubNotAnswering
exp_alerts: []
- eval_time: 11m
alertname: HubNotAnswering
exp_alerts: []

# No answer from minute 1: HubNotAnswering fires at minute 6, stays, and
# ends with the first answer.
- interval: 1m
input_series:
- series: 'probe_success{job="clawctl-hub-healthz", instance="https://hub.example.com/healthz"}'
values: '1 0x14 1 1'
- series: 'up{job="clawctl-hub-healthz", instance="https://hub.example.com/healthz"}'
values: '1x17'
alert_rule_test:
- eval_time: 5m
alertname: HubNotAnswering
exp_alerts: []
- eval_time: 6m
alertname: HubNotAnswering
exp_alerts:
- exp_labels:
severity: critical
source: prometheus
machine: hub
job: clawctl-hub-healthz
instance: https://hub.example.com/healthz
exp_annotations:
summary: 'Hub 沒有回應'
description: 'https://hub.example.com/healthz 連續 5 分鐘沒有回 200。主控台打不開, 經這個網址報到的機器也報不到。下一步:到 Hub 主機查 Hub 服務的狀態。'
- eval_time: 15m
alertname: HubNotAnswering
exp_alerts:
- exp_labels:
severity: critical
source: prometheus
machine: hub
job: clawctl-hub-healthz
instance: https://hub.example.com/healthz
exp_annotations:
summary: 'Hub 沒有回應'
description: 'https://hub.example.com/healthz 連續 5 分鐘沒有回 200。主控台打不開, 經這個網址報到的機器也報不到。下一步:到 Hub 主機查 Hub 服務的狀態。'
- eval_time: 16m
alertname: HubNotAnswering
exp_alerts: []
- eval_time: 16m
alertname: HubProbeNotRunning
exp_alerts: []

# The exporter stops answering from minute 1: probe_success has no samples,
# so HubNotAnswering stays quiet and HubProbeNotRunning fires at minute 11.
- interval: 1m
input_series:
- series: 'probe_success{job="clawctl-hub-healthz", instance="https://hub.example.com/healthz"}'
values: '1 _x20'
- series: 'up{job="clawctl-hub-healthz", instance="https://hub.example.com/healthz"}'
values: '1 0x20'
alert_rule_test:
- eval_time: 10m
alertname: HubProbeNotRunning
exp_alerts: []
- eval_time: 11m
alertname: HubProbeNotRunning
exp_alerts:
- exp_labels:
severity: warning
source: prometheus
machine: hub
job: clawctl-hub-healthz
instance: https://hub.example.com/healthz
exp_annotations:
summary: 'Hub 探測沒有在跑'
description: 'Prometheus 連續 10 分鐘拿不到 Hub 探測的結果,這段時間沒有人在看 Hub 有沒有回應。 下一步:在觀測主機上跑 systemctl status prometheus-blackbox-exporter。'
- eval_time: 20m
alertname: HubNotAnswering
exp_alerts: []

# No scrape job at all: HubProbeNotRunning fires at minute 10.
- interval: 1m
input_series:
- series: 'up{job="node", instance="192.0.2.1:9100"}'
values: '1x20'
alert_rule_test:
- eval_time: 9m
alertname: HubProbeNotRunning
exp_alerts: []
- eval_time: 10m
alertname: HubProbeNotRunning
exp_alerts:
- exp_labels:
severity: warning
source: prometheus
machine: hub
job: clawctl-hub-healthz
exp_annotations:
summary: 'Hub 探測沒有在跑'
description: 'Prometheus 連續 10 分鐘拿不到 Hub 探測的結果,這段時間沒有人在看 Hub 有沒有回應。 下一步:在觀測主機上跑 systemctl status prometheus-blackbox-exporter。'
Loading
Loading