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
- func SaveCounters(dataDir string, c Counters, now time.Time) error
- type Counters
- type HeartbeatInput
- type Persister
- type Snapshot
- type Stats
- func (s *Stats) BuildHeartbeat(in HeartbeatInput) *tunnelv1.Heartbeat
- func (s *Stats) Lifetime() Counters
- func (s *Stats) RecordRequest(completionTokens int, payoutMicro int64)
- func (s *Stats) RecordTokens(n int)
- func (s *Stats) RequestFinished()
- func (s *Stats) RequestStarted()
- func (s *Stats) Restore(c Counters)
- func (s *Stats) Snapshot() Snapshot
Constants ¶
const SaveInterval = 30 * time.Second
SaveInterval is how often moving counters are written.
const StatsFile = "stats.json"
StatsFile is the file name inside the data dir.
Variables ¶
This section is empty.
Functions ¶
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
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.
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 NewStatsWithClock ¶
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
Lifetime returns the totals to persist: earlier runs plus this one.
func (*Stats) RecordRequest ¶
RecordRequest registers a completed request and its simulated payout.
func (*Stats) RecordTokens ¶
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.