metrics

package
v1.15.0 Latest Latest
Warning

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

Go to latest
Published: Oct 28, 2026 License: Apache-2.0 Imports: 13 Imported by: 1 module, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package metrics is a self-contained Prometheus exporter for the CLI and its embedded MCP server.

The public GitHub mirror forbids imports of internal monorepo packages (`just cli-check-isolation`), so this package copies the push pattern of the internal sdk/go_metrics instead of importing it: counters, gauges, and histograms are held in process, rendered as Prometheus text exposition, and POSTed to VICTORIA_METRICS_PUSH_URL on a fixed interval. Without that env var the push loop never starts and metrics stay pull-only via Handler.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Handler

func Handler() http.Handler

Handler serves the current registry as Prometheus text exposition. It is meant for an internal scrape port, not the public MCP endpoint.

func Start

func Start(ctx context.Context)

Start starts the push loop when VICTORIA_METRICS_PUSH_URL is set. Without the env var it is a no-op, so an unconfigured local `mcp serve` never sends anything. A final flush fires when ctx ends, matching sdk/go_metrics.

func WriteText

func WriteText(w *bytes.Buffer)

WriteText renders every registered family as Prometheus text exposition, including the shared process labels other Go services attach (k8s_cluster_name, container, pod).

Types

type Counter

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

Counter is a monotonically increasing metric split by label values.

func NewCounter

func NewCounter(name string, labelNames ...string) *Counter

NewCounter registers a counter family. labelNames must match the length of every labelValues argument passed to Inc/Add; mismatched calls are dropped.

func (*Counter) Add

func (c *Counter) Add(delta float64, labelValues ...string)

Add adds delta to the series identified by labelValues.

func (*Counter) Inc

func (c *Counter) Inc(labelValues ...string)

Inc adds one to the series identified by labelValues.

func (*Counter) Name

func (c *Counter) Name() string

Name returns the metric name, used to order families in the payload.

type Gauge

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

Gauge is a metric that can go up and down, split by label values.

func NewGauge

func NewGauge(name string, labelNames ...string) *Gauge

NewGauge registers a gauge family. labelNames must match the length of every labelValues argument passed to Set/Inc/Dec; mismatched calls are dropped.

func (*Gauge) Add

func (g *Gauge) Add(delta float64, labelValues ...string)

Add adds delta to the series identified by labelValues.

func (*Gauge) Dec

func (g *Gauge) Dec(labelValues ...string)

Dec subtracts one from the series identified by labelValues.

func (*Gauge) Get

func (g *Gauge) Get(labelValues ...string) (float64, bool)

Get returns the current value of the series identified by labelValues.

func (*Gauge) Inc

func (g *Gauge) Inc(labelValues ...string)

Inc adds one to the series identified by labelValues.

func (*Gauge) Name

func (g *Gauge) Name() string

Name returns the metric name, used to order families in the payload.

func (*Gauge) Set

func (g *Gauge) Set(value float64, labelValues ...string)

Set replaces the value of the series identified by labelValues.

type GaugeFunc

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

GaugeFunc computes its value at every render instead of storing one. Use it for counts derived from other state, where a stored value would go stale when traffic stops.

func NewGaugeFunc

func NewGaugeFunc(name string, fn func() float64) *GaugeFunc

NewGaugeFunc registers a computed gauge family. fn runs on every render (push tick or scrape) and must be cheap and lock-safe.

func (*GaugeFunc) Name

func (g *GaugeFunc) Name() string

Name returns the metric name, used to order families in the payload.

type Histogram

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

Histogram is a cumulative distribution split by label values. Buckets are fixed upper bounds; the implicit +Inf bucket tracks every observation.

func NewHistogram

func NewHistogram(name string, buckets []float64, labelNames ...string) *Histogram

NewHistogram registers a histogram family. A nil buckets argument uses defaultBuckets. labelNames must match the length of every labelValues argument passed to Observe; mismatched calls are dropped.

func (*Histogram) Name

func (h *Histogram) Name() string

Name returns the metric name, used to order families in the payload.

func (*Histogram) Observe

func (h *Histogram) Observe(value float64, labelValues ...string)

Observe records one value in the series identified by labelValues.

Jump to

Keyboard shortcuts

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