Docs restructure, code review, gatherer reliability, JWT key fail-closed
Documentation - Three levels: DOCS/General (overview, configuration), DOCS/Deployment (choose a method, first steps), details per method in Containers/ and System_Services/; new root README and DOCS/README map. - Remove superseded pages (Deployment.md, Deployment_Docker/Native.md, Index.md); split the two scenario guides by section. - Isolate the Timeweb/Hysteria2 records in DEPLOYMENTS/timeweb-hysteria2/ (not linked from DOCS, listed in .graphifyignore). - Add DOCS/code_review/ with a time-stamped analysis of the code base. Gatherer (BUG-02, BUG-03) - Session key (CN, address, connected_since_ts), baseline from the active_sessions snapshot, grace period for sessions missing from the status. - Status file integrity (TITLE/TIME/END) and freshness; a torn read skips the tick. - Cache applied after commit; main loop survives exceptions, backs off, and stops cleanly on SIGTERM/SIGINT; new client rows start with the first frame's totals; five tests. JWT signing key (SEC-01) - No built-in default: Core and Profiler refuse to start with a missing, placeholder or short (< 32) key; shipped config.ini has an empty value. - Same rule in install.sh, update.sh (issues a new key when missing or weak), docker lib/entrypoint; five tests, conftest.py for the test key. Each change has a plan and a summary under DOCS/Changes/. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
f95a0b63e6
commit
ad6995bb63
85 files changed
+2805
-1280
No files matched your search
@@ -214,6 +214,10 @@ Real-time list of currently connected clients.
|
||||
|
||||
### `GET /sessions`
|
||||
|
||||
Field notes:
|
||||
- `connected_since`: the real start of the session as reported by OpenVPN (`Connected Since (time_t)` of the status file), in **UTC**, format `YYYY-MM-DD HH:MM:SS`. It does not depend on when the gatherer first saw the session (older versions returned the local time of the first observation). If OpenVPN does not report the value, the time of the first observation (UTC) is used.
|
||||
- `last_seen`: time of the last gatherer tick that saw the session (gatherer host local time).
|
||||
|
||||
#### Example Response
|
||||
```json
|
||||
{
|
||||
|
||||
@@ -8,13 +8,29 @@ The gatherer runs a continuous loop (default interval: **10 seconds**).
|
||||
|
||||
### A. Log Parsing
|
||||
- **Source**: `/var/log/openvpn/openvpn-status.log` (Status File v2, CSV format).
|
||||
- **Target Fields**: `Common Name`, `Real Address`, `Bytes Sent`, `Bytes Received`.
|
||||
- **Target Fields**: `Common Name`, `Real Address`, `Bytes Sent`, `Bytes Received`, `Connected Since (time_t)`.
|
||||
- **Filtering**: Only lines starting with `CLIENT_LIST`.
|
||||
|
||||
### B. Delta Calculation (`update_client_status_and_bytes`)
|
||||
The log provides *lifetime* counters for a session. The gatherer calculates the traffic *delta* (increment) since the last check.
|
||||
- **Logic**: `Increment = Current Value - Last Saved Value`.
|
||||
- **Reset Detection**: If `Current Value < Last Saved Value`, it assumes a session/server restart and counts the entire `Current Value` as the increment.
|
||||
The log provides *lifetime* counters for a session. The gatherer calculates the traffic *delta* (increment) since the last check. A session is identified by the key `(common_name, real_address, connected_since_ts)`, where `connected_since_ts` is the `Connected Since (time_t)` column (index 8) of `CLIENT_LIST`. A reconnect always gets a new `connected_since_ts` and therefore a new session.
|
||||
|
||||
| Situation | Increment |
|
||||
|-----------|-----------|
|
||||
| Key is in the in-memory cache | `Current - Previous`. If a counter decreased (same key), it is treated as a reset and the whole `Current` is counted. |
|
||||
| Not in cache, key is in the baseline (snapshot of `active_sessions` loaded at start, or a session recently dropped from the cache) | `Current - Baseline` (traffic during a daemon downtime is counted, nothing is counted twice). |
|
||||
| Not in cache, session started after the daemon start (with a margin of `2 x check_interval`) | New session: the whole `Current` value, whatever its size. For a client seen for the first time the `clients` row is created with these totals (the first frame is not lost). |
|
||||
| Not in cache, session older than the daemon and no snapshot (first start after an update, lost DB) | Baseline: increment `0`, a WARNING with the client name is logged (the only case of lost traffic, once per session). |
|
||||
| `connected_since_ts` is missing or not a number (non-standard status file) | Fallback heuristic: counters below 10 MB are counted as a new session, otherwise increment `0`; a WARNING is logged. |
|
||||
|
||||
Cache changes are collected in a temporary structure and applied only after the database transaction is committed. If the transaction fails, the cache is unchanged and the next tick counts the difference for the whole interval.
|
||||
|
||||
### B1. Read Validity, Grace Period, Restart and Shutdown
|
||||
- **Validity** (`parse_status`): the status file must contain a `TITLE` line, a `TIME,<text>,<epoch>` line and end with `END`. A missing file, a read error or an incomplete file (read while OpenVPN rewrites it) makes the gatherer **skip the tick entirely**: the database and the cache are not touched, and the next valid tick counts the difference for the whole interval. After `status_invalid_max` (default 6) skipped ticks in a row the message is logged at ERROR level.
|
||||
- **Freshness**: if `TIME` is older than `status_stale_seconds` (default 60 s), OpenVPN is considered stopped: there are no clients, all clients become `Disconnected`, sessions leave the cache via the grace period. A valid, fresh file without `CLIENT_LIST` lines simply means no clients.
|
||||
- **Grace period**: a session missing from the status is not dropped at once. Its `missing_ticks` counter grows each tick and the session is removed from the cache when it reaches `session_grace_ticks` (default 3, about 30 s). A session that comes back with the same key continues without double counting. A removed session is remembered (last counters, 1 hour) so that a late return with the same key is still counted as a continuation.
|
||||
- **Restart**: at start the gatherer loads `active_sessions` as the baseline (see the table above). `active_sessions.connected_since` stores the real session start in UTC (`YYYY-MM-DD HH:MM:SS`), which is also what `/sessions` returns.
|
||||
- **Resilience and shutdown**: every cycle runs in `try/except`; a failure is logged with a traceback and does not stop the daemon. After consecutive failures the pause grows as `min(interval * 2^n, 60)` seconds and resets after a successful cycle. `SIGTERM`/`SIGINT` only set a stop flag: the current cycle is finished, the pause is interrupted and the process exits normally (code 0).
|
||||
- **Settings** (`[openvpn_monitor]`, can be overridden by `OVPMON_OPENVPN_MONITOR_*`): `check_interval` (>= 1), `session_grace_ticks` (>= 0), `status_stale_seconds` (>= 1), `status_invalid_max` (>= 1). An invalid value stops the start with a clear message and exit code 1.
|
||||
|
||||
### C. Rate Calculation
|
||||
- **Speed**: Calculated as `Increment * 8 / (Interval * 1_000_000)` to get **Mbps**.
|
||||
|
||||
Reference in new issue
Block a user