Show vessels per source and rolling usage counts in /v1/stats - #16
Merged
Conversation
Each source entry gains vessels (distinct MMSIs its stations heard in the last 30 minutes) and vessels_exclusive (heard by no other source in that window). Duplicates now record the vessel for the station that heard it second, so a source's count does not depend on who delivered the message first.
clients becomes an object: open streams, streams opened and HTTP API requests, each since start and over the last 60 minutes. Requests are counted once at the mux; streams where a subscriber is created, so all three stream endpoints count.
…t totals Events, duplicates, per-source events, streams opened and API requests are counted in hourly rings over the last 7 days and reported as last_24h/last_7d; uptime_s and the since-start totals go away, since deploys restart the server. The rings persist in <snapshot>-usage.json on the same 10 s tick as the vessel snapshot and on shutdown, and are restored on boot. Since-start counters remain only in /metrics.
There was a problem hiding this comment.
Pull request overview
This PR updates the public /v1/stats endpoint to answer marketing/ops questions directly by adding per-source vessel counts (including exclusive vessels) and replacing since-start counters with rolling 24h/7d usage windows persisted across restarts.
Changes:
- Add persisted rolling hourly “ring” counters (24h/7d) for events, duplicates, stream opens, HTTP requests, and per-source events.
- Extend per-source stats with
vesselsandvessels_exclusive, including counting vessels heard via duplicate receptions. - Update docs and tests to reflect the new
/v1/statsresponse shape and clarify AISHub licensing notes.
Reviewed changes
Copilot reviewed 11 out of 12 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
| server/stats.go | Implements rolling usage counters, persistence to *-usage.json, request counting, and new /v1/stats JSON shape. |
| server/stats_test.go | Updates /v1/stats contract tests and adds a persistence survival test. |
| server/stations.go | Ensures duplicate receptions still update per-station vessel sets; adds per-source vessel aggregation. |
| server/pipeline.go | Wires rolling counters into emit/touch/subscribe and updates duplicate handling to pass MMSI. |
| server/main.go | Loads/saves the new usage counters on boot/tick/shutdown and wraps the mux to count API requests. |
| server/aishub.go | Updates documentation wording around AISHub terms. |
| research/open-feeds.md | Updates AISHub entry details/notes. |
| README.md | Updates source licensing table for AISHub and formatting. |
| PLAN.md | Updates AISHub licensing rationale and roadmap checklist formatting. |
| docs/API.md | Updates /v1/stats documentation and example payload shape. |
| .gitignore | Changes ignored patterns (notably removes *.local.md, adds spec). |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
List sources from the station vessel sets as well as the event rings, so a source that only ever duplicates others still reports its vessels; prune source rings silent for the whole 7-day window so UDP station churn cannot grow the map or the usage file; persist plain ring state so no mutex is copied; log a usage-file error that is not simply a missing file.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
/v1/statsnow answers the marketing-page questions directly: how many vessels each source is hearing, how many of those nobody else hears, and how much the service is being used, without any number that resets on deploy.Each entry in
sourcesgainsvessels(distinct MMSIs its stations heard in the last 30 minutes) andvessels_exclusive(heard by no other source in that window). Duplicates now record the vessel for the station that heard it second, so a source's count no longer depends on who delivered the message first; without that, aisstream's copies of Kystverket messages would vanish from its count and flatter the comparison.clientsbecomes an object: open streams, streams opened on the three WebSocket endpoints, and HTTP API requests (everything except streams,/healthand/metrics). Those, plus events, duplicates and per-source events, are reported aslast_24handlast_7dfrom hourly rings that persist in<snapshot>-usage.jsonbeside the vessel snapshot, saved every 10 s and on shutdown and restored on boot.uptime_sand the since-start totals are gone from this endpoint;/metricskeeps its resetting counters as Prometheus expects.docs/API.mdandserver/README.mddescribe the new shape. After the first deploy the windows fill over seven days, solast_7dreads low for the first week.