432 lines
14 KiB
Markdown
432 lines
14 KiB
Markdown
# `rud.json` Configuration Guide
|
|
|
|
**R u ded? (`rud`)** is configured entirely through a single JSON file (`rud.json` by default). The configuration is loaded once at startup and controls:
|
|
|
|
1. **`server`** — The single HTTP endpoint binding, auto-refresh interval, and HTTP status codes.
|
|
2. **`storage`** — In-memory ring-buffer size and optional disk persistence.
|
|
3. **`defaults`** — Global fallback intervals, timeouts, retries, and degraded latency thresholds.
|
|
4. **`monitors`** — Health and uptime checks (`http`/`https`, `tcp`, `ping`, `dns`, `cmd`).
|
|
5. **`events`** — Declarative alert triggers (combining monitor boolean conditions, sustained durations, and metrics) and actions (`webhook`, `command`).
|
|
6. **`page`** — Minimalist styling (`theme`) and the explicit list of UI `elements` rendered on the web status page.
|
|
|
|
> **Note:** On the web status page, **only** the elements explicitly listed in `page.elements` are rendered (plus the `'Powered by R u ded?'` attribution footer). If `rud.json` does not exist when `rud` starts (or when you run `rud -init`), a sensible default `rud.json` is generated automatically.
|
|
|
|
---
|
|
|
|
## Duration Format
|
|
|
|
All duration fields in `rud.json` accept human-readable Go duration strings:
|
|
- `"500ms"` (500 milliseconds)
|
|
- `"10s"` (10 seconds)
|
|
- `"5m"` (5 minutes)
|
|
- `"5h"` (5 hours)
|
|
- `"1h30m"` (1 hour 30 minutes)
|
|
|
|
---
|
|
|
|
## 1. `server` Section
|
|
|
|
Controls the single HTTP endpoint served by `rud`.
|
|
|
|
```json
|
|
"server": {
|
|
"listen": ":8080",
|
|
"endpoint": "/",
|
|
"refresh_interval": "10s",
|
|
"status_codes": {
|
|
"html": {
|
|
"up": 200,
|
|
"degraded": 200,
|
|
"down": 200,
|
|
"pending": 200
|
|
},
|
|
"json": {
|
|
"up": 200,
|
|
"degraded": 200,
|
|
"down": 503,
|
|
"pending": 200
|
|
}
|
|
}
|
|
}
|
|
```
|
|
|
|
| Field | Type | Default | Description |
|
|
| :--- | :--- | :--- | :--- |
|
|
| `listen` | `string` | `":8080"` | TCP address and port to bind (`"127.0.0.1:8080"`, `":8080"`). |
|
|
| `endpoint` | `string` | `"/"` | The single HTTP path served. All other paths return `404 Not Found`. |
|
|
| `refresh_interval` | `Duration` | `"10s"` | Browser live-update polling interval (fetches `<endpoint>?format=json`). Set to `"0s"` to disable client-side polling. |
|
|
| `status_codes.html` | `object` | `200` for all | HTTP status codes returned for HTML requests per global state (`up`, `degraded`, `down`, `pending`). Keeping HTML at `200` prevents Cloudflare Tunnel from replacing your status page with a Cloudflare 5xx error page. |
|
|
| `status_codes.json` | `object` | `200` (`503` on `down`) | HTTP status codes returned when JSON is requested via `Accept: application/json` or `?format=json`. |
|
|
|
|
---
|
|
|
|
## 2. `storage` Section
|
|
|
|
Controls the in-memory check history ring buffer and optional state persistence across restarts.
|
|
|
|
```json
|
|
"storage": {
|
|
"history_size": 60,
|
|
"persistence_file": "./data/rud_state.json",
|
|
"save_interval": "1m"
|
|
}
|
|
```
|
|
|
|
| Field | Type | Default | Description |
|
|
| :--- | :--- | :--- | :--- |
|
|
| `history_size` | `int` | `60` | Maximum number of recent check results retained in memory per monitor. |
|
|
| `persistence_file` | `string` | `""` (disabled) | Optional file path to save and restore monitor state and history across restarts. Leave empty (`""`) for pure in-memory operation. |
|
|
| `save_interval` | `Duration` | `"1m"` | How often state is written to `persistence_file` (also saved automatically on graceful shutdown). |
|
|
|
|
---
|
|
|
|
## 3. `defaults` Section
|
|
|
|
Provides fallback check settings when a monitor omits them.
|
|
|
|
```json
|
|
"defaults": {
|
|
"interval": "15s",
|
|
"timeout": "5s",
|
|
"retries": 1,
|
|
"degraded_latency": "750ms"
|
|
}
|
|
```
|
|
|
|
| Field | Type | Default | Description |
|
|
| :--- | :--- | :--- | :--- |
|
|
| `interval` | `Duration` | `"30s"` | How often each monitor check runs. |
|
|
| `timeout` | `Duration` | `"5s"` | Per-attempt timeout for a check. |
|
|
| `retries` | `int` | `1` | Number of immediate retry attempts before marking a monitor as `"down"`. |
|
|
| `degraded_latency` | `Duration` | `"1000ms"` | If a check succeeds but takes longer than this threshold, its state becomes `"degraded"`. |
|
|
|
|
---
|
|
|
|
## 4. `monitors` Section
|
|
|
|
An array of health checks. Every monitor shares these base fields:
|
|
|
|
| Field | Type | Required | Description |
|
|
| :--- | :--- | :--- | :--- |
|
|
| `id` | `string` | **Yes** | Unique identifier for the monitor (referenced in `page.elements` and `events`). |
|
|
| `name` | `string` | No | Friendly display name (defaults to `id`). |
|
|
| `description` | `string` | No | Short description shown when `show_description` is enabled. |
|
|
| `link` | `string` | No | Optional URL to link the monitor's name to on the status page. |
|
|
| `method` | `string` | **Yes** | Check method: `"http"`, `"https"`, `"tcp"`, `"ping"`, `"dns"`, or `"cmd"`. |
|
|
| `interval` | `Duration` | No | Overrides `defaults.interval`. |
|
|
| `timeout` | `Duration` | No | Overrides `defaults.timeout`. |
|
|
| `retries` | `int` | No | Overrides `defaults.retries`. |
|
|
| `degraded_latency` | `Duration` | No | Overrides `defaults.degraded_latency`. |
|
|
|
|
### Method 1: HTTP / HTTPS (`"method": "http"` or `"https"`)
|
|
|
|
```json
|
|
{
|
|
"id": "main-api",
|
|
"name": "Core API",
|
|
"method": "https",
|
|
"url": "https://api.gsdistance.org/health",
|
|
"http_method": "GET",
|
|
"expected_status": [200, 204],
|
|
"headers": {
|
|
"Authorization": "Bearer secret-token",
|
|
"X-Custom-Header": "rud"
|
|
},
|
|
"body": "",
|
|
"body_regex": "\"ok\":\\s*true",
|
|
"insecure_skip_verify": false
|
|
}
|
|
```
|
|
|
|
- `url` (**required**): Full HTTP/HTTPS endpoint URL.
|
|
- `http_method`: HTTP verb (`"GET"`, `"POST"`, `"HEAD"`, etc.; default `"GET"`).
|
|
- `expected_status`: List of accepted HTTP status codes (defaults to any `200..299` if omitted).
|
|
- `headers`: Key-value map of custom request headers.
|
|
- `body`: Optional request payload body string.
|
|
- `body_regex`: Optional regular expression that must match the response body.
|
|
- `insecure_skip_verify`: Set `true` to ignore self-signed/expired TLS certificates.
|
|
|
|
### Method 2: TCP Port (`"method": "tcp"`)
|
|
|
|
```json
|
|
{
|
|
"id": "postgres-db",
|
|
"name": "PostgreSQL Primary",
|
|
"method": "tcp",
|
|
"target": "10.0.0.12:5432"
|
|
}
|
|
```
|
|
|
|
- `target` (**required**): `host:port` to verify TCP 3-way handshake connectivity and latency.
|
|
|
|
### Method 3: Direct ICMP Ping (`"method": "ping"`)
|
|
|
|
```json
|
|
{
|
|
"id": "edge-router",
|
|
"name": "Edge Gateway",
|
|
"method": "ping",
|
|
"host": "1.1.1.1",
|
|
"count": 1,
|
|
"privileged": false
|
|
}
|
|
```
|
|
|
|
- `host` (**required**): IP address or hostname to ping.
|
|
- `count`: Number of echo packets (default `1`).
|
|
- `privileged`: Uses native ICMP echo sockets with automatic fallback to the system `ping` command.
|
|
|
|
### Method 4: DNS Record Check (`"method": "dns"`)
|
|
|
|
```json
|
|
{
|
|
"id": "domain-dns",
|
|
"name": "GsDistance DNS",
|
|
"method": "dns",
|
|
"host": "gsdistance.org",
|
|
"record_type": "A",
|
|
"resolver": "1.1.1.1:53",
|
|
"expected_regex": "^(104|172)\\."
|
|
}
|
|
```
|
|
|
|
- `host` (**required**): Domain name to resolve.
|
|
- `record_type`: `"A"`, `"AAAA"`, `"CNAME"`, `"MX"`, `"TXT"`, or `"NS"` (default `"A"`).
|
|
- `resolver`: Optional custom DNS server (`ip:port` or `ip`). Uses system resolver if omitted.
|
|
- `expected_regex`: Optional regular expression verified against returned DNS records.
|
|
|
|
### Method 5: Custom Command / Script (`"method": "cmd"`)
|
|
|
|
```json
|
|
{
|
|
"id": "disk-space",
|
|
"name": "Root Disk Free Space",
|
|
"method": "cmd",
|
|
"command": "df -h / | awk 'NR==2 {print $5}'",
|
|
"shell": true,
|
|
"expected_exit_code": 0,
|
|
"output_regex": "^[0-8][0-9]%$"
|
|
}
|
|
```
|
|
|
|
- `command` (**required**): Executable or shell command line.
|
|
- `args`: Optional array of arguments when `shell` is `false`.
|
|
- `shell`: When `true`, executes via `/bin/sh -c`.
|
|
- `working_dir`: Optional working directory path.
|
|
- `env`: Optional map of environment variables (`{"KEY": "VALUE"}`).
|
|
- `expected_exit_code`: Expected process exit status (default `0`).
|
|
- `output_regex`: Optional regular expression matched against combined `stdout`/`stderr`.
|
|
|
|
---
|
|
|
|
## 5. `events` Section (Declarative Triggers & Actions)
|
|
|
|
Events allow you to declaratively combine **monitor boolean state triggers**, **sustained duration requirements (`for`)**, and **metric triggers** using `"and"` / `"or"` logic to execute outbound webhooks or custom shell commands.
|
|
|
|
```json
|
|
"events": [
|
|
{
|
|
"id": "cluster-critical",
|
|
"name": "Cluster Down or Sustained High Latency",
|
|
"cooldown": "30m",
|
|
"trigger_on_recovery": true,
|
|
"condition": {
|
|
"operator": "or",
|
|
"conditions": [
|
|
{
|
|
"type": "state",
|
|
"monitors": ["1", "2", "3"],
|
|
"match": "all",
|
|
"state": "down"
|
|
},
|
|
{
|
|
"type": "state",
|
|
"monitors": ["*"],
|
|
"match": "any",
|
|
"state": "down",
|
|
"for": "5h"
|
|
},
|
|
{
|
|
"type": "metric",
|
|
"monitors": ["main-api"],
|
|
"match": "any",
|
|
"metric": "uptime_pct",
|
|
"comparator": "<",
|
|
"value": 99.0,
|
|
"for": "15m"
|
|
}
|
|
]
|
|
},
|
|
"actions": [
|
|
{
|
|
"type": "webhook",
|
|
"url": "https://hooks.example.com/rud",
|
|
"http_method": "POST",
|
|
"headers": {
|
|
"Authorization": "Bearer webhook-secret"
|
|
},
|
|
"body_template": "{\"event\":\"{{.EventName}}\",\"status\":\"{{.Status}}\",\"monitors\":\"{{.TriggeredMonitors}}\",\"timestamp\":\"{{.Timestamp}}\"}"
|
|
},
|
|
{
|
|
"type": "command",
|
|
"command": "/usr/local/bin/notify-oncall.sh \"{{.EventName}}\" \"{{.Status}}\" \"{{.TriggeredMonitors}}\"",
|
|
"shell": true,
|
|
"timeout": "10s"
|
|
}
|
|
]
|
|
}
|
|
]
|
|
```
|
|
|
|
### Condition Fields
|
|
|
|
- **Boolean Combinators**:
|
|
- `operator`: `"and"` or `"or"`
|
|
- `conditions`: Array of nested condition objects (can be nested to any depth).
|
|
- **Monitor State Conditions (`"type": "state"`)**:
|
|
- `monitors`: Array of monitor IDs (e.g., `["1", "2", "3"]`) or `["*"]` for all monitors.
|
|
- `match`: `"all"` (every listed monitor must match) or `"any"` (at least one listed monitor must match).
|
|
- `state`: `"down"`, `"degraded"`, or `"up"`.
|
|
- `for`: Optional sustained duration (e.g., `"5h"` — monitor must remain in `state` continuously for at least 5 hours).
|
|
- **Metric Conditions (`"type": "metric"`)**:
|
|
- `monitors`: Array of monitor IDs or `["*"]`.
|
|
- `match`: `"all"` or `"any"`.
|
|
- `metric`: `"uptime_pct"`, `"latency_ms"`, or `"consecutive_failures"`.
|
|
- `comparator`: `"<"`, `"<="`, `">"`, `">="`, `"=="`, or `"!="`.
|
|
- `value`: Numeric threshold (e.g., `99.5` for 99.5% uptime, `500` for 500ms latency).
|
|
- `for`: Optional sustained duration that the metric inequality must hold continuously.
|
|
|
|
### Action Template Variables
|
|
|
|
Both `webhook` (`body_template`) and `command` (`command`, `args`) support Go `text/template` placeholders:
|
|
- `{{.EventID}}` — ID of the event rule
|
|
- `{{.EventName}}` — Name of the event rule
|
|
- `{{.Status}}` — `"TRIGGERED"` or `"RESOLVED"`
|
|
- `{{.OverallState}}` — Global status (`"up"`, `"degraded"`, `"down"`)
|
|
- `{{.OverallUptimePct}}` — Aggregate uptime percentage
|
|
- `{{.TriggeredMonitors}}` — Comma-separated list of monitor IDs that matched
|
|
- `{{.MonitorsJSON}}` — Raw JSON array of matching monitor states
|
|
- `{{.Timestamp}}` — ISO-8601 UTC timestamp
|
|
|
|
Command actions also receive environment variables: `RUD_EVENT_ID`, `RUD_EVENT_NAME`, `RUD_EVENT_STATUS`, `RUD_OVERALL_STATE`, `RUD_TRIGGERED_MONITORS`, and `RUD_TIMESTAMP`.
|
|
|
|
---
|
|
|
|
## 6. `page` Section (Theme & UI Elements)
|
|
|
|
The web status page is minimalist and strictly renders **only** the elements configured in `page.elements` in the exact order they appear, followed by the `'Powered by R u ded?'` footer.
|
|
|
|
### `page.theme`
|
|
|
|
```json
|
|
"theme": {
|
|
"bg_color": "#111111",
|
|
"card_bg_color": "#191919",
|
|
"text_color": "#e5e5e5",
|
|
"muted_text_color": "#888888",
|
|
"border_color": "#2e2e2e",
|
|
"accent_color": "#cccccc",
|
|
"up_color": "#2ecc71",
|
|
"degraded_color": "#f1c40f",
|
|
"down_color": "#e74c3c",
|
|
"pending_color": "#7f8c8d",
|
|
"font_family": "ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace",
|
|
"max_width": "820px",
|
|
"border_radius": "2px",
|
|
"custom_css": ""
|
|
}
|
|
```
|
|
|
|
### `page.elements` Types
|
|
|
|
#### 1. `header`
|
|
Renders the page heading, optional subtitle, live indicator dot, and last-updated timestamp.
|
|
```json
|
|
{
|
|
"type": "header",
|
|
"title": "R u ded?",
|
|
"subtitle": "Minimalist system status & health monitor",
|
|
"align": "split",
|
|
"show_last_updated": true,
|
|
"show_live_indicator": true
|
|
}
|
|
```
|
|
- `align`: `"split"` (title left, timestamp right), `"left"`, or `"center"`.
|
|
|
|
#### 2. `status_banner`
|
|
Renders a global status bar colored by the overall state (`up`, `degraded`, `down`, `pending`).
|
|
```json
|
|
{
|
|
"type": "status_banner",
|
|
"messages": {
|
|
"up": "No — All systems operational",
|
|
"degraded": "Kinda — Some systems are experiencing degraded performance",
|
|
"down": "Yes — One or more systems are down",
|
|
"pending": "Checking system status..."
|
|
},
|
|
"show_overall_uptime": true,
|
|
"show_counts": true
|
|
}
|
|
```
|
|
|
|
#### 3. `summary_cards`
|
|
Renders a compact row of aggregate metrics.
|
|
```json
|
|
{
|
|
"type": "summary_cards",
|
|
"title": "Overview",
|
|
"metrics": ["total", "up", "degraded", "down", "overall_uptime", "avg_latency"]
|
|
}
|
|
```
|
|
|
|
#### 4. `monitor_group`
|
|
Renders a list or grid of monitors with granular toggles for bars, badges, and metadata. You can include multiple `monitor_group` elements to organize services by category.
|
|
```json
|
|
{
|
|
"type": "monitor_group",
|
|
"title": "Core Infrastructure",
|
|
"description": "Primary endpoints",
|
|
"monitors": ["rud-http", "rud-tcp"],
|
|
"layout": "list",
|
|
"display": {
|
|
"show_bar": true,
|
|
"bar_ticks": 40,
|
|
"show_uptime": true,
|
|
"show_latency": true,
|
|
"show_status_badge": true,
|
|
"show_method": true,
|
|
"show_target": false,
|
|
"show_description": true,
|
|
"show_message": false,
|
|
"show_last_checked": false,
|
|
"custom_labels": {
|
|
"up": "OK",
|
|
"degraded": "SLOW",
|
|
"down": "DED",
|
|
"pending": "WAIT"
|
|
}
|
|
}
|
|
}
|
|
```
|
|
- `monitors`: Array of monitor IDs to include in this group, or `["*"]` for all monitors.
|
|
- `layout`: `"list"` (vertical stack) or `"grid"` (responsive multi-column grid).
|
|
|
|
#### 5. `custom_block`
|
|
Renders a static notice, maintenance message, or text block.
|
|
```json
|
|
{
|
|
"type": "custom_block",
|
|
"title": "Scheduled Maintenance",
|
|
"content": "Database maintenance scheduled for Sunday 02:00 UTC.",
|
|
"style": "info"
|
|
}
|
|
```
|
|
- `style`: `"neutral"`, `"info"`, `"warning"`, or `"danger"`.
|
|
|
|
#### 6. `divider`
|
|
Renders a clean horizontal separator line between elements.
|
|
```json
|
|
{
|
|
"type": "divider"
|
|
}
|
|
```
|