packaging: Prometheus-Regeln im Repo, nicht nur auf dem Host

Die Alarmregeln für /metrics lagen nur unter /opt/compose; beim Neuaufsetzen wären sie
weg gewesen, ohne dass es jemandem auffällt — ein Monitoring, das nichts mehr überwacht,
sieht aus wie ein Monitoring ohne Befund. Jetzt liegen sie als
packaging/prometheus-junction.yml im Repo, mit drei neuen Regeln für die zuletzt
gebauten Möglichkeiten: ein Schlüssel über 90 Prozent seines Monatsbudgets, ein
Peer-Cache, der schlecht antwortet (Anfragen laufen weiter, nur eben zum Anbieter —
deshalb braucht es einen Alarm), und ein Drain, der seit zehn Minuten läuft.

Auf n95 geladen: alle sechs Regeln health=ok, keine davon feuert.
This commit is contained in:
Hermes committed 2026-11-08 12:26:40 +00:00
1 parent b71bfb5a0a
commit 7547542244
2 files changed
+89

No files matched your search

+7
View File
@@ -504,6 +504,13 @@ Everything else is proxied to the endpoint the rules choose.
`make install` also installs `junction-wol` (C, 100 lines) for the `wake-wol.sh`
hook — building a magic packet should not need an interpreter either.
`packaging/` holds what belongs next to the binary but not inside it:
`junction.service` and `junction@.service` (the unit and the rolling-update template,
both with `RuntimeDirectory=junction…` — without it the control socket cannot be created
after a reboot), and `prometheus-junction.yml`, the alert rules for `/metrics`
(router down, endpoint unusable, heavy failover, a key near its budget, a peer cache
that answers badly, a drain that never finishes).
## Cluster: several instances, one port, one cache
No Redis, no etcd, no proxy in front — the cluster is two mechanisms, both optional.
+82
View File
@@ -0,0 +1,82 @@
# junction — der Router vor den Modellen.
#
# Zwei Dinge, die man verwechseln kann: "Prometheus erreicht den Router nicht" (up == 0)
# und "der Router erreicht einen Endpunkt nicht" (junction_endpoint_up == 0). Das erste
# ist ein Ausfall der Vermittlung selbst, das zweite oft nur ein Gerät, das absichtlich
# aus ist. Deshalb zwei Regeln mit unterschiedlicher Härte, und die Pause zählt nicht
# als Ausfall: ein pausierter Endpunkt ist eine Entscheidung, kein Fehler.
groups:
- name: junction
rules:
- alert: JunctionDown
expr: up{job="junction"} == 0
for: 3m
labels:
severity: critical
system: junction
annotations:
summary: "junction ist nicht scrapebar ({{ $labels.instance }})"
description: "Der Router vor den Modellen antwortet nicht auf /metrics. Jede Anfrage der Agenten läuft derzeit entweder direkt zu einem Anbieter oder gar nicht."
runbook: "systemctl status junction; journalctl -u junction -n 50. Der Dienst hat Restart=always — antwortet er trotzdem nicht, ist die Konfiguration kaputt, nicht der Prozess (junction --config /etc/junction/junction.conf von Hand starten zeigt die Zeile)."
- alert: JunctionEndpointDown
expr: junction_endpoint_up == 0 and on(endpoint) junction_endpoint_paused == 0
for: 30m
labels:
severity: warning
system: junction
annotations:
summary: "Endpunkt {{ $labels.endpoint }} ist seit 30 Minuten nicht nutzbar"
description: "pausiert, offline, im Cooldown oder über dem harten Budget. Die Kette läuft weiter, solange ein anderes Ziel greift — diese Meldung heißt: ein Ziel fehlt dauerhaft."
runbook: "curl -s localhost:8090/status | jq '.endpoints[] | select(.name==\"{{ $labels.endpoint }}\")' — last_error und last_hook_reason nennen den Grund. POST /admin/resume/<name> räumt Pause, Cooldown und Offline."
- alert: JunctionFailoverHeavy
expr: sum(rate(junction_requests_total{outcome="fail"}[10m])) > 0.05
for: 10m
labels:
severity: warning
system: junction
annotations:
summary: "junction scheitert an mehr als 3 Anfragen pro Minute"
description: "Requests, die keinen Endpunkt gefunden haben. Meist ein 429-Sturm beim Anbieter, ein erschöpftes Budget oder ein Modell, das kein Ziel bedienen kann."
runbook: "journalctl -u junction -n 100 | grep -E 'failed|retry|no_endpoint'. Der Retry (retry_num) fängt kurze Aussetzer ab; was hier zählt, ist schon durch alle Versuche gefallen."
# A key that is nearly out of budget is a client that will start getting 403s soon.
# The number comes from the same ledger /spend reads, so the alert and the dashboard
# cannot disagree — but it is this process's own bookkeeping, not the provider's.
- alert: JunctionVkeyBudgetNearlySpent
expr: junction_vkey_budget_usd > 0 and (junction_vkey_spend_usd_total / junction_vkey_budget_usd) > 0.9
for: 5m
labels:
severity: warning
system: junction
annotations:
summary: "virtual key {{ $labels.vkey }} has spent over 90 % of its monthly budget"
description: "At {{ $value | printf \"%.2f\" }} of the ratio. Once the budget is used up junction answers 403 vkey_budget_exhausted for that key — a client, not an endpoint, stops working."
runbook: "curl -s localhost:8090/spend | jq '.vkeys[] | select(.name==\"{{ $labels.vkey }}\")' shows where the money went. Either raise the budget in the vkey line or point the client at a cheaper model."
# The peer cache is a shortcut; errors mean the shortcut is gone, not that requests
# fail. That is exactly why it needs an alert: nothing user-visible breaks.
- alert: JunctionCachePeerFailing
expr: junction_cache_peers > 0 and increase(junction_cache_peer_errors_total[10m]) > 10
for: 10m
labels:
severity: warning
system: junction
annotations:
summary: "the shared cache reaches its peers {{ $value | printf \"%.0f\" }} times badly per 10 min"
description: "Requests are still served, from the provider rather than from the peer's cache. Errors here are: peer not reachable, peer secret wrong, frame rejected."
runbook: "curl -s -H \"X-Junction-Peer: $JUNCTION_CACHE_KEY\" http://<peer>:<cache port>/cache/stats — no answer means the port is down or cache_secret_env differs between the nodes. Check journalctl -u junction | grep cache_peer."
# A drain that never finishes is an instance that has stopped taking traffic and
# still holds its slot: the rolling update is half done and nobody noticed.
- alert: JunctionDrainStuck
expr: junction_draining == 1
for: 10m
labels:
severity: warning
system: junction
annotations:
summary: "an instance has been draining for 10 minutes"
description: "The listening socket is closed (no new requests) but the process has not exited. Either a request hangs longer than drain_timeout or the drain path itself is stuck; until it exits, a rolling update is only half done."
runbook: "curl -s localhost:8090/status | jq '.queue' — inflight tells whether requests are really running. journalctl -u junction | grep -E 'draining|drained|drain_timeout'."