Documentation
¶
Overview ¶
Package metrics provides the process-local metrics registry used by Kivgraph.
The registry deliberately has no exporter dependency. Query counters use atomics for accumulation after a shared lookup; lifecycle and storage observations update a small locked state. An optional OpenTelemetry bridge forwards the same observations without changing the base registry contract.
Index ¶
- Constants
- type IndexMetrics
- type IndexObservation
- type LadybugMetrics
- type LadybugObservation
- type OpenTelemetry
- type OpenTelemetryOptions
- type QueryMetrics
- type QueryObservation
- type Registry
- func (r *Registry) ObserveIndex(observation IndexObservation)
- func (r *Registry) ObserveLadybug(observation LadybugObservation)
- func (r *Registry) ObserveQuery(observation QueryObservation)
- func (r *Registry) ObserveSnapshot(observation SnapshotObservation)
- func (r *Registry) ObserveWorker(observation WorkerObservation)
- func (r *Registry) RecordWorkerRestart()
- func (r *Registry) Report() Report
- func (r *Registry) ReportAt(now time.Time) Report
- type Report
- type SnapshotMetrics
- type SnapshotObservation
- type WorkerMetrics
- type WorkerObservation
Constants ¶
const ( QueryDuration = "kivgraph_query_duration" QueryTotal = "kivgraph_query_total" QueryErrors = "kivgraph_query_errors" QueryResults = "kivgraph_query_results" QueryTruncated = "kivgraph_query_truncated" QueryUnresolvedRelated = "kivgraph_query_unresolved_related" SnapshotID = "kivgraph_snapshot_id" SnapshotAge = "kivgraph_snapshot_age" SnapshotBuildDuration = "kivgraph_snapshot_build_duration" SnapshotBytes = "kivgraph_snapshot_bytes" IndexDuration = "kivgraph_index_duration" IndexFiles = "kivgraph_index_files" IndexSymbols = "kivgraph_index_symbols" IndexEdges = "kivgraph_index_edges" IndexUnresolved = "kivgraph_index_unresolved" LadybugTransaction = "kivgraph_ladybug_transaction_duration" LadybugDatabaseBytes = "kivgraph_ladybug_database_bytes" TSWorkerRestarts = "kivgraph_ts_worker_restarts" TSWorkerMemory = "kivgraph_ts_worker_memory" )
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type IndexMetrics ¶
type IndexMetrics struct {
Duration time.Duration `json:"duration"`
Files uint64 `json:"files"`
Symbols uint64 `json:"symbols"`
Edges uint64 `json:"edges"`
Unresolved uint64 `json:"unresolved"`
}
IndexMetrics is the latest index operation gauge set.
type IndexObservation ¶
type IndexObservation struct {
Duration time.Duration
Files uint64
Symbols uint64
Edges uint64
Unresolved uint64
}
IndexObservation records the latest completed indexing operation.
type LadybugMetrics ¶
type LadybugMetrics struct {
Transactions uint64 `json:"transactions"`
TransactionTotal time.Duration `json:"transaction_total"`
TransactionMax time.Duration `json:"transaction_max"`
DatabaseBytes int64 `json:"database_bytes"`
}
LadybugMetrics is the cumulative transaction view and latest size gauge.
type LadybugObservation ¶
LadybugObservation records one LadybugDB transaction and the latest database size observed by the caller.
type OpenTelemetry ¶
type OpenTelemetry struct {
// contains filtered or unexported fields
}
OpenTelemetry forwards registry observations to OpenTelemetry instruments. It contains no exporter or background goroutine; the caller controls the lifetime of the supplied MeterProvider.
func NewOpenTelemetry ¶
func NewOpenTelemetry(options OpenTelemetryOptions) (*OpenTelemetry, error)
NewOpenTelemetry creates the instruments used by the metrics bridge. A nil MeterProvider deliberately uses a no-op implementation, so exporters remain disabled unless the caller supplies a provider configured for export.
type OpenTelemetryOptions ¶
type OpenTelemetryOptions struct {
MeterProvider metric.MeterProvider
MeterName string
}
OpenTelemetryOptions configures the optional OpenTelemetry metrics bridge.
MeterProvider is owned by the caller. Kivgraph never creates an exporter or a collector. A nil provider selects the OpenTelemetry no-op provider.
type QueryMetrics ¶
type QueryMetrics struct {
Calls uint64 `json:"calls"`
Errors uint64 `json:"errors"`
Results uint64 `json:"results"`
Truncated uint64 `json:"truncated"`
UnresolvedRelated uint64 `json:"unresolved_related"`
LatencyCount uint64 `json:"latency_count"`
LatencyTotal time.Duration `json:"latency_total"`
LatencyMax time.Duration `json:"latency_max"`
}
QueryMetrics is the cumulative view for one tool. Latency is retained as count, sum, and maximum rather than an unbounded sample list.
type QueryObservation ¶
type QueryObservation struct {
ToolName string
Elapsed time.Duration
Returned int
Truncated bool
UnresolvedRelated int
SnapshotID *uint64
SnapshotAgeMS *int64
Err error
}
QueryObservation is the completed result of one MCP query handler.
type Registry ¶
type Registry struct {
// contains filtered or unexported fields
}
Registry is a process-local metrics collector. It is safe for concurrent observations and reports. Query observations are lock-free after a tool name has been seen once.
func NewRegistryWithOpenTelemetry ¶
func NewRegistryWithOpenTelemetry(options OpenTelemetryOptions) (*Registry, error)
NewRegistryWithOpenTelemetry creates a registry with an optional OpenTelemetry metrics bridge. The regular NewRegistry constructor remains exporter-free and does not incur bridge instrumentation overhead.
func (*Registry) ObserveIndex ¶
func (r *Registry) ObserveIndex(observation IndexObservation)
ObserveIndex replaces the latest index gauges.
func (*Registry) ObserveLadybug ¶
func (r *Registry) ObserveLadybug(observation LadybugObservation)
ObserveLadybug records one LadybugDB transaction and replaces the database size gauge with the latest non-negative observation.
func (*Registry) ObserveQuery ¶
func (r *Registry) ObserveQuery(observation QueryObservation)
ObserveQuery records one completed query. Negative values are clamped so a malformed caller cannot make counters wrap through unsigned arithmetic.
func (*Registry) ObserveSnapshot ¶
func (r *Registry) ObserveSnapshot(observation SnapshotObservation)
ObserveSnapshot replaces the current snapshot gauges.
func (*Registry) ObserveWorker ¶
func (r *Registry) ObserveWorker(observation WorkerObservation)
ObserveWorker replaces the current TypeScript worker gauges.
func (*Registry) RecordWorkerRestart ¶
func (r *Registry) RecordWorkerRestart()
RecordWorkerRestart increments the TypeScript worker restart counter without changing the last memory gauge.
type Report ¶
type Report struct {
Queries map[string]QueryMetrics `json:"queries"`
Snapshot *SnapshotMetrics `json:"snapshot,omitempty"`
Index *IndexMetrics `json:"index,omitempty"`
Worker *WorkerMetrics `json:"worker,omitempty"`
Ladybug *LadybugMetrics `json:"ladybug,omitempty"`
}
Report is a consistent copy of all metrics available from the registry. Report is what one process measured. A section is absent when this process never observed it: `kivgraph serve` records queries and the snapshot it loaded, and never indexes anything, so reporting an index that took zero seconds over zero files would describe work that happened somewhere else -- and read exactly like a graph that is empty.
type SnapshotMetrics ¶
type SnapshotMetrics struct {
ID uint64 `json:"id"`
CreatedAt time.Time `json:"created_at"`
Age time.Duration `json:"age"`
BuildDuration time.Duration `json:"build_duration"`
Bytes int64 `json:"bytes"`
}
SnapshotMetrics is the current snapshot gauge set.
type SnapshotObservation ¶
type SnapshotObservation struct {
ID uint64
CreatedAt time.Time
BuildDuration time.Duration
Bytes int64
}
SnapshotObservation records the immutable snapshot currently available to readers. CreatedAt is retained so Report can derive a live age.
type WorkerMetrics ¶
type WorkerMetrics struct {
Restarts uint64 `json:"restarts"`
MemoryBytes int64 `json:"memory_bytes"`
}
WorkerMetrics is the current TypeScript worker gauge set.
type WorkerObservation ¶
WorkerObservation records the current TypeScript worker state.