metrics

package
v0.2.6 Latest Latest
Warning

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

Go to latest
Published: Jul 25, 2026 License: AGPL-3.0 Imports: 7 Imported by: ? modules, 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 provides the lightweight Prometheus text-format metrics types and the Store that aggregates them for the registry server.

Index

Constants

This section is empty.

Variables

View Source
var DefaultDurationBuckets = []float64{
	0.0001, 0.00025, 0.0005, 0.001, 0.0025, 0.005, 0.01, 0.025, 0.05, 0.1, 0.25, 0.5, 1.0,
}

DefaultDurationBuckets are the default histogram buckets for request duration (seconds).

View Source
var SaveDurationBuckets = []float64{
	0.1, 0.25, 0.5, 1, 1.5, 2, 3, 5, 10, 30, 60,
}

SaveDurationBuckets bracket the typical flushSave wall time for a production-sized snapshot. At 220k+ nodes we see ~1.5 s steady-state and up to ~5 s under heavy concurrent load; the long buckets catch the occasional cliff so an operator can spot it.

Functions

func FormatFloat

func FormatFloat(v float64) string

FormatFloat formats a float64 for Prometheus output. Integers are printed without decimal point for cleaner output.

Types

type Counter

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

Counter is a monotonically increasing atomic counter.

func (*Counter) Get

func (c *Counter) Get() float64

func (*Counter) Inc

func (c *Counter) Inc()

type CounterVec

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

func NewCounterVec

func NewCounterVec() *CounterVec

func (*CounterVec) Snapshot

func (cv *CounterVec) Snapshot() []LabelValue

func (*CounterVec) WithLabel

func (cv *CounterVec) WithLabel(val string) *Counter

type Gauge

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

Gauge is a numeric value that can go up and down.

func (*Gauge) Get

func (g *Gauge) Get() float64

func (*Gauge) Set

func (g *Gauge) Set(v float64)

type Histogram

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

Histogram tracks the distribution of observed values in predefined buckets.

func NewHistogram

func NewHistogram(buckets []float64) *Histogram

func (*Histogram) Observe

func (h *Histogram) Observe(v float64)

func (*Histogram) Snapshot

func (h *Histogram) Snapshot() (buckets []float64, counts []uint64, sum float64, count uint64)

Snapshot returns a copy; callers must not hold h.mu (deadlock) or retain pointers into the returned slices after mutation.

type HistogramVec

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

func NewHistogramVec

func NewHistogramVec(buckets []float64) *HistogramVec

func (*HistogramVec) Snapshot

func (hv *HistogramVec) Snapshot() []LabelHistogram

func (*HistogramVec) WithLabel

func (hv *HistogramVec) WithLabel(val string) *Histogram

type LabelHistogram

type LabelHistogram struct {
	Label   string
	Buckets []float64
	Counts  []uint64
	Sum     float64
	Count   uint64
}

type LabelValue

type LabelValue struct {
	Label string
	Value float64
}

type NetworkMetricSnapshot

type NetworkMetricSnapshot struct {
	Name       string
	Members    int
	Owners     int
	Admins     int
	Enterprise bool
	PolicySet  bool
}

NetworkMetricSnapshot holds per-network metrics computed on each scrape.

type Store

type Store struct {
	// Request metrics (labeled by message type)
	RequestsTotal   *CounterVec   // pilot_requests_total{type="..."}
	RequestDuration *HistogramVec // pilot_request_duration_seconds{type="..."}
	ErrorsTotal     *CounterVec   // pilot_errors_total{type="..."}

	// Gauge metrics (updated on each scrape)
	NodesOnline   Gauge // pilot_nodes_online
	NodesTotal    Gauge // pilot_nodes_total
	TrustLinks    Gauge // pilot_trust_links
	TaskExecutors Gauge // pilot_task_executors
	UptimeSeconds Gauge // pilot_uptime_seconds

	// Lifecycle counters
	Registrations     Counter // pilot_registrations_total
	Deregistrations   Counter // pilot_deregistrations_total
	TrustReports      Counter // pilot_trust_reports_total
	TrustRevocations  Counter // pilot_trust_revocations_total
	HandshakeRequests Counter // pilot_handshake_requests_total

	// Network gauges (updated on each scrape)
	NetworksTotal      Gauge // pilot_networks_total
	NetworksEnterprise Gauge // pilot_networks_enterprise
	InvitesPending     Gauge // pilot_invites_pending

	// Enterprise counters
	AuditEventsTotal Counter     // pilot_audit_events_total
	InvitesSent      Counter     // pilot_invites_sent_total
	InvitesAccepted  Counter     // pilot_invites_accepted_total
	InvitesRejected  Counter     // pilot_invites_rejected_total
	RbacOps          *CounterVec // pilot_rbac_operations_total{op="..."}
	PolicyChanges    Counter     // pilot_policy_changes_total
	KeyRotations     Counter     // pilot_key_rotations_total

	// Provisioning counters
	ProvisionsTotal    Counter // pilot_provisions_total
	AuditExportsTotal  Counter // pilot_audit_exports_total
	AuditExportErrors  Counter // pilot_audit_export_errors_total
	IdpVerifications   Counter // pilot_idp_verifications_total
	RbacPreAssignments Counter // pilot_rbac_pre_assignments_total

	// Reliability counters (Phase 3 wiring)
	WalFull      Counter // pilot_wal_full_total
	WalErrors    Counter // pilot_wal_errors_total
	SaveFailures Counter // pilot_save_failures_total

	// Save lifecycle — one tick per flushSave call
	SaveTotal           Counter    // pilot_save_total
	SaveLastUnixSeconds Gauge      // pilot_save_last_unix_seconds — Unix s of last successful save
	SaveDuration        *Histogram // pilot_save_duration_seconds — wall time per flushSave

	// Per-action audit breakdown (label = action)
	AuditActions *CounterVec // pilot_audit_action_total{action="..."}

	// Signature verify outcomes (label = result: ok|fail)
	SignatureVerify *CounterVec // pilot_signature_verify_total{result="..."}

	// Event-bus publish total (single hot path, no labels)
	EventBusPublish Counter // pilot_event_bus_publish_total

	// Event-bus publish broken down by "source.type" so operators can see
	// what's actually flowing through the bus (membership.changed vs
	// trust.created vs audit.entry vs ...). Label is the concatenated
	// dot-namespaced event name from the publisher.
	EventBusPublishByType *CounterVec // pilot_event_bus_publish_by_type_total{event="..."}

	// Webhook delivery counters — per-outcome counter vec + last delivery
	// timestamp. Lets operators see whether the configured webhook is
	// actually firing and whether deliveries are succeeding.
	WebhookDeliveries *CounterVec // pilot_webhook_deliveries_total{result="ok|error"} (declared, populated from WebhookStatsFn at scrape time)
	WebhookLastUnix   Gauge       // pilot_webhook_last_delivery_unix_seconds

	// WebhookStatsFn surfaces the webhook store's atomic counters at
	// scrape time. ok=false (no URL configured) → the webhook block is
	// omitted entirely, same as BeaconStatsFn. Source in webhook.Stats().
	WebhookStatsFn func() (delivered, failed, dropped uint64, lastUnix int64, ok bool)

	// Rate-limit denials by kind (label = kind: ip|punch|relay|discover)
	RateLimitDenied *CounterVec // pilot_ratelimit_denied_total{kind="..."}

	// BeaconStatsFn surfaces the beacon's atomic relay counters when wired.
	// nil when no beacon is attached; the scrape omits the metrics in that
	// case so a registry without a beacon doesn't read as 0 traffic.
	BeaconStatsFn func() (forwarded, dropped, notFound uint64, ok bool)

	// RegistryInternalsFn surfaces server-internal state that's not part of
	// the request path (pubkey index size, WAL bytes, replication epoch +
	// role). The closure is invoked at scrape time so the values are always
	// fresh. nil → the metrics are omitted from the scrape output.
	RegistryInternalsFn func() (pubkeys uint64, walSize uint64, term uint64, isStandby bool, ok bool)

	NetworkMetrics []NetworkMetricSnapshot

	// Enterprise status gauges
	IdpConfigured     Gauge // pilot_idp_configured (0 or 1)
	WebhookConfigured Gauge // pilot_webhook_configured (0 or 1)
	AuditExportActive Gauge // pilot_audit_export_active (0 or 1)
	DirectorySynced   Gauge // pilot_directory_synced_networks

	// Runtime / saturation observability
	RuntimeGoroutines     Gauge // pilot_runtime_goroutines
	RuntimeConnectionsTCP Gauge // pilot_registry_tcp_connections
	HandshakeInboxSize    Gauge // pilot_handshake_inbox_size
	HandshakeRespSize     Gauge // pilot_handshake_responses_size

	// list_nodes cache observability
	ListNodesCacheHits     Gauge // pilot_list_nodes_cache_hits
	ListNodesCacheWaits    Gauge // pilot_list_nodes_cache_waits
	ListNodesCacheRebuilds Gauge // pilot_list_nodes_cache_rebuilds

	// PanicCountFn returns the total recovered-panic count since process start.
	// Injected at construction so WriteTo can surface it without importing server.
	PanicCountFn func() uint64
	// contains filtered or unexported fields
}

Store aggregates all Prometheus metrics for the registry server. It is intentionally zero-external-dependency.

func NewStore

func NewStore(panicCountFn func() uint64) *Store

NewStore creates a new Store with all vecs initialized.

func (*Store) GetNetworkMetrics

func (st *Store) GetNetworkMetrics() []NetworkMetricSnapshot

GetNetworkMetrics returns a copy of the per-network snapshot slice (thread-safe).

func (*Store) SetNetworkMetrics

func (st *Store) SetNetworkMetrics(snaps []NetworkMetricSnapshot)

SetNetworkMetrics replaces the per-network snapshot slice (thread-safe).

func (*Store) WriteTo

func (st *Store) WriteTo(w io.Writer) (int64, error)

Jump to

Keyboard shortcuts

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