feat: publish durable queue and spool gauges

This commit is contained in:
2026-09-11 09:28:54 +00:00
parent ea8a4d8846
commit 0e18af02bb
7 changed files with 178 additions and 0 deletions
+34
View File
@@ -0,0 +1,34 @@
package spool
import (
"context"
"errors"
rvboxv1 "github.com/rvbox/rvbox/gen/go/rvbox/v1"
)
// Telemetry is the bounded durable-spool state exposed as client gauges. It
// contains no command body, output, UUID, or client identity.
type Telemetry struct {
QueuedCommands uint64
ChargedBytes uint64
}
func (store *Store) Telemetry(ctx context.Context) (Telemetry, error) {
if store == nil {
return Telemetry{}, errors.New("client spool is unavailable")
}
store.mu.Lock()
defer store.mu.Unlock()
if store.db == nil {
return Telemetry{}, errors.New("client spool is closed")
}
var result Telemetry
if err := store.db.QueryRowContext(ctx, `SELECT count(*) FROM commands WHERE terminal = 0 AND phase IN (?, ?)`, uint32(rvboxv1.CommandLifecycle_COMMAND_QUEUED), uint32(rvboxv1.CommandLifecycle_COMMAND_DISPATCHED)).Scan(&result.QueuedCommands); err != nil {
return Telemetry{}, err
}
if err := store.db.QueryRowContext(ctx, `SELECT client_total_charged_bytes FROM spool_counters WHERE singleton = 1`).Scan(&result.ChargedBytes); err != nil {
return Telemetry{}, err
}
return result, nil
}