telemetry

package
v0.4.113 Latest Latest
Warning

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

Go to latest
Published: Nov 11, 2026 License: Apache-2.0 Imports: 26 Imported by: ? 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 telemetry sends ReCasaOS's anonymous usage statistics to PostHog's EU cloud: a heartbeat at most every three hours, which counts the boxes, and a version_changed event once per install or upgrade, which measures how fast they update. What is sent, what never is, and the three ways to turn it off: https://github.com/ReCasaOS/CasaOS-Install#anonymous-statistics

Two environment variables are for the install check only, never for a box: CASAOS_TELEMETRY_ENDPOINT replaces the capture URL, and CASAOS_TELEMETRY_START_DELAY (a Go duration, e.g. 0s) the random start delay.

Index

Constants

View Source
const (

	// StateFile holds the choice, the id and the last heartbeat (root, 0600).
	StateFile = "/var/lib/casaos/telemetry.json"
)

Variables

View Source
var Default = New("/")

Default is the box's own: the API answers from it and main runs its checks.

Functions

This section is empty.

Types

type Preview

type Preview struct {
	Event      string         `json:"event"`
	Properties map[string]any `json:"properties"`
}

Preview is the heartbeat as it would be sent now. It is built even when the statistics are off: it is local and sends nothing.

type State

type State struct {
	Enabled    bool      `json:"enabled"`
	ID         string    `json:"id"`
	LastSent   time.Time `json:"last_sent,omitzero"`
	NoticeSeen bool      `json:"notice_seen"`
}

State is telemetry.json.

type Status

type Status struct {
	Enabled    bool    `json:"enabled"`
	NoticeSeen bool    `json:"notice_seen"`
	Preview    Preview `json:"preview"`
}

Status is what GET and PUT /v1/sys/telemetry answer in data.

type Telemetry

type Telemetry struct {
	// Root is the filesystem everything is read from and written to: "/" on a
	// box, a fixture directory in tests.
	Root string
	// Endpoint is PostHog's capture URL.
	Endpoint string
	Now      func() time.Time
	// Command runs a program and returns its standard output: systemd-detect-virt.
	Command func(name string, args ...string) ([]byte, error)
	// contains filtered or unexported fields
}

Telemetry is the statistics of one box.

func New

func New(root string) *Telemetry

New reads the box under root and sends to PostHog, or to CASAOS_TELEMETRY_ENDPOINT when the install check sets it.

func (*Telemetry) ApplyOffMarker

func (t *Telemetry) ApplyOffMarker() error

ApplyOffMarker folds the installer's telemetry-off marker into telemetry.json: statistics off, the id kept, the marker deleted. main runs it at startup, before the API serves and before the first check.

func (*Telemetry) Check

func (t *Telemetry) Check(ctx context.Context)

Check is one hourly pass:

  1. statistics off: delete upgraded-from, build nothing, send nothing;
  2. upgraded-from present: send version_changed, delete the file only once sent (a value equal to the running release, a repair re-run or an upgrade that failed before the copy, is deleted unsent: nothing changed);
  3. last_sent absent or heartbeatEvery old: send heartbeat, record last_sent only once sent.

A failure is logged and waits for the next check: nothing is retried sooner or queued.

func (*Telemetry) Properties

func (t *Telemetry) Properties() map[string]any

Properties is what every event carries. The sender and the preview the dashboard shows both build it here: what the owner sees is what is sent.

func (*Telemetry) Run

func (t *Telemetry) Run(ctx context.Context)

Run checks once after a random delay of up to an hour, which spreads the boxes an update restarted together, then every hour until ctx is done.

func (*Telemetry) Status

func (t *Telemetry) Status() Status

func (*Telemetry) Update

func (t *Telemetry) Update(enabled, noticeSeen *bool) (Status, error)

Update sets whichever of enabled and notice_seen is given, and nothing else; it rewrites a malformed telemetry.json. Turning the statistics off holds from the next check.

Jump to

Keyboard shortcuts

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