Documentation
¶
Index ¶
- func Collector(opts CollectorOpts) func(next http.Handler) http.Handler
- func Handler() http.Handler
- func Transport(opts TransportOpts) func(http.RoundTripper) http.RoundTripper
- type CollectorOpts
- type CounterMetric
- type CounterMetricLabeled
- type GaugeMetric
- type GaugeMetricLabeled
- type HistogramMetric
- type HistogramMetricLabeled
- type TransportOpts
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Collector ¶
func Collector(opts CollectorOpts) func(next http.Handler) http.Handler
Collector returns HTTP middleware for tracking Prometheus metrics for incoming HTTP requests.
func Handler ¶
Handler returns an HTTP handler that serves OpenMetrics (Prometheus metrics) from the default Prometheus registry in the standard exposition format.
This handler should typically be mounted at the "/metrics" path and protected from public access, e.g. via github.com/go-chi/chi/middleware.BasicAuth middleware.
func Transport ¶
func Transport(opts TransportOpts) func(http.RoundTripper) http.RoundTripper
Transport returns a new http.RoundTripper to be used in http.Client to track metrics for outgoing HTTP requests. It records request duration and counts for each unique combination of HTTP method, path and status code. The metrics are tagged with the endpoint (method + path) and status code for detailed monitoring.
Types ¶
type CollectorOpts ¶
type CollectorOpts struct {
// Host enables tracking of request "host" label.
Host bool
// Proto enables tracking of request "proto" label, e.g. "HTTP/2", "HTTP/1.1 WebSocket".
Proto bool
// Skip is an optional predicate function that determines whether to skip recording metrics for a given request.
// If nil, all requests are recorded. If provided, requests where Skip returns true will not be recorded.
Skip func(r *http.Request) bool
}
type CounterMetric ¶
type CounterMetric struct {
// contains filtered or unexported fields
}
func Counter ¶
func Counter(name string, help string) CounterMetric
Counter creates a counter metric
func (*CounterMetric) Add ¶
func (c *CounterMetric) Add(value float64)
func (*CounterMetric) Inc ¶
func (c *CounterMetric) Inc()
type CounterMetricLabeled ¶
type CounterMetricLabeled[T any] struct { // contains filtered or unexported fields }
func CounterWith ¶
func CounterWith[T any](name string, help string) CounterMetricLabeled[T]
CounterWith creates a counter metric with typed labels
func (*CounterMetricLabeled[T]) Add ¶
func (c *CounterMetricLabeled[T]) Add(value float64, labels T)
func (*CounterMetricLabeled[T]) Inc ¶
func (c *CounterMetricLabeled[T]) Inc(labels T)
type GaugeMetric ¶
type GaugeMetric struct {
// contains filtered or unexported fields
}
func (*GaugeMetric) Add ¶
func (g *GaugeMetric) Add(value float64)
func (*GaugeMetric) Dec ¶
func (g *GaugeMetric) Dec()
func (*GaugeMetric) Inc ¶
func (g *GaugeMetric) Inc()
func (*GaugeMetric) Set ¶
func (g *GaugeMetric) Set(value float64)
type GaugeMetricLabeled ¶
type GaugeMetricLabeled[T any] struct { // contains filtered or unexported fields }
func GaugeWith ¶
func GaugeWith[T any](name, help string) GaugeMetricLabeled[T]
GaugeWith creates a gauge metric with typed labels
func (*GaugeMetricLabeled[T]) Add ¶
func (g *GaugeMetricLabeled[T]) Add(value float64, labels T)
func (*GaugeMetricLabeled[T]) Dec ¶
func (g *GaugeMetricLabeled[T]) Dec(labels T)
func (*GaugeMetricLabeled[T]) Inc ¶
func (g *GaugeMetricLabeled[T]) Inc(labels T)
func (*GaugeMetricLabeled[T]) Set ¶
func (g *GaugeMetricLabeled[T]) Set(value float64, labels T)
type HistogramMetric ¶
type HistogramMetric struct {
// contains filtered or unexported fields
}
func Histogram ¶
func Histogram(name, help string, buckets []float64) HistogramMetric
Histogram creates a histogram metric
func (*HistogramMetric) Observe ¶
func (h *HistogramMetric) Observe(value float64)
type HistogramMetricLabeled ¶
type HistogramMetricLabeled[T any] struct { // contains filtered or unexported fields }
HistogramMetric represents a histogram metric with typed labels
func HistogramWith ¶
func HistogramWith[T any](name, help string, buckets []float64) HistogramMetricLabeled[T]
HistogramWith creates a histogram metric with typed labels
func (*HistogramMetricLabeled[T]) Observe ¶
func (h *HistogramMetricLabeled[T]) Observe(value float64, labels T)
type TransportOpts ¶
type TransportOpts struct {
// Host adds the request host as a "host" label to metrics.
// WARNING: High cardinality risk - only enable for limited, known hosts.
// Do not enable for user-input URLs, crawlers, or dynamically generated hosts.
Host bool
}