metrics

package
v0.3.6 Latest Latest
Warning

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

Go to latest
Published: Aug 15, 2025 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func InitFromEnv

func InitFromEnv()

InitFromEnv enables Prometheus exporter if METRICS_PROMETHEUS=true. It also starts a small HTTP server on the port configured by METRICS_PORT (default 9090) and listens on ":<port>" with endpoints: /metrics (prom) and /healthz (200 ok).

func ObserveToolResultSize

func ObserveToolResultSize(tool string, size int)

ObserveToolResultSize records a histogram of result sizes for a tool, applying basic sampling to reduce cardinality/volume. Sampling rate is controlled by METRICS_RESULT_SAMPLE_N (default 1 = every call).

func SetRecorder

func SetRecorder(r Recorder)

SetRecorder swaps the global recorder implementation.

func TimeOp

func TimeOp(op string) func(success bool)

TimeOp is a helper to time DB operations.

func TimeTool

func TimeTool(tool string) func(success bool)

TimeTool is a helper to time tool handler operations.

Types

type Recorder

type Recorder interface {
	IncDBOpTotal(op string, success bool)
	ObserveDBOpSeconds(op string, success bool, seconds float64)
	IncToolTotal(tool string, success bool)
	ObserveToolSeconds(tool string, success bool, seconds float64)
	// Optional: result size metrics (low-cardinality by tool)
	ObserveToolResultSize(tool string, size int)
	// Optional: statement-cache and pool metrics
	IncStmtCacheHit(op string)
	IncStmtCacheMiss(op string)
	ObservePoolStats(inUse, idle int)
}

Recorder defines the metrics surface used across the codebase.

func Default

func Default() Recorder

Default returns the current recorder.

Jump to

Keyboard shortcuts

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