metrics

package
v0.5.2 Latest Latest
Warning

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

Go to latest
Published: Jul 15, 2026 License: MIT Imports: 11 Imported by: 0

Documentation

Overview

Package metrics provides Prometheus-format metrics collection and export.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Counter

type Counter struct {
	// contains filtered or unexported fields
}

Counter is a monotonically increasing metric.

func (*Counter) Add

func (c *Counter) Add(n int64, labels map[string]string)

func (*Counter) Inc

func (c *Counter) Inc(labels map[string]string)

type Gauge

type Gauge struct {
	// contains filtered or unexported fields
}

Gauge is a metric that can go up and down.

func (*Gauge) Set

func (g *Gauge) Set(v float64)

type Histogram

type Histogram struct {
	// contains filtered or unexported fields
}

Histogram tracks value distributions in configurable buckets. It keeps an unlabeled default series plus any number of labeled series (used for per-tenant / per-provider attribution).

func (*Histogram) Observe

func (h *Histogram) Observe(v float64)

Observe records a value in the unlabeled series.

func (*Histogram) ObserveWithLabels added in v0.4.0

func (h *Histogram) ObserveWithLabels(v float64, labels map[string]string)

ObserveWithLabels records a value in the series identified by labels. An empty label set falls back to the unlabeled series.

type OTLPExporter added in v0.4.0

type OTLPExporter struct {
	// contains filtered or unexported fields
}

OTLPExporter exports the registry's metrics to an OTLP/HTTP endpoint using the JSON encoding of the OpenTelemetry metrics protocol (ExportMetricsServiceRequest). When the endpoint is empty it is a no-op, so offline runs and tests never require a live collector.

func NewOTLPExporter added in v0.4.0

func NewOTLPExporter(endpoint string) *OTLPExporter

NewOTLPExporter creates a metrics exporter. endpoint should be the collector base URL (e.g. "http://localhost:4318"); the exporter POSTs to "<endpoint>/v1/metrics". An empty endpoint yields a no-op exporter.

func (*OTLPExporter) Enabled added in v0.4.0

func (e *OTLPExporter) Enabled() bool

Enabled reports whether the exporter will actually export.

func (*OTLPExporter) Export added in v0.4.0

func (e *OTLPExporter) Export(ctx context.Context, r *Registry) error

Export snapshots the registry and sends it to the configured endpoint. When disabled (empty endpoint) it returns nil without doing any I/O.

func (*OTLPExporter) WithHTTPClient added in v0.4.0

func (e *OTLPExporter) WithHTTPClient(c *http.Client) *OTLPExporter

WithHTTPClient overrides the HTTP client (useful for tests).

func (*OTLPExporter) WithHeader added in v0.4.0

func (e *OTLPExporter) WithHeader(k, v string) *OTLPExporter

WithHeader adds a header sent with each export request (e.g. auth).

type Registry

type Registry struct {
	// contains filtered or unexported fields
}

Registry holds all Chronos metrics and serves them in Prometheus format.

func NewRegistry

func NewRegistry() *Registry

NewRegistry creates a new metrics registry with pre-defined Chronos metrics.

func (*Registry) AddTokens

func (r *Registry) AddTokens(provider string, count int64)

AddTokens adds to the token usage counter.

func (*Registry) Counter

func (r *Registry) Counter(name, help string) *Counter

Counter returns or creates a counter metric.

func (*Registry) Gauge

func (r *Registry) Gauge(name, help string) *Gauge

Gauge returns or creates a gauge metric.

func (*Registry) Handler

func (r *Registry) Handler() http.Handler

Handler returns an http.Handler that serves metrics in Prometheus format.

func (*Registry) Histogram

func (r *Registry) Histogram(name, help string, buckets []float64) *Histogram

Histogram returns or creates a histogram metric.

func (*Registry) IncAgentRuns

func (r *Registry) IncAgentRuns(agentID string)

IncAgentRuns increments the agent runs counter.

func (*Registry) IncErrors added in v0.4.0

func (r *Registry) IncErrors(tenant, kind string)

IncErrors increments the error counter for a tenant and error kind.

func (*Registry) IncToolCalls

func (r *Registry) IncToolCalls(toolName string)

IncToolCalls increments the tool calls counter.

func (*Registry) ObserveModelLatency

func (r *Registry) ObserveModelLatency(provider string, d time.Duration)

ObserveModelLatency records a model call latency.

func (*Registry) RecordModelCall added in v0.4.0

func (r *Registry) RecordModelCall(tenant, provider string, d time.Duration, promptTokens, completionTokens int64, isErr bool)

RecordModelCall records a single model invocation with per-tenant attribution: model-call counter, token usage (prompt + completion), latency, and errors.

func (*Registry) RecordToolCall added in v0.4.0

func (r *Registry) RecordToolCall(tenant, tool string, d time.Duration, isErr bool)

RecordToolCall records a single tool invocation with per-tenant attribution: it increments the tool-call counter, observes latency, and increments the error counter when the call failed.

func (*Registry) SetActiveSessions

func (r *Registry) SetActiveSessions(n float64)

SetActiveSessions sets the active session count.

Jump to

Keyboard shortcuts

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