Docs / Operate
Monitoring
From docs/guides/monitoring.md · last changed 2026-08-22 · Suggest a change
On this page 8 sections
This guide covers monitoring RCH in production environments.
Built-in Monitoring#
Status Commands#
# Overall system status
rch status
# Worker health and slots
rch status --workers
# Active and recent builds
rch status --jobs
# Aggregate statistics
rch status --stats
# Circuit breaker states
rch status --circuitsFleet-wide Reliability#
rch doctor --reliability checks the local machine. To assess the whole
fleet in one command, rch fleet doctor --reliability fans out over SSH to
every worker, runs the per-worker reliability doctor in parallel, and
aggregates the results. The fleet verdict is the worst per-worker verdict;
an unreachable worker counts as failing (you cannot prove a worker you could
not reach is healthy).
# Fleet-wide health (worst verdict wins)
rch fleet doctor --reliability
# Machine-readable envelope (per-worker drill-down under data.per_worker)
rch fleet doctor --reliability --json
# Narrow check across all workers
rch fleet doctor --reliability --scope pressure,topology
# Only specific workers
rch fleet doctor --reliability --workers css,bil
# Apply remediations fleet-wide (requires the confirmation gate)
rch fleet doctor --reliability --fix --fleet-confirmProbes run with bounded concurrency (≤16 simultaneous SSH sessions) and a
per-worker timeout (--worker-timeout, default 10s); a stalled worker is
reported as unreachable rather than hanging the command. --fix is a
fleet-wide mutation and requires --fleet-confirm; without it the command
runs check-only.
JSON Output#
For programmatic monitoring:
# Machine-readable output
rch status --json
rch status --workers --json
rch status --jobs --jsonExample JSON output:
{
"daemon": {
"running": true,
"uptime_secs": 3600,
"version": "0.2.0"
},
"workers": {
"total": 4,
"healthy": 3,
"degraded": 1,
"unreachable": 0
},
"builds": {
"active": 5,
"completed_last_hour": 42,
"failed_last_hour": 2
}
}Daemon Logs#
# Tail daemon logs
rch daemon logs
# With filters
rch daemon logs --tail 100
rch daemon logs --level warn
rch daemon logs --since "1 hour ago"Doctor: RUSTC_WRAPPER and one-time rebuilds#
rch doctor reports the state of Cargo's compile-wrapper variables
(RUSTC_WRAPPER, RUSTC_WORKSPACE_WRAPPER). Their rebuild semantics
differ, and the check explains exactly what each one does — verified
against current cargo by rch/tests/rustc_wrapper_fingerprint_fixture.rs:
| Variable | In Cargo fingerprints? | Effect of enable / change / remove |
|---|---|---|
RUSTC_WRAPPER |
No | Never forces a rebuild. The wrapper must still exec the real compiler. |
RUSTC_WORKSPACE_WRAPPER |
Yes (the value) | First use of a given value compiles the workspace once; reuse is incremental; removal falls back to previously valid artifacts without recompiling. |
What the check reports:
- Pass — no wrapper configured, a plain
RUSTC_WRAPPERthat resolves, or an unchangedRUSTC_WORKSPACE_WRAPPER. - Warning — first observation of a
RUSTC_WORKSPACE_WRAPPER, its value changed since the last doctor run, or the configured wrapper binary is missing/unreadable.
The one-time rebuild after enabling or changing a workspace wrapper is
expected behavior (Cargo fingerprints the wrapper value), not a regression.
Doctor persists a small identity marker under ~/.cache/rch/ to distinguish
"first observation" from "unchanged" across runs.
# See the check in machine-readable form
rch doctor --json | jq '.checks[] | select(.name == "rustc_wrapper")'Health Check Script#
Create a health check for your monitoring system:
#!/bin/bash
# rch-health-check.sh
set -e
# Check daemon
if ! rch daemon status >/dev/null 2>&1; then
echo "CRITICAL: RCH daemon not running"
exit 2
fi
# Check workers
WORKER_STATUS=$(rch status --workers --json)
UNHEALTHY=$(echo "$WORKER_STATUS" | jq '.workers | map(select(.status != "healthy")) | length')
if [ "$UNHEALTHY" -gt 0 ]; then
echo "WARNING: $UNHEALTHY unhealthy workers"
exit 1
fi
echo "OK: RCH healthy"
exit 0Metrics Collection#
Prometheus Integration#
RCH can expose metrics for Prometheus (if enabled):
# ~/.config/rch/config.toml
[metrics]
enabled = true
endpoint = "0.0.0.0:9090"
path = "/metrics"Available metrics:
rch_builds_total{worker, status}- Total builds by worker and statusrch_build_duration_seconds- Build duration histogramrch_worker_slots_available{worker}- Available slots per workerrch_worker_status{worker, status}- Worker health statusrch_transfer_bytes_total{direction}- Bytes transferredrch_circuit_state{worker, state}- Circuit breaker states
OpenTelemetry (OTLP) Export#
The doctor/hook event metrics (rch_doctor_*, rch_hook_*,
rch_request_duration_seconds) are mirrored to an OpenTelemetry collector
over OTLP/gRPC when enabled. The Prometheus inventory remains the single
source of truth — OTLP carries the same metric names and labels, so both
exposition surfaces can run simultaneously.
Enable it with environment variables (no config-file change needed):
export RCH_OTEL_ENABLED=1
# Preferred RCH-specific endpoint var; falls back to the OTel standard
# OTEL_EXPORTER_OTLP_ENDPOINT if unset.
export RCH_OTEL_EXPORTER_OTLP_ENDPOINT="http://localhost:4317"
export OTEL_SERVICE_NAME="rch" # resource service.name (default: rch)
export RCH_OTEL_EXPORT_INTERVAL_SECS=30 # periodic push cadence (default: 30)Behavior:
- Export activates only when both
RCH_OTEL_ENABLEDis truthy and an endpoint is set. Otherwise the pipeline stays off (Prometheus-only). - Fail-open: if the exporter cannot be built (bad endpoint, missing runtime),
RCH logs
otlp.exporter.build_failedand continues with Prometheus only. - Histogram bucket boundaries match the Prometheus definitions (hook hot-path buckets stay sub-millisecond).
StatsD/DataDog#
# ~/.config/rch/config.toml
[metrics]
statsd_endpoint = "127.0.0.1:8125"
statsd_prefix = "rch"Custom Metrics Script#
Collect metrics periodically:
#!/bin/bash
# rch-metrics.sh - Run every minute via cron
STATUS=$(rch status --json)
# Extract metrics
ACTIVE_BUILDS=$(echo "$STATUS" | jq '.builds.active')
HEALTHY_WORKERS=$(echo "$STATUS" | jq '.workers.healthy')
TOTAL_SLOTS=$(echo "$STATUS" | jq '.workers.total_slots')
USED_SLOTS=$(echo "$STATUS" | jq '.workers.used_slots')
# Send to your metrics system
curl -X POST "http://metrics.example.com/api/v1/push" \
-d "rch.builds.active=$ACTIVE_BUILDS" \
-d "rch.workers.healthy=$HEALTHY_WORKERS" \
-d "rch.slots.total=$TOTAL_SLOTS" \
-d "rch.slots.used=$USED_SLOTS"Alerting#
Alert Conditions#
| Condition | Severity | Recommended Action |
|---|---|---|
| Daemon not running | Critical | Auto-restart via systemd |
| All workers unreachable | Critical | Page on-call |
| Worker circuit open | Warning | Investigate, may self-recover |
| Worker degraded | Info | Monitor, check if persists |
| High build queue | Warning | Add workers or reduce load |
| Transfer failures | Warning | Check network |
Webhook Alerts#
# ~/.config/rch/config.toml
[alerts]
webhook_url = "https://hooks.slack.com/services/..."
alert_on = ["daemon_down", "circuit_open", "all_workers_down"]Reliability Verdict Webhooks#
rch doctor --reliability --watch continuously re-runs the reliability
probe suite and computes a tri-state verdict (Healthy / Degraded /
Failing). Configure first-class webhooks to fire the moment the verdict
transitions, so an on-call engineer is paged within ~50ms instead of
waiting on a log-shipper pipeline.
# ~/.config/rch/config.toml
[doctor.webhooks]
# Bound on concurrent in-flight deliveries (shared across endpoints).
# When exhausted, a delivery is dropped and journaled rather than queued
# unboundedly.
max_inflight = 16
[[doctor.webhooks.endpoints]]
name = "ops-slack"
url = "https://hooks.slack.com/services/T0/B0/..."
format = "slack" # slack | pagerduty | generic_json
on_transitions = ["healthy_to_degraded", "any_to_failing", "failing_to_healthy"]
retry_max = 3
retry_backoff_ms = 200 # doubles each retry (200, 400, 800, …)
timeout_ms = 5000
enabled = true
# Optional HMAC-SHA256 signing. The named env var holds the secret; the
# signature is sent as `X-RCH-Signature: sha256=<hex>`.
signing_secret_env = "RCH_WEBHOOK_HMAC"
[[doctor.webhooks.endpoints]]
name = "pagerduty-critical"
url = "https://events.pagerduty.com/v2/enqueue"
format = "pagerduty"
on_transitions = ["any_to_failing"] # `resolve` auto-fires on any_to_healthy
# Secrets are NEVER stored in config — only the NAME of the env var that
# holds them is. The runtime reads it at dispatch time.
routing_key_env = "RCH_PAGERDUTY_ROUTING_KEY"
enabled = trueTransition predicates (on_transitions): healthy_to_degraded,
degraded_to_failing, any_to_failing, any_to_degraded,
failing_to_healthy, degraded_to_healthy, any_to_healthy,
any_to_any. An empty list never fires; enabled = false is a
per-endpoint kill switch. The implicit baseline for the first sweep is
Healthy, so a watch session that starts in a bad state still pages.
Every delivery attempt (and its outcome) is journaled to the
rch::doctor::webhook tracing target for post-mortem audit. Webhook
dispatch is fail-open: a misconfigured or unreachable endpoint never
affects the watch loop's verdict or exit code.
Email Alerts#
#!/bin/bash
# rch-alert.sh
if ! rch daemon status >/dev/null 2>&1; then
echo "RCH daemon is down on $(hostname)" | \
mail -s "CRITICAL: RCH Daemon Down" oncall@example.com
fiPagerDuty Integration#
#!/bin/bash
# Alert to PagerDuty on critical issues
PD_KEY="your-pagerduty-integration-key"
if ! rch daemon status >/dev/null 2>&1; then
curl -X POST "https://events.pagerduty.com/v2/enqueue" \
-H "Content-Type: application/json" \
-d "{
\"routing_key\": \"$PD_KEY\",
\"event_action\": \"trigger\",
\"payload\": {
\"summary\": \"RCH daemon down on $(hostname)\",
\"severity\": \"critical\",
\"source\": \"$(hostname)\"
}
}"
fiDashboards#
Grafana Dashboard#
Import the provided Grafana dashboard from docs/observability/grafana-dashboard.json:
# Import via Grafana UI:
# 1. Go to Dashboards > Import
# 2. Upload the JSON file or paste its contents
# 3. Select your Prometheus data sourceKey panels included:
- Overview - Healthy workers, active builds, queue depth, slot utilization
- Build Metrics - Throughput by result, duration percentiles
- Worker Metrics - Slots per worker, health check latency, status
- Decision Latency (SLA Critical) - P95/P99 for non-compilation (<1ms) and compilation (<5ms)
- Circuit Breaker - State per worker, trip/recovery events
- Transfer Metrics - Upload/download throughput and duration
- Classification Tiers - Distribution and latency by tier
- API Metrics - Request rate by endpoint, active connections
Prometheus AlertManager Rules#
Deploy the alert rules from docs/observability/prometheus-alerts.yaml:
# Add to your Prometheus alerting rules configuration:
cp docs/observability/prometheus-alerts.yaml /etc/prometheus/rules/rch-alerts.yaml
# Or include via prometheus.yml:
# rule_files:
# - "rules/rch-alerts.yaml"Alert groups:
- rch-worker-health - Worker offline, stale, degraded alerts
- rch-circuit-breaker - Circuit breaker open, high trip rate
- rch-build-health - Failure rate, queue depth alerts
- rch-decision-latency-sla - CRITICAL alerts for latency SLA breaches
- rch-transfer - Slow transfer warnings
- rch-daemon - Daemon down, high connection count
- rch-slot-utilization - Capacity planning alerts
Terminal Dashboard#
Use the built-in TUI (if available):
rch dashboardOr a simple watch:
watch -n 5 'rch status --workers'Log Analysis#
Key Log Patterns#
# Find errors
rch daemon logs | grep -i error
# Find slow transfers
rch daemon logs | grep "transfer.*ms" | awk '$NF > 5000'
# Find circuit breaker events
rch daemon logs | grep -i "circuit"
# Find selection events
rch daemon logs | grep -i "selected.*worker"Log Shipping#
Forward logs to your log aggregation system:
# For systemd journals
journalctl --user -u rchd -f | nc logstash.example.com 5000
# Or configure rsyslog/fluentd/filebeatLog Levels#
Control log verbosity:
# ~/.config/rch/config.toml
[general]
log_level = "info" # error, warn, info, debug, traceOr at runtime:
RUST_LOG=debug rchdPeriodic Health Reports#
Generate daily reports:
#!/bin/bash
# rch-daily-report.sh
echo "RCH Daily Report - $(date)"
echo "=========================="
echo
echo "Build Statistics:"
rch status --stats
echo
echo "Worker Health:"
rch status --workers
echo
echo "Recent Failures:"
rch daemon logs --level error --since "24 hours ago"Schedule with cron:
0 9 * * * /path/to/rch-daily-report.sh | mail -s "RCH Daily Report" team@example.comCapacity Planning#
Track Usage Trends#
# Hourly stats collection
*/5 * * * * rch status --json >> /var/log/rch/metrics.jsonlAnalyze for patterns:
# Average slot utilization per hour
cat /var/log/rch/metrics.jsonl | \
jq -r '[.timestamp, .workers.used_slots/.workers.total_slots] | @csv' | \
datamash -t, groupby 1 mean 2Scale Triggers#
Consider adding workers when:
- Average slot utilization > 80%
- Build queue regularly > 0
- P95 build wait time > 30s
Consider reducing workers when:
- Average slot utilization < 30%
- Workers frequently idle
- Cost optimization needed