Skip to content

Show vessels per source and rolling usage counts in /v1/stats - #16

Merged
bkeepers merged 6 commits into
mainfrom
station-counts
Aug 23, 2026
Merged

Show vessels per source and rolling usage counts in /v1/stats#16
bkeepers merged 6 commits into
mainfrom
station-counts

Conversation

@bkeepers

@bkeepers bkeepers commented Aug 23, 2026

Copy link
Copy Markdown
Member

/v1/stats now 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 sources 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 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.

clients becomes an object: open streams, streams opened on the three WebSocket endpoints, and HTTP API requests (everything except streams, /health and /metrics). Those, plus events, duplicates and per-source events, are reported as last_24h and last_7d from hourly rings that persist in <snapshot>-usage.json beside the vessel snapshot, saved every 10 s and on shutdown and restored on boot. uptime_s and the since-start totals are gone from this endpoint; /metrics keeps its resetting counters as Prometheus expects.

docs/API.md and server/README.md describe the new shape. After the first deploy the windows fill over seven days, so last_7d reads low for the first week.

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.
Copilot AI lite review requested due to automatic review settings August 23, 2026 12:40

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 vessels and vessels_exclusive, including counting vessels heard via duplicate receptions.
  • Update docs and tests to reflect the new /v1/stats response 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.

Comment thread server/stats.go Outdated
Comment thread server/main.go
Comment thread server/stats.go
Comment thread server/stats.go
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.
@bkeepers
bkeepers merged commit 947cf36 into main Aug 23, 2026
3 checks passed
@bkeepers
bkeepers deleted the station-counts branch August 23, 2026 13:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants