package store import ( "context" "errors" rvboxv1 "github.com/rvbox/rvbox/gen/go/rvbox/v1" ) // Telemetry is the bounded operational state that the server publishes as // gauges. It deliberately contains no client or command identifier. type Telemetry struct { QueuedCommands uint64 ChargedBytes uint64 } func (store *Store) Telemetry(ctx context.Context) (Telemetry, error) { if store == nil { return Telemetry{}, errors.New("server store is unavailable") } store.mu.Lock() defer store.mu.Unlock() if store.db == nil { return Telemetry{}, ErrStoreClosed } var result Telemetry if err := store.db.QueryRowContext(ctx, `SELECT count(*) FROM commands WHERE lifecycle = ?`, uint32(rvboxv1.CommandLifecycle_COMMAND_QUEUED)).Scan(&result.QueuedCommands); err != nil { return Telemetry{}, err } if err := store.db.QueryRowContext(ctx, `SELECT command_charged_bytes FROM storage_counters WHERE singleton = 1`).Scan(&result.ChargedBytes); err != nil { return Telemetry{}, err } return result, nil }