This commit is contained in:
tyuXX 2026-11-07 15:22:48 +03:00
parent d37503c863
commit 1509789cde
19 changed files with 1534 additions and 112 deletions

View file

@ -3,7 +3,7 @@
**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.
2. **`storage`** — In-memory ring-buffer size, daily JSONL history logs (zstd-compressed), the SQLite stats database, and optional state 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`).
@ -53,7 +53,7 @@ Controls the single HTTP endpoint served by `rud`.
| 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`. |
| `endpoint` | `string` | `"/"` | The single HTTP path served for the status page. All other paths return `404 Not Found`, except `/monitor` which serves the per-monitor history pages. |
| `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`. |
@ -62,21 +62,41 @@ Controls the single HTTP endpoint served by `rud`.
## 2. `storage` Section
Controls the in-memory check history ring buffer and optional state persistence across restarts.
Controls the in-memory check history ring buffer, long-term history logging, the stats database, and optional state persistence across restarts.
```json
"storage": {
"history_size": 60,
"persistence_file": "./data/rud_state.json",
"save_interval": "1m"
"save_interval": "1m",
"logs_dir": "logs",
"stats_db": "stats.db",
"stats_retention_days": 90
}
```
| Field | Type | Default | Description |
| :--- | :--- | :--- | :--- |
| `history_size` | `int` | `60` | Maximum number of recent check results retained in memory per monitor. |
| `history_size` | `int` | `60` | Maximum number of recent check results retained in memory per monitor (powers the live tick-bars on the status page). |
| `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). |
| `logs_dir` | `string` | `"logs"` | Directory for the **full-history daily logs**. Every check result is appended as one JSON object per line to `DD-MM-YYYY.json`. When the day rolls over (or on startup for stale files), the previous day's file is zstd-compressed to `DD-MM-YYYY.json.zst` and the original removed — full history is retained indefinitely for external viewers. Set to `"off"` or `"none"` to disable. |
| `stats_db` | `string` | `"stats.db"` | Path to the **SQLite stats database** (pure-Go driver, no cgo). Stores per-hour aggregates (checks, up/degraded/down counts, latency sum/min/max) per monitor, powering the `/monitor` history page. Set to `"off"` or `"none"` to disable. |
| `stats_retention_days` | `int` | `90` | How many days of hourly stats are kept in `stats_db`; older rows are pruned automatically. Also caps the `?days=` window on the `/monitor` page. |
### Daily log format
Each line of `DD-MM-YYYY.json` is a self-contained JSON object, e.g.:
```json
{"monitor_id":"rud-http","name":"RUD Status Endpoint","method":"http","target":"http://127.0.0.1:8080/?format=json","timestamp":"2026-11-07T12:08:05Z","state":"up","latency_ms":0.84,"code":200,"message":"HTTP 200"}
```
Files are named in `DD-MM-YYYY` format using the server's local time zone. Once compressed they can be decompressed with any zstd tool (`zstd -d`, `unzstd`, etc.).
### Monitor history page
Every monitor name on the status page links to `/monitor?id=<monitor-id>` (also reachable as `/monitor/<monitor-id>`), which renders the monitor's current state plus server-side SVG charts of the retained stats: daily uptime and average latency over the last `stats_retention_days` days (or `?days=N`, capped at the retention window), and hourly uptime for the most recent period. `/monitor` without an ID lists all monitors.
---