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, and update_failed or module_failed after a run of the installer or a module job that failed. 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 ¶
const (
// StateFile holds the choice, the id and the last heartbeat (root, 0600).
StateFile = "/var/lib/casaos/telemetry.json"
)
Variables ¶
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 Modules ¶ added in v0.4.151
type Modules struct {
Known map[string]bool // every module a catalogue lists (shipped or online); nil when no catalogue could be read
Installed map[string]string // installed modules a catalogue lists: name -> version
Catalogue string // the online catalogue's serial, or the word for why none was read
}
Modules is what the statistics read of the module list.
type Preview ¶
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)
// ListModules gives the module list; main sets it, and nil leaves the modules out.
ListModules func() (Modules, error)
// contains filtered or unexported fields
}
Telemetry is the statistics of one box.
func New ¶
New reads the box under root and sends to PostHog, or to CASAOS_TELEMETRY_ENDPOINT when the install check sets it.
func (*Telemetry) ApplyOffMarker ¶
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 ¶
Check is one hourly pass:
- statistics off: delete upgraded-from and the failure markers, build nothing, send nothing;
- 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);
- a failure marker there (update-failed, then module-failed/<name>): send it, delete it once sent (statistics off, step 1 deletes them unsent);
- 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 ¶
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.