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 ¶
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.
var DefaultRegistry = &Registry{}
DefaultRegistry is the global registry.
Functions ¶
func Handler ¶
Handler returns an http.Handler that serves the /metrics endpoint in Prometheus text exposition format.
func RegistryHandler ¶
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).
type Gauge ¶
type Gauge struct {
// contains filtered or unexported fields
}
Gauge is a metric that can go up and down (e.g. active_connections).
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 ¶
NewHistogram creates a named histogram with the specified bucket boundaries. If buckets is nil, DefaultBuckets is used.
type Registry ¶
type Registry struct {
// contains filtered or unexported fields
}
Registry holds all registered metrics.
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.