Documentation
¶
Overview ¶
Package metrics provides a unified Prometheus metrics toolkit for Go services. It includes registry management, metric builders, HTTP handlers, and middleware.
Index ¶
- Constants
- func BytesBuckets() []float64
- func DefaultBuckets() []float64
- func DefaultPathNormalize(path string) string
- func ExternalAPIDurationBuckets() []float64
- func FiberHandler() fiber.Handler
- func FiberHandlerFor(registry *Registry) fiber.Handler
- func FiberHandlerForGatherer(gatherer prometheus.Gatherer) fiber.Handler
- func HTTPDurationBuckets() []float64
- func Handler() http.Handler
- func HandlerFor(registry *Registry) http.Handler
- func HandlerForGatherer(gatherer prometheus.Gatherer) http.Handler
- func NewFiberHandler(opts HandlerOpts) fiber.Handler
- func NewFiberMiddleware(namespace string) fiber.Handler
- func NewFiberMiddlewareWithConfig(cfg HTTPMetricsConfig) fiber.Handler
- func NewHandler(opts HandlerOpts) http.Handler
- func RedisDurationBuckets() []float64
- func RegisterHTTPHandler(mux *http.ServeMux, path string)
- func RegisterHTTPHandlerFor(mux *http.ServeMux, path string, registry *Registry)
- func SanitizeLabelValue(s string, maxLen int) string
- type AuthMetrics
- type BackgroundTaskMetrics
- func (m *BackgroundTaskMetrics) DecRunning()
- func (m *BackgroundTaskMetrics) IncRunning()
- func (m *BackgroundTaskMetrics) RecordExecution(task, result string, duration time.Duration)
- func (m *BackgroundTaskMetrics) RecordFailure(task string, duration time.Duration)
- func (m *BackgroundTaskMetrics) RecordSuccess(task string, duration time.Duration)
- type CacheMetrics
- type CommonMetrics
- func (cm *CommonMetrics) NewAuthMetrics() *AuthMetrics
- func (cm *CommonMetrics) NewBackgroundTaskMetrics() *BackgroundTaskMetrics
- func (cm *CommonMetrics) NewCacheMetrics(name string) *CacheMetrics
- func (cm *CommonMetrics) NewExternalServiceMetrics(serviceName string) *ExternalServiceMetrics
- func (cm *CommonMetrics) NewOTPMetrics() *OTPMetrics
- func (cm *CommonMetrics) NewRateLimitMetrics() *RateLimitMetrics
- func (cm *CommonMetrics) NewRedisMetrics() *RedisMetrics
- type CounterBuilder
- func (b *CounterBuilder) Build() prometheus.Counter
- func (b *CounterBuilder) BuildVec() *prometheus.CounterVec
- func (b *CounterBuilder) ConstLabels(labels prometheus.Labels) *CounterBuilder
- func (b *CounterBuilder) Help(help string) *CounterBuilder
- func (b *CounterBuilder) Labels(labels ...string) *CounterBuilder
- type ExternalServiceMetrics
- type GaugeBuilder
- type HTTPMetrics
- type HTTPMetricsConfig
- type HandlerOpts
- type HistogramBuilder
- func (b *HistogramBuilder) Buckets(buckets []float64) *HistogramBuilder
- func (b *HistogramBuilder) Build() prometheus.Histogram
- func (b *HistogramBuilder) BuildVec() *prometheus.HistogramVec
- func (b *HistogramBuilder) ConstLabels(labels prometheus.Labels) *HistogramBuilder
- func (b *HistogramBuilder) Help(help string) *HistogramBuilder
- func (b *HistogramBuilder) Labels(labels ...string) *HistogramBuilder
- type OTPMetrics
- type RateLimitMetrics
- type RedisMetrics
- func (m *RedisMetrics) RecordConnectionError()
- func (m *RedisMetrics) RecordFailure(operation string, duration time.Duration)
- func (m *RedisMetrics) RecordOperation(operation, result string, duration time.Duration)
- func (m *RedisMetrics) RecordSuccess(operation string, duration time.Duration)
- func (m *RedisMetrics) SetActiveConnections(count float64)
- type Registry
- func (r *Registry) Counter(name string) *CounterBuilder
- func (r *Registry) Gatherer() prometheus.Gatherer
- func (r *Registry) Gauge(name string) *GaugeBuilder
- func (r *Registry) Histogram(name string) *HistogramBuilder
- func (r *Registry) MustRegister(collectors ...prometheus.Collector)
- func (r *Registry) Namespace() string
- func (r *Registry) PrometheusRegistry() *prometheus.Registry
- func (r *Registry) Register(name string, collector prometheus.Collector) error
- func (r *Registry) Registerer() prometheus.Registerer
- func (r *Registry) Subsystem() string
- func (r *Registry) Summary(name string) *SummaryBuilder
- func (r *Registry) Unregister(name string) bool
- func (r *Registry) WithSubsystem(subsystem string) *Registry
- type SummaryBuilder
- func (b *SummaryBuilder) Build() prometheus.Summary
- func (b *SummaryBuilder) BuildVec() *prometheus.SummaryVec
- func (b *SummaryBuilder) ConstLabels(labels prometheus.Labels) *SummaryBuilder
- func (b *SummaryBuilder) Help(help string) *SummaryBuilder
- func (b *SummaryBuilder) Labels(labels ...string) *SummaryBuilder
- func (b *SummaryBuilder) Objectives(objectives map[float64]float64) *SummaryBuilder
Constants ¶
const DefaultLabelValueMaxLength = 256
Default max length for a single label value to avoid unbounded cardinality and exposition bloat. Prometheus does not enforce a limit; this is a reasonable default for safety.
Variables ¶
This section is empty.
Functions ¶
func BytesBuckets ¶
func BytesBuckets() []float64
BytesBuckets returns buckets suitable for request/response size tracking. Values: 100B, 1KB, 10KB, 100KB, 1MB, 10MB
func DefaultBuckets ¶
func DefaultBuckets() []float64
DefaultBuckets returns the default Prometheus histogram buckets.
func DefaultPathNormalize ¶ added in v1.1.0
DefaultPathNormalize normalizes request paths for use as metric labels to avoid cardinality explosion. It replaces numeric and UUID-like path segments with ":id", e.g. /users/123 -> /users/:id, /items/550e8400-e29b-41d4-a716-446655440000 -> /items/:id. Use this as PathTransformFunc in production so each distinct ID does not create a new time series.
func ExternalAPIDurationBuckets ¶
func ExternalAPIDurationBuckets() []float64
ExternalAPIDurationBuckets returns buckets suitable for external API call duration tracking. Values: 10ms, 50ms, 100ms, 250ms, 500ms, 1s, 2.5s, 5s, 10s, 30s
func FiberHandler ¶
FiberHandler returns a Fiber-compatible handler for the /metrics endpoint using the default Prometheus registry.
func FiberHandlerFor ¶
FiberHandlerFor returns a Fiber-compatible handler for the given registry.
func FiberHandlerForGatherer ¶
func FiberHandlerForGatherer(gatherer prometheus.Gatherer) fiber.Handler
FiberHandlerForGatherer returns a Fiber-compatible handler for the given Gatherer.
func HTTPDurationBuckets ¶
func HTTPDurationBuckets() []float64
HTTPDurationBuckets returns buckets suitable for HTTP request duration tracking. Values: 1ms, 5ms, 10ms, 25ms, 50ms, 100ms, 250ms, 500ms, 1s, 2.5s, 5s, 10s
func Handler ¶
Handler returns a standard http.Handler for the /metrics endpoint using the default Prometheus registry.
func HandlerFor ¶
HandlerFor returns an http.Handler for the given registry.
func HandlerForGatherer ¶
func HandlerForGatherer(gatherer prometheus.Gatherer) http.Handler
HandlerForGatherer returns an http.Handler for the given Gatherer.
func NewFiberHandler ¶
func NewFiberHandler(opts HandlerOpts) fiber.Handler
NewFiberHandler creates a new Fiber metrics handler with the given options.
func NewFiberMiddleware ¶
NewFiberMiddleware creates a Fiber middleware with default configuration.
func NewFiberMiddlewareWithConfig ¶
func NewFiberMiddlewareWithConfig(cfg HTTPMetricsConfig) fiber.Handler
NewFiberMiddlewareWithConfig creates a Fiber middleware with custom configuration.
func NewHandler ¶
func NewHandler(opts HandlerOpts) http.Handler
NewHandler creates a new metrics HTTP handler with the given options. When Timeout is greater than 0, the handler is wrapped with http.TimeoutHandler; timed-out requests respond with 503 Service Unavailable.
func RedisDurationBuckets ¶
func RedisDurationBuckets() []float64
RedisDurationBuckets returns buckets suitable for Redis operation duration tracking. Values: 0.5ms, 1ms, 2.5ms, 5ms, 10ms, 25ms, 50ms, 100ms, 250ms, 500ms, 1s
func RegisterHTTPHandler ¶
RegisterHTTPHandler registers the metrics handler on an http.ServeMux.
func RegisterHTTPHandlerFor ¶
RegisterHTTPHandlerFor registers a metrics handler for the given registry.
func SanitizeLabelValue ¶ added in v1.1.0
SanitizeLabelValue returns a value safe for use as a Prometheus label value. It replaces newlines and carriage returns (which would break the exposition format), escapes backslashes, and truncates to maxLen runes. Use 0 for maxLen to skip truncation. Call this for any label value that may come from untrusted input (e.g. request path, user-provided strings).
Types ¶
type AuthMetrics ¶
type AuthMetrics struct {
RequestsTotal *prometheus.CounterVec
SessionsCreated prometheus.Counter
SessionsDestroyed prometheus.Counter
}
AuthMetrics holds authentication metrics.
func (*AuthMetrics) RecordAuthRequest ¶
func (m *AuthMetrics) RecordAuthRequest(method, result string)
RecordAuthRequest records an authentication request.
func (*AuthMetrics) RecordFailure ¶
func (m *AuthMetrics) RecordFailure(method string)
RecordFailure records a failed authentication.
func (*AuthMetrics) RecordSessionCreated ¶
func (m *AuthMetrics) RecordSessionCreated()
RecordSessionCreated records a session creation.
func (*AuthMetrics) RecordSessionDestroyed ¶
func (m *AuthMetrics) RecordSessionDestroyed()
RecordSessionDestroyed records a session destruction.
func (*AuthMetrics) RecordSuccess ¶
func (m *AuthMetrics) RecordSuccess(method string)
RecordSuccess records a successful authentication.
type BackgroundTaskMetrics ¶
type BackgroundTaskMetrics struct {
ExecutionsTotal *prometheus.CounterVec
Duration *prometheus.HistogramVec
ErrorsTotal prometheus.Counter
Running prometheus.Gauge
}
BackgroundTaskMetrics holds metrics for background tasks.
func (*BackgroundTaskMetrics) DecRunning ¶
func (m *BackgroundTaskMetrics) DecRunning()
DecRunning decrements the running task count.
func (*BackgroundTaskMetrics) IncRunning ¶
func (m *BackgroundTaskMetrics) IncRunning()
IncRunning increments the running task count.
func (*BackgroundTaskMetrics) RecordExecution ¶
func (m *BackgroundTaskMetrics) RecordExecution(task, result string, duration time.Duration)
RecordExecution records a background task execution.
func (*BackgroundTaskMetrics) RecordFailure ¶
func (m *BackgroundTaskMetrics) RecordFailure(task string, duration time.Duration)
RecordFailure records a failed task execution.
func (*BackgroundTaskMetrics) RecordSuccess ¶
func (m *BackgroundTaskMetrics) RecordSuccess(task string, duration time.Duration)
RecordSuccess records a successful task execution.
type CacheMetrics ¶
type CacheMetrics struct {
Hits prometheus.Counter
Misses prometheus.Counter
Size prometheus.Gauge
Errors prometheus.Counter
}
CacheMetrics holds cache-related metrics.
func (*CacheMetrics) RecordError ¶
func (m *CacheMetrics) RecordError()
RecordError records a cache error.
func (*CacheMetrics) RecordMiss ¶
func (m *CacheMetrics) RecordMiss()
RecordMiss records a cache miss.
func (*CacheMetrics) SetSize ¶
func (m *CacheMetrics) SetSize(size float64)
SetSize sets the current cache size.
type CommonMetrics ¶
type CommonMetrics struct {
// contains filtered or unexported fields
}
CommonMetrics provides frequently used metric patterns for services.
func NewCommonMetrics ¶
func NewCommonMetrics(registry *Registry) *CommonMetrics
NewCommonMetrics creates a new CommonMetrics instance.
func (*CommonMetrics) NewAuthMetrics ¶
func (cm *CommonMetrics) NewAuthMetrics() *AuthMetrics
NewAuthMetrics creates authentication metrics.
func (*CommonMetrics) NewBackgroundTaskMetrics ¶
func (cm *CommonMetrics) NewBackgroundTaskMetrics() *BackgroundTaskMetrics
NewBackgroundTaskMetrics creates background task metrics.
func (*CommonMetrics) NewCacheMetrics ¶
func (cm *CommonMetrics) NewCacheMetrics(name string) *CacheMetrics
NewCacheMetrics creates cache metrics with the given name prefix.
func (*CommonMetrics) NewExternalServiceMetrics ¶
func (cm *CommonMetrics) NewExternalServiceMetrics(serviceName string) *ExternalServiceMetrics
NewExternalServiceMetrics creates metrics for an external service.
func (*CommonMetrics) NewOTPMetrics ¶
func (cm *CommonMetrics) NewOTPMetrics() *OTPMetrics
NewOTPMetrics creates OTP metrics.
func (*CommonMetrics) NewRateLimitMetrics ¶
func (cm *CommonMetrics) NewRateLimitMetrics() *RateLimitMetrics
NewRateLimitMetrics creates rate limit metrics.
func (*CommonMetrics) NewRedisMetrics ¶
func (cm *CommonMetrics) NewRedisMetrics() *RedisMetrics
NewRedisMetrics creates Redis operation metrics.
type CounterBuilder ¶
type CounterBuilder struct {
// contains filtered or unexported fields
}
CounterBuilder provides a fluent interface for building Counter metrics.
func (*CounterBuilder) Build ¶
func (b *CounterBuilder) Build() prometheus.Counter
Build creates and registers a Counter (without labels).
func (*CounterBuilder) BuildVec ¶
func (b *CounterBuilder) BuildVec() *prometheus.CounterVec
BuildVec creates and registers a CounterVec (with labels).
func (*CounterBuilder) ConstLabels ¶
func (b *CounterBuilder) ConstLabels(labels prometheus.Labels) *CounterBuilder
ConstLabels sets constant labels for the counter.
func (*CounterBuilder) Help ¶
func (b *CounterBuilder) Help(help string) *CounterBuilder
Help sets the help text for the counter.
func (*CounterBuilder) Labels ¶
func (b *CounterBuilder) Labels(labels ...string) *CounterBuilder
Labels sets the label names for the counter.
type ExternalServiceMetrics ¶
type ExternalServiceMetrics struct {
CallsTotal *prometheus.CounterVec
CallDuration *prometheus.HistogramVec
}
ExternalServiceMetrics holds metrics for external service calls.
func (*ExternalServiceMetrics) RecordCall ¶
func (m *ExternalServiceMetrics) RecordCall(operation, result string, duration time.Duration)
RecordCall records an external service call.
func (*ExternalServiceMetrics) RecordFailure ¶
func (m *ExternalServiceMetrics) RecordFailure(operation string, duration time.Duration)
RecordFailure records a failed external service call.
func (*ExternalServiceMetrics) RecordSuccess ¶
func (m *ExternalServiceMetrics) RecordSuccess(operation string, duration time.Duration)
RecordSuccess records a successful external service call.
type GaugeBuilder ¶
type GaugeBuilder struct {
// contains filtered or unexported fields
}
GaugeBuilder provides a fluent interface for building Gauge metrics.
func (*GaugeBuilder) Build ¶
func (b *GaugeBuilder) Build() prometheus.Gauge
Build creates and registers a Gauge (without labels).
func (*GaugeBuilder) BuildVec ¶
func (b *GaugeBuilder) BuildVec() *prometheus.GaugeVec
BuildVec creates and registers a GaugeVec (with labels).
func (*GaugeBuilder) ConstLabels ¶
func (b *GaugeBuilder) ConstLabels(labels prometheus.Labels) *GaugeBuilder
ConstLabels sets constant labels for the gauge.
func (*GaugeBuilder) Help ¶
func (b *GaugeBuilder) Help(help string) *GaugeBuilder
Help sets the help text for the gauge.
func (*GaugeBuilder) Labels ¶
func (b *GaugeBuilder) Labels(labels ...string) *GaugeBuilder
Labels sets the label names for the gauge.
type HTTPMetrics ¶
type HTTPMetrics struct {
// RequestsTotal counts total HTTP requests by method, path, and status
RequestsTotal *prometheus.CounterVec
// RequestDuration observes request latency by method and path
RequestDuration *prometheus.HistogramVec
// RequestsInFlight tracks currently processing requests
RequestsInFlight prometheus.Gauge
// RequestSize observes request body size
RequestSize *prometheus.HistogramVec
// ResponseSize observes response body size
ResponseSize *prometheus.HistogramVec
}
HTTPMetrics holds the metrics collectors for HTTP request monitoring.
func NewHTTPMetrics ¶
func NewHTTPMetrics(cfg HTTPMetricsConfig) *HTTPMetrics
NewHTTPMetrics creates a new HTTPMetrics with the given configuration.
func (*HTTPMetrics) FiberMiddleware ¶
func (m *HTTPMetrics) FiberMiddleware(cfg HTTPMetricsConfig) fiber.Handler
FiberMiddleware returns a Fiber middleware that collects HTTP metrics.
func (*HTTPMetrics) RecordRequest ¶
func (m *HTTPMetrics) RecordRequest(method, path, status string, duration time.Duration)
RecordRequest records a single HTTP request metric. This is useful for manual metric recording outside of middleware. Method, path, and status are sanitized for safe use as label values.
func (*HTTPMetrics) RecordRequestWithSize ¶
func (m *HTTPMetrics) RecordRequestWithSize(method, path, status string, duration time.Duration, reqSize, respSize int)
RecordRequestWithSize records an HTTP request with size information.
type HTTPMetricsConfig ¶
type HTTPMetricsConfig struct {
// Registry is the metrics registry to use. If nil, creates a new one.
Registry *Registry
// Namespace for metrics (e.g., "myservice")
Namespace string
// Subsystem for metrics (default: "http")
Subsystem string
// DurationBuckets for the request duration histogram
DurationBuckets []float64
// SizeBuckets for request/response size histograms
SizeBuckets []float64
// SkipPaths is a list of paths to skip metrics collection
SkipPaths []string
// PathTransformFunc transforms the request path before using it as a label.
// This is useful for normalizing paths with parameters (e.g., /users/123 -> /users/:id)
PathTransformFunc func(path string) string
// IncludeRequestSize enables request size tracking
IncludeRequestSize bool
// IncludeResponseSize enables response size tracking
IncludeResponseSize bool
// IncludeRequestsInFlight enables in-flight request tracking
IncludeRequestsInFlight bool
}
HTTPMetricsConfig configures the HTTP metrics middleware.
func DefaultHTTPMetricsConfig ¶
func DefaultHTTPMetricsConfig() HTTPMetricsConfig
DefaultHTTPMetricsConfig returns the default configuration for HTTP metrics. PathTransformFunc is set to DefaultPathNormalize to avoid label cardinality explosion in production; override to nil or a custom function if you need raw paths or different normalization.
type HandlerOpts ¶
type HandlerOpts struct {
// Registry is the custom registry to use. If nil, uses default registry.
Registry *Registry
// ErrorHandling defines how errors are handled.
// See promhttp.HandlerOpts for details.
ErrorHandling promhttp.HandlerErrorHandling
// ErrorLog is an optional logger for errors.
ErrorLog promhttp.Logger
// EnableOpenMetrics enables OpenMetrics format in addition to standard format.
EnableOpenMetrics bool
// DisableCompression disables response compression.
DisableCompression bool
// MaxRequestsInFlight limits concurrent requests. 0 means no limit.
MaxRequestsInFlight int
// Timeout specifies the maximum time for a request in seconds.
// When > 0, the handler is wrapped with http.TimeoutHandler; 0 means no timeout.
Timeout int
}
HandlerOpts provides options for configuring metrics handlers.
func DefaultHandlerOpts ¶
func DefaultHandlerOpts() HandlerOpts
DefaultHandlerOpts returns the default handler options.
type HistogramBuilder ¶
type HistogramBuilder struct {
// contains filtered or unexported fields
}
HistogramBuilder provides a fluent interface for building Histogram metrics.
func (*HistogramBuilder) Buckets ¶
func (b *HistogramBuilder) Buckets(buckets []float64) *HistogramBuilder
Buckets sets the bucket boundaries for the histogram.
func (*HistogramBuilder) Build ¶
func (b *HistogramBuilder) Build() prometheus.Histogram
Build creates and registers a Histogram (without labels).
func (*HistogramBuilder) BuildVec ¶
func (b *HistogramBuilder) BuildVec() *prometheus.HistogramVec
BuildVec creates and registers a HistogramVec (with labels).
func (*HistogramBuilder) ConstLabels ¶
func (b *HistogramBuilder) ConstLabels(labels prometheus.Labels) *HistogramBuilder
ConstLabels sets constant labels for the histogram.
func (*HistogramBuilder) Help ¶
func (b *HistogramBuilder) Help(help string) *HistogramBuilder
Help sets the help text for the histogram.
func (*HistogramBuilder) Labels ¶
func (b *HistogramBuilder) Labels(labels ...string) *HistogramBuilder
Labels sets the label names for the histogram.
type OTPMetrics ¶
type OTPMetrics struct {
ChallengesTotal *prometheus.CounterVec
SendsTotal *prometheus.CounterVec
SendDuration *prometheus.HistogramVec
VerificationsTotal *prometheus.CounterVec
}
OTPMetrics holds OTP/verification code metrics.
func (*OTPMetrics) RecordChallengeCreated ¶
func (m *OTPMetrics) RecordChallengeCreated(channel, purpose, result string)
RecordChallengeCreated records a challenge creation event.
func (*OTPMetrics) RecordSend ¶
func (m *OTPMetrics) RecordSend(channel, provider, result string, duration time.Duration)
RecordSend records an OTP send event.
func (*OTPMetrics) RecordVerification ¶
func (m *OTPMetrics) RecordVerification(result, reason string)
RecordVerification records a verification event.
type RateLimitMetrics ¶
type RateLimitMetrics struct {
Hits *prometheus.CounterVec
}
RateLimitMetrics holds rate limiting metrics.
func (*RateLimitMetrics) RecordHit ¶
func (m *RateLimitMetrics) RecordHit(scope string)
RecordHit records a rate limit hit for the given scope. Common scopes: "user", "ip", "destination", "resend_cooldown"
type RedisMetrics ¶
type RedisMetrics struct {
OperationsTotal *prometheus.CounterVec
OperationDuration *prometheus.HistogramVec
ConnectionsActive prometheus.Gauge
ConnectionErrors prometheus.Counter
}
RedisMetrics holds Redis operation metrics.
func (*RedisMetrics) RecordConnectionError ¶
func (m *RedisMetrics) RecordConnectionError()
RecordConnectionError records a connection error.
func (*RedisMetrics) RecordFailure ¶
func (m *RedisMetrics) RecordFailure(operation string, duration time.Duration)
RecordFailure records a failed Redis operation.
func (*RedisMetrics) RecordOperation ¶
func (m *RedisMetrics) RecordOperation(operation, result string, duration time.Duration)
RecordOperation records a Redis operation.
func (*RedisMetrics) RecordSuccess ¶
func (m *RedisMetrics) RecordSuccess(operation string, duration time.Duration)
RecordSuccess records a successful Redis operation.
func (*RedisMetrics) SetActiveConnections ¶
func (m *RedisMetrics) SetActiveConnections(count float64)
SetActiveConnections sets the number of active connections.
type Registry ¶
type Registry struct {
// contains filtered or unexported fields
}
Registry wraps prometheus.Registry with additional functionality for managing metrics in a service-oriented way.
func DefaultRegistry ¶
func DefaultRegistry() *Registry
DefaultRegistry returns a Registry wrapping the default Prometheus registry.
func NewRegistry ¶
NewRegistry creates a new Registry with the given namespace. The namespace is typically the service name (e.g., "herald", "stargate").
func NewRegistryWithSubsystem ¶
NewRegistryWithSubsystem creates a new Registry with namespace and subsystem.
func (*Registry) Counter ¶
func (r *Registry) Counter(name string) *CounterBuilder
Counter creates a new CounterBuilder.
func (*Registry) Gatherer ¶
func (r *Registry) Gatherer() prometheus.Gatherer
Gatherer returns the underlying prometheus.Gatherer interface.
func (*Registry) Gauge ¶
func (r *Registry) Gauge(name string) *GaugeBuilder
Gauge creates a new GaugeBuilder.
func (*Registry) Histogram ¶
func (r *Registry) Histogram(name string) *HistogramBuilder
Histogram creates a new HistogramBuilder.
func (*Registry) MustRegister ¶
func (r *Registry) MustRegister(collectors ...prometheus.Collector)
MustRegister registers collectors and panics on error.
func (*Registry) PrometheusRegistry ¶
func (r *Registry) PrometheusRegistry() *prometheus.Registry
PrometheusRegistry returns the underlying *prometheus.Registry.
func (*Registry) Register ¶
func (r *Registry) Register(name string, collector prometheus.Collector) error
Register registers a collector with the registry. It tracks the collector for later unregistration.
func (*Registry) Registerer ¶
func (r *Registry) Registerer() prometheus.Registerer
Registerer returns the underlying prometheus.Registerer interface.
func (*Registry) Summary ¶
func (r *Registry) Summary(name string) *SummaryBuilder
Summary creates a new SummaryBuilder.
func (*Registry) Unregister ¶
Unregister removes a collector from the registry.
func (*Registry) WithSubsystem ¶
WithSubsystem returns a new Registry with the same underlying registry but a different subsystem.
type SummaryBuilder ¶
type SummaryBuilder struct {
// contains filtered or unexported fields
}
SummaryBuilder provides a fluent interface for building Summary metrics.
func (*SummaryBuilder) Build ¶
func (b *SummaryBuilder) Build() prometheus.Summary
Build creates and registers a Summary (without labels).
func (*SummaryBuilder) BuildVec ¶
func (b *SummaryBuilder) BuildVec() *prometheus.SummaryVec
BuildVec creates and registers a SummaryVec (with labels).
func (*SummaryBuilder) ConstLabels ¶
func (b *SummaryBuilder) ConstLabels(labels prometheus.Labels) *SummaryBuilder
ConstLabels sets constant labels for the summary.
func (*SummaryBuilder) Help ¶
func (b *SummaryBuilder) Help(help string) *SummaryBuilder
Help sets the help text for the summary.
func (*SummaryBuilder) Labels ¶
func (b *SummaryBuilder) Labels(labels ...string) *SummaryBuilder
Labels sets the label names for the summary.
func (*SummaryBuilder) Objectives ¶
func (b *SummaryBuilder) Objectives(objectives map[float64]float64) *SummaryBuilder
Objectives sets the quantile objectives for the summary.