metrics

package
v1.3.0 Latest Latest
Warning

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

Go to latest
Published: Jul 16, 2026 License: MIT Imports: 8 Imported by: 0

Documentation

Overview

Package metrics provides a lightweight, Prometheus-compatible metrics collector for Nimbus applications. It supports counters, gauges, and histograms without requiring an external Prometheus client library.

Index

Constants

This section is empty.

Variables

View Source
var DefaultBuckets = []float64{0.005, 0.01, 0.025, 0.05, 0.1, 0.25, 0.5, 1, 2.5, 5, 10}

DefaultBuckets are latency buckets suitable for HTTP request durations in seconds.

View Source
var DefaultRegistry = &Registry{}

DefaultRegistry is the global registry.

Functions

func Handler

func Handler() http.Handler

Handler returns an http.Handler that serves the /metrics endpoint in Prometheus text exposition format.

func RegistryHandler

func RegistryHandler(r *Registry) http.Handler

RegistryHandler returns an http.Handler for a specific registry.

Types

type Counter

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

Counter is a monotonically increasing metric (e.g. total_requests).

func NewCounter

func NewCounter(name, help string) *Counter

NewCounter creates a named counter.

func (*Counter) Add

func (c *Counter) Add(delta uint64, l Labels)

Add increments the counter by delta for the given label set.

func (*Counter) Inc

func (c *Counter) Inc(l Labels)

Inc increments the counter by 1 for the given label set.

type Gauge

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

Gauge is a metric that can go up and down (e.g. active_connections).

func NewGauge

func NewGauge(name, help string) *Gauge

NewGauge creates a named gauge.

func (*Gauge) Add

func (g *Gauge) Add(delta int64, l Labels)

Add adds delta to the gauge.

func (*Gauge) Dec

func (g *Gauge) Dec(l Labels)

Dec decrements the gauge by 1.

func (*Gauge) Inc

func (g *Gauge) Inc(l Labels)

Inc increments the gauge by 1.

func (*Gauge) Set

func (g *Gauge) Set(val int64, l Labels)

Set sets the gauge to a value.

type Histogram

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

Histogram tracks the distribution of observed values across configurable buckets (e.g. request_duration_seconds).

func NewHistogram

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

NewHistogram creates a named histogram with the specified bucket boundaries. If buckets is nil, DefaultBuckets is used.

func (*Histogram) Observe

func (h *Histogram) Observe(val float64, l Labels)

Observe records a new value in the histogram.

type Labels

type Labels map[string]string

Labels is a set of key-value pairs attached to a metric sample.

type Registry

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

Registry holds all registered metrics.

func (*Registry) Expose

func (r *Registry) Expose() string

Expose renders all metrics in Prometheus text exposition format.

func (*Registry) Register

func (r *Registry) Register(m metric)

Register adds a metric to the registry.

type RuntimeStats

type RuntimeStats struct {
	Goroutines   int    `json:"goroutines"`
	NumGC        uint32 `json:"num_gc"`
	LastGCUnixNs uint64 `json:"last_gc_unix_ns"`

	HeapAlloc    uint64 `json:"heap_alloc"`
	HeapSys      uint64 `json:"heap_sys"`
	HeapIdle     uint64 `json:"heap_idle"`
	HeapInuse    uint64 `json:"heap_inuse"`
	HeapReleased uint64 `json:"heap_released"`
	HeapObjects  uint64 `json:"heap_objects"`

	PauseTotalNs uint64 `json:"pause_total_ns"`
	NextGC       uint64 `json:"next_gc"`
}

RuntimeStats captures a snapshot of Go runtime metrics that are commonly useful when debugging performance issues (GC, heap usage, goroutines). It is framework-agnostic and can be exposed via any HTTP handler, logged periodically, or consumed by observability plugins like Telescope.

func ReadRuntimeStats

func ReadRuntimeStats() RuntimeStats

ReadRuntimeStats reads runtime.MemStats and returns a simplified snapshot. You can expose this via an endpoint, log it periodically, or feed it into dashboards like the Telescope plugin.

Jump to

Keyboard shortcuts

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