metrics

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Jun 2, 2026 License: BSD-3-Clause Imports: 4 Imported by: 0

Documentation

Overview

Package metrics owns the Prometheus instrumentation for the in-guest weft-microvm-agent. The daemon registers a small surface :

  • weft_microvm_agent_build_info{version,commit,date} — boot fingerprint
  • weft_microvm_agent_apply_total{concern,result} — Apply call counter
  • weft_microvm_agent_apply_duration_seconds{concern} — Apply latency histogram
  • weft_microvm_agent_nats_connected — 0/1 gauge

Each NATS-driven subscriber (mesh / mounts / sshkeys / properties / boot) calls Recorder.RecordApply after running its ApplyFunc ; the concern label routes the observation to the right time-series. Mirrors the shape of openweft/weft-network's internal/metrics package — same Registry-not-Default policy, same Handler() wiring.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Recorder

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

Recorder bundles the metrics + the helpers subscribers call from their Apply hot path. Construct once at startup ; share by pointer.

The recorder owns its own prometheus.Registry rather than using promauto's default — keeps test isolation tight (each New() is a clean slate) and prevents process-global pollution that would surface as collisions in unit tests run in the same binary.

func New

func New(version, commit, date string) *Recorder

New builds + registers the recorder against a fresh registry. version / commit / date come from main.go's -ldflags stamps so the build_info metric is useful in a multi-VM scrape.

func (*Recorder) Handler

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

Handler returns the http.Handler serving /metrics. Caller wires it into a dedicated listener (different port from the Introspect gRPC) so the scrape surface doesn't share fate with the control plane.

func (*Recorder) RecordApply

func (r *Recorder) RecordApply(concern string, err error, dur time.Duration)

RecordApply records one Apply invocation : increments the counter (labelled ok / error from err) and observes the histogram (labelled by concern only — error vs ok latency are usually different distributions but the volume here is too low to justify the extra cardinality, and the counter already carries the success ratio).

Safe to call with a nil receiver — subscribers without metrics wiring (tests, non-prod main()s) get a no-op. Matches the pattern other Anthropic-style daemons use to keep test setup cheap.

func (*Recorder) Registry

func (r *Recorder) Registry() *prometheus.Registry

Registry exposes the underlying prometheus.Registry for tests + the rare case a caller wants to register a domain-specific metric alongside ours.

func (*Recorder) SetNATSConnected

func (r *Recorder) SetNATSConnected(connected bool)

SetNATSConnected flips the gauge. Call once from the NATS subscriber lifecycle on connect (true) ; call false on close. Nil-receiver-safe like RecordApply.

Jump to

Keyboard shortcuts

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