telemetry

package
v0.9.4 Latest Latest
Warning

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

Go to latest
Published: Nov 26, 2026 License: Apache-2.0 Imports: 12 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 telemetry assembles heartbeats and keeps rolling performance stats (tok/s, request counters) shared by the tunnel, local API and TUI.

Index

Constants

View Source
const SaveInterval = 30 * time.Second

SaveInterval is how often moving counters are written.

View Source
const StatsFile = "stats.json"

StatsFile is the file name inside the data dir.

Variables

This section is empty.

Functions

func SaveCounters added in v0.8.1

func SaveCounters(dataDir string, c Counters, now time.Time) error

SaveCounters writes the counters atomically.

Types

type Counters added in v0.8.1

type Counters struct {
	Tokens          int64     `json:"total_tokens"`
	Requests        int64     `json:"total_requests"`
	EarnedMicrocred int64     `json:"earned_microcredits"`
	Since           time.Time `json:"since"`
}

Counters are the lifetime totals that survive a daemon restart (persist.go). Numbers only: nothing about any request.

func LoadCounters added in v0.8.1

func LoadCounters(dataDir string) (c Counters, ok bool, err error)

LoadCounters reads the persisted lifetime counters. ok is false when there are none (first run, or a file that could not be used, which is then moved aside); err describes an unusable file and is for logging.

type HeartbeatInput

type HeartbeatInput struct {
	State      typesv1.NodeState
	QueueDepth int
	GPUTempC   float64
	OnBattery  bool
	VRAMUsedMB uint64
	RAMUsedMB  uint64
	Models     []*typesv1.ModelState
}

HeartbeatInput carries the non-stats fields the builder needs.

type Persister added in v0.8.1

type Persister struct {
	Stats   *Stats
	DataDir string
	Log     *slog.Logger
	// contains filtered or unexported fields
}

Persister keeps a Stats' lifetime counters on disk.

func (*Persister) Restore added in v0.8.1

func (p *Persister) Restore()

Restore loads the persisted counters into Stats. Never fails the caller: an unusable file is logged and counting starts from zero.

func (*Persister) Run added in v0.8.1

func (p *Persister) Run(ctx context.Context, interval time.Duration)

Run saves every interval (<= 0: SaveInterval) until ctx ends, then once more: the graceful-shutdown write.

func (*Persister) Save added in v0.8.1

func (p *Persister) Save()

Save writes the counters if they changed since the last write.

type Snapshot

type Snapshot struct {
	TokensPerSec1m  float64 `json:"tokens_per_sec_1m"`
	RequestsPerMin  float64 `json:"requests_per_min"`
	TotalRequests   int64   `json:"total_requests"`
	TotalTokens     int64   `json:"total_tokens"`
	Inflight        int     `json:"inflight"`
	EarnedMicrocred int64   `json:"earned_microcredits"`

	SessionRequests        int64     `json:"session_requests"`
	SessionTokens          int64     `json:"session_tokens"`
	SessionEarnedMicrocred int64     `json:"session_earned_microcredits"`
	LifetimeSince          time.Time `json:"lifetime_since"`
}

Snapshot is a point-in-time view for the local API / heartbeat.

Total* and EarnedMicrocred are LIFETIME figures: they continue across daemon restarts (since LifetimeSince). Session* are the same counters since this process started. The rates are rolling one-minute windows and know nothing of either.

type Stats

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

Stats aggregates node-local counters. Safe for concurrent use.

func NewStats

func NewStats() *Stats

NewStats returns a Stats using the real clock.

func NewStatsWithClock

func NewStatsWithClock(now func() time.Time) *Stats

NewStatsWithClock injects a clock (tests).

func (*Stats) BuildHeartbeat

func (s *Stats) BuildHeartbeat(in HeartbeatInput) *tunnelv1.Heartbeat

BuildHeartbeat assembles the tunnel heartbeat message (SPEC §4.1 telemetry: capacity, queue depth, temps, tok/s rolling stats).

func (*Stats) Lifetime added in v0.8.1

func (s *Stats) Lifetime() Counters

Lifetime returns the totals to persist: earlier runs plus this one.

func (*Stats) RecordRequest

func (s *Stats) RecordRequest(completionTokens int, payoutMicro int64)

RecordRequest registers a completed request and its simulated payout.

func (*Stats) RecordTokens

func (s *Stats) RecordTokens(n int)

RecordTokens registers n generated tokens at the current time.

func (*Stats) RequestFinished

func (s *Stats) RequestFinished()

func (*Stats) RequestStarted

func (s *Stats) RequestStarted()

RequestStarted / RequestFinished track in-flight depth.

func (*Stats) Restore added in v0.8.1

func (s *Stats) Restore(c Counters)

Restore sets the totals of earlier runs; lifetime figures continue from them. Call before serving.

func (*Stats) Snapshot

func (s *Stats) Snapshot() Snapshot

Jump to

Keyboard shortcuts

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