pingcollector

package
v0.311.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 30, 2026 License: MIT Imports: 14 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package pingcollector receives muster's anonymous usage ping (internal/usageping; docs/usage-ping.md) and answers aggregate questions about it. cmd/muster-ping-collector serves it.

🔴 WHAT IT KEEPS IS EXACTLY THE PAYLOAD, ONE ROW PER (install id, kind, UTC day), AND NOTHING ABOUT THE REQUEST. The table has no column for an address, a user agent or a header (TestOneRowPerInstallPerDayAndNoAddress pins its column set), the handler never reads r.RemoteAddr or a forwarding header, and nothing here logs a request. A later heartbeat the same day replaces that day's row, so an install is one row a day whatever it sends. Rows older than Retention are deleted.

Index

Constants

View Source
const MaxStatsDays = 90

MaxStatsDays is the longest window /v1/stats answers for.

View Source
const Retention = 180 * 24 * time.Hour

Retention is how long a day's rows are kept.

View Source
const Schema = `` /* 615-byte string literal not displayed */

Schema is the collector's whole database: one table, created at start (EnsureSchema). Its own database, not muster's: it shares no migration.

🔴 NO COLUMN FOR THE REQUEST: no address, user agent or header. The columns are the payload's fields, the day, and when that day's row was last written.

Variables

This section is empty.

Functions

This section is empty.

Types

type Day

type Day struct {
	Day       string                    `json:"day"`
	Servers   int                       `json:"servers"`
	Mirrors   int                       `json:"mirrors"`
	ByVersion map[string]map[string]int `json:"by_version"`
	ByDeploy  map[string]map[string]int `json:"by_deploy"`
	Hosts     map[string]int            `json:"server_hosts"`
	Agents    map[string]int            `json:"server_agents"`
}

Day is one UTC day's counts. Servers and Mirrors are the installs of each kind that sent that day (each mirror is one active host); the maps count installs by version and by deploy mode per kind ("server" / "mirror"), and the servers by their banded host and agent counts.

type PG

type PG struct {
	// contains filtered or unexported fields
}

PG is Store on Postgres.

func NewPG

func NewPG(pool *pgxpool.Pool) *PG

NewPG is Store over pool.

func (*PG) EnsureSchema

func (p *PG) EnsureSchema(ctx context.Context) error

EnsureSchema creates the table when it is missing.

func (*PG) Prune

func (p *PG) Prune(ctx context.Context, before time.Time) error

Prune implements Store.

func (*PG) Stats

func (p *PG) Stats(ctx context.Context, from, to time.Time) (Stats, error)

Stats implements Store.

func (*PG) Upsert

func (p *PG) Upsert(ctx context.Context, d time.Time, pl usageping.Payload, seen time.Time) error

Upsert implements Store.

type Server

type Server struct {
	Store Store
	// StatsToken is the bearer token /v1/stats requires; "" turns /v1/stats
	// off (404).
	StatsToken string
	// Now is the clock; nil is time.Now.
	Now func() time.Time
	// contains filtered or unexported fields
}

Server is the collector's HTTP side.

func (*Server) Handler

func (s *Server) Handler() http.Handler

Handler serves POST /v1/ping, GET /v1/stats (JSON), GET /v1/stats/page (the same numbers as an HTML table) and GET /healthz.

type Stats

type Stats struct {
	From string `json:"from"`
	To   string `json:"to"`
	// Installs is the distinct installs seen in the window, by kind.
	Installs map[string]int `json:"installs"`
	Days     []Day          `json:"days"`
}

Stats is /v1/stats's answer: aggregates only, never an install id.

type Store

type Store interface {
	// Upsert keeps p as install p.InstallID's row for kind p.Kind on day,
	// replacing that day's earlier one.
	Upsert(ctx context.Context, day time.Time, p usageping.Payload, seen time.Time) error
	// Prune deletes the rows of days before day.
	Prune(ctx context.Context, before time.Time) error
	// Stats aggregates the days from..to (UTC dates, inclusive).
	Stats(ctx context.Context, from, to time.Time) (Stats, error)
}

Store is where the heartbeats go.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL