Documentation
¶
Overview ¶
Package metrics is the fleet SaaS-operations god-view (/v1/admin/metrics) — the operator's business dashboard: MRR/ARR, net-new vs churned MRR, the plan/category mix, the top customers, and the recent subscription movements. SuperAdmin only (core.Admit).
It reads the ONE shared warehouse (commerce.events) — the table the commerce analytics collector lands every subscription/invoice/usage-lifecycle event in — over the SAME client (datastore.Query) the o11y/compute lenses use, with ZERO per-org fan-out. Each panel is ONE aggregate query that folds the whole fleet (subscription state = latest-event-wins via argMax; new/churn/usage = windowed), exactly the way o11y.go composes independent per-signal reads. An unconnected warehouse — or the collector's events table not provisioned yet — degrades to an honest empty snapshot (real zeros, `[]` not null) with a not-ok source, never a fabricated number. Money is USD cents end to end; time bounds are POSITIONAL args.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type MetricsData ¶
type MetricsData struct {
SaaSMetrics
GeneratedAt string `json:"generatedAt"`
Sources []core.SourceStatus `json:"sources"`
}
MetricsData is the GET /v1/admin/metrics payload: the SaaS snapshot, flat, plus the admin read time and the upstream freshness strip every god-view carries.
type MetricsIn ¶
type MetricsIn struct {
// Window is the movement window the new/churned MRR and the recent feed are
// measured over. Anything unrecognised falls back to the board default.
Window string `json:"window"`
// Limit caps the top-customers table.
Limit string `json:"limit"`
}
MetricsIn is the GET /v1/admin/metrics query.
type MetricsOut ¶
type MetricsOut struct {
Status string `json:"status"`
Msg string `json:"msg"`
Data *MetricsData `json:"data"`
}
MetricsOut is the GET /v1/admin/metrics envelope.
type SaaSCategory ¶
type SaaSCategory struct {
Category string `json:"category"`
MRRCents money.Cents `json:"mrrCents"`
Subscriptions int `json:"subscriptions"`
}
SaaSCategory is one plan-category bucket of run-rate MRR (the plan mix).
type SaaSCustomer ¶
type SaaSCustomer struct {
Org string `json:"org"`
Plan string `json:"plan"`
Category string `json:"category"`
Status string `json:"status"`
MRRCents money.Cents `json:"mrrCents"`
UsageCents money.Cents `json:"usageCents"`
Seats int `json:"seats"`
Since string `json:"since,omitempty"`
}
SaaSCustomer is one top customer by MRR + windowed usage.
type SaaSEvent ¶
type SaaSEvent struct {
At string `json:"at"`
Org string `json:"org"`
Type string `json:"type"`
Plan string `json:"plan"`
Category string `json:"category"`
MRRDeltaCents money.Cents `json:"mrrDeltaCents"`
}
SaaSEvent is one recent subscription movement ("created" or "canceled").
type SaaSMetrics ¶
type SaaSMetrics struct {
AsOf string `json:"asOf"`
Currency string `json:"currency"`
Window string `json:"window"`
Revenue SaaSRevenue `json:"revenue"`
Subs SaaSSubs `json:"subscriptions"`
Usage SaaSUsage `json:"usage"`
Customers []SaaSCustomer `json:"customers"`
Orgs int `json:"orgs"`
Gaps []string `json:"gaps"`
}
SaaSMetrics is the whole-business SaaS-operations aggregate.
type SaaSPlan ¶
type SaaSPlan struct {
Plan string `json:"plan"`
Name string `json:"name"`
Category string `json:"category"`
Active int `json:"active"`
Trialing int `json:"trialing"`
Seats int `json:"seats"`
MRRCents money.Cents `json:"mrrCents"`
}
SaaSPlan is one plan's active/trialing counts, seats, and MRR contribution.
type SaaSRevenue ¶
type SaaSRevenue struct {
MRRCents money.Cents `json:"mrrCents"`
ARRCents money.Cents `json:"arrCents"`
ActiveSubscriptions int `json:"activeSubscriptions"`
PayingCustomers int `json:"payingCustomers"`
Trials int `json:"trials"`
NewMRRCents money.Cents `json:"newMrrCents"`
ChurnedMRRCents money.Cents `json:"churnedMrrCents"`
NetNewMRRCents money.Cents `json:"netNewMrrCents"`
ByCategory []SaaSCategory `json:"byCategory"`
}
SaaSRevenue is the recurring-revenue headline (run-rate MRR/ARR + windowed movement).
type SaaSSubs ¶
type SaaSSubs struct {
ByPlan []SaaSPlan `json:"byPlan"`
TrialsActive int `json:"trialsActive"`
New int `json:"new"`
Canceled int `json:"canceled"`
Recent []SaaSEvent `json:"recent"`
}
SaaSSubs is the subscription-operations panel (per-plan mix, trials, new/canceled, recent movements).