metrics

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Oct 23, 2026 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Overview

Package metrics holds the Prometheus metrics, served on METRICS_ADDR. The names and labels are part of the 1.x API (README "Metrics").

Index

Constants

This section is empty.

Variables

View Source
var (
	Events = factory.NewCounterVec(prometheus.CounterOpts{
		Name: "tokenmeter_events_total",
		Help: "Usage events received, by result: created, duplicate or invalid.",
	}, []string{"result"})

	Requests = factory.NewCounterVec(prometheus.CounterOpts{
		Name: "tokenmeter_requests_total",
		Help: "API requests by transport (http, grpc), route or RPC, and status code.",
	}, []string{"transport", "route", "code"})

	RequestDuration = factory.NewHistogramVec(prometheus.HistogramOpts{
		Name:    "tokenmeter_request_duration_seconds",
		Help:    "API request duration by transport and route or RPC.",
		Buckets: []float64{.001, .0025, .005, .01, .025, .05, .1, .25, .5, 1, 2.5, 5, 10},
	}, []string{"transport", "route"})

	StorageErrors = factory.NewCounterVec(prometheus.CounterOpts{
		Name: "tokenmeter_storage_errors_total",
		Help: "Failed storage operations by store (postgres, clickhouse) and operation.",
	}, []string{"store", "op"})

	ReadFallbacks = factory.NewCounter(prometheus.CounterOpts{
		Name: "tokenmeter_read_fallbacks_total",
		Help: "Reports answered from Postgres because a ClickHouse query failed.",
	})

	ClickHouseEnabled = factory.NewGauge(prometheus.GaugeOpts{
		Name: "tokenmeter_clickhouse_enabled",
		Help: "1 when CLICKHOUSE_ENABLED is set.",
	})

	ClickHouseUp = factory.NewGauge(prometheus.GaugeOpts{
		Name: "tokenmeter_clickhouse_serving",
		Help: "1 while reports are served from ClickHouse, 0 while from Postgres (not connected, backfilling, or its last query failed).",
	})

	Copied = factory.NewCounter(prometheus.CounterOpts{
		Name: "tokenmeter_clickhouse_copied_events_total",
		Help: "Events copied from the outbox to ClickHouse.",
	})

	InsertFailures = factory.NewCounterVec(prometheus.CounterOpts{
		Name: "tokenmeter_clickhouse_insert_failures_total",
		Help: "Failed ClickHouse inserts, by reason: unreachable (retried) or refused (postponed).",
	}, []string{"reason"})

	OutboxEvents = factory.NewGauge(prometheus.GaugeOpts{
		Name: "tokenmeter_clickhouse_outbox_events",
		Help: "Events waiting in the outbox for ClickHouse, counted up to 1000000.",
	})

	OutboxOldest = factory.NewGauge(prometheus.GaugeOpts{
		Name: "tokenmeter_clickhouse_outbox_oldest_seconds",
		Help: "Age of the oldest event waiting for ClickHouse; 0 when none waits.",
	})

	BuildInfo = factory.NewGaugeVec(prometheus.GaugeOpts{
		Name: "tokenmeter_build_info",
		Help: "Always 1; the version label names the running release.",
	}, []string{"version"})
)

Registry holds only tokenmeter's metrics plus the Go and process ones.

Functions

func Serve

func Serve(ctx context.Context, addr string) error

Serve exposes /metrics and /healthz on addr until ctx ends; "" disables it.

func WatchOutbox

func WatchOutbox(ctx context.Context, backlog Backlog, interval time.Duration)

WatchOutbox samples the outbox every interval: a query per scrape could pile up on a large outbox.

Types

type Backlog

type Backlog func(ctx context.Context) (int64, time.Duration, error)

Backlog reports the outbox size and the age of its oldest event.

Jump to

Keyboard shortcuts

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