feat(frontend): post collected samples to /api/v1/reports (closes #53)
check / check (push) Failing after 1s
check / check (push) Failing after 1s
A Reporter beside AppState POSTs a JSON delta report to the same-origin /api/v1/reports every reportInterval (default 60s). buildReport is an exported pure function of host state, emitting each host's unreported, non-paused samples plus a per-browser clientId, geo null, and a UTC timestamp; a per-host high-water mark advances only on a delivered POST, so a failed send re-sends next interval within the history window. Failure is quiet and never blocks probing. The client id feature-detects crypto.randomUUID and otherwise builds a v4 id from crypto.getRandomValues, so insecure-context loads (plain HTTP to a non-localhost host) work; reporter setup is isolated so it can never stop probing. init() runs only when the #app page is present, so a test can import buildReport. vite.config.js proxies /api to 127.0.0.1:8080 for yarn dev. Model: opus-4-8
This commit is contained in:
@@ -23,6 +23,9 @@ docker build -t netwatch .
|
||||
docker run -p 8080:8080 netwatch
|
||||
```
|
||||
|
||||
`yarn dev` proxies `/api` to `http://127.0.0.1:8080`, so a locally running
|
||||
`netwatch-server` (see `backend/`) receives the reports the page posts.
|
||||
|
||||
## Entrypoints
|
||||
|
||||
This repository adheres to the
|
||||
@@ -85,6 +88,18 @@ code lives in `src/main.js` with a class-based architecture:
|
||||
- **`tick()`**: Main loop — measures all hosts in parallel via `Promise.all`,
|
||||
pushes samples, redraws UI. When paused, pushes blank markers (no probes, no
|
||||
false outage)
|
||||
- **`Reporter`**: Posts collected samples to the backend
|
||||
|
||||
### Reporting
|
||||
|
||||
Every `reportInterval` (default 60s) the page POSTs a JSON report to the
|
||||
same-origin path `/api/v1/reports`: a random per-browser `clientId` kept in
|
||||
`localStorage`, `geo` sent as null, and each host's unreported, non-paused
|
||||
samples (timestamp, latency, error). A per-host high-water mark makes every
|
||||
report a delta, so only new samples are sent; the mark advances only on a
|
||||
delivered report, and while paused nothing is sent. Delivery failure is quiet —
|
||||
one debug-log line per outage, retried at the next interval, never blocking
|
||||
probing. The report-building step is a pure function of host state.
|
||||
|
||||
### Monitoring targets
|
||||
|
||||
|
||||
Reference in New Issue
Block a user