metrics

package module
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Mar 27, 2026 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrEmptyHost = errors.New("host cannot be empty")
	ErrZeroPort  = errors.New("port cannot be zero")
)
View Source
var (
	// Registerer allows custom metric registration.
	Registerer = prometheus.DefaultRegisterer
)

Functions

func RequestDurationMetricHTTPMiddleware

func RequestDurationMetricHTTPMiddleware(next http.Handler) http.Handler

RequestDurationMetricHTTPMiddleware tracks HTTP request duration.

func RequestDurationMetricUnaryServerInterceptor

func RequestDurationMetricUnaryServerInterceptor(serviceName string) grpc.UnaryServerInterceptor

RequestDurationMetricUnaryServerInterceptor tracks gRPC request duration.

func SetRegisterer

func SetRegisterer(r prometheus.Registerer)

SetRegisterer sets a custom Prometheus registerer.

Types

type Config

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

Config defines the metrics server configuration.

func NewConfig

func NewConfig(opts ...Option) *Config

NewConfig creates a new Config with defaults and applies options.

func (*Config) Validate

func (c *Config) Validate() error

Validate checks if the configuration is valid.

type Counter

type Counter = prometheus.Counter

Metric types (aliases from Prometheus).

func NewCounter

func NewCounter(opts CounterOpts) Counter

NewCounter creates a Counter metric.

type CounterOpts

type CounterOpts = prometheus.CounterOpts

Metric types (aliases from Prometheus).

type CounterVec

type CounterVec = prometheus.CounterVec

Metric types (aliases from Prometheus).

func NewCounterVec

func NewCounterVec(opts CounterOpts, labels []string) *CounterVec

NewCounterVec creates a CounterVec metric.

type GRPCConnectionMonitor

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

GRPCConnectionMonitor periodically checks gRPC service health.

func NewGRPCConnectionMonitor

func NewGRPCConnectionMonitor(
	service GRPCService,
	pingTimer time.Duration,
	serviceFrom string,
	serviceTo string,
) *GRPCConnectionMonitor

NewGRPCConnectionMonitor creates a new monitor.

func (*GRPCConnectionMonitor) Close

func (s *GRPCConnectionMonitor) Close() error

Close stops the monitor.

func (*GRPCConnectionMonitor) Start

func (s *GRPCConnectionMonitor) Start(ctx context.Context)

Start begins health checks.

type GRPCService

type GRPCService interface {
	Connection() grpc.ClientConnInterface
}

GRPCService defines the interface for gRPC connections.

type Gauge

type Gauge = prometheus.Gauge

Metric types (aliases from Prometheus).

func NewGauge

func NewGauge(opts GaugeOpts) Gauge

NewGauge creates a Gauge metric.

type GaugeOpts

type GaugeOpts = prometheus.GaugeOpts

Metric types (aliases from Prometheus).

type GaugeVec

type GaugeVec = prometheus.GaugeVec

Metric types (aliases from Prometheus).

func NewGaugeVec

func NewGaugeVec(opts GaugeOpts, labels []string) *GaugeVec

NewGaugeVec creates a GaugeVec metric.

type Histogram

type Histogram = prometheus.Histogram

Metric types (aliases from Prometheus).

func NewHistogram

func NewHistogram(opts HistogramOpts) Histogram

NewHistogram creates a Histogram metric.

type HistogramOpts

type HistogramOpts = prometheus.HistogramOpts

Metric types (aliases from Prometheus).

type HistogramVec

type HistogramVec = prometheus.HistogramVec

Metric types (aliases from Prometheus).

func NewHistogramVec

func NewHistogramVec(opts HistogramOpts, labels []string) *HistogramVec

NewHistogramVec creates a HistogramVec metric.

type Option

type Option func(*Config)

Option configures the Config.

func WithHost

func WithHost(host string) Option

WithHost sets the server host (default: "0.0.0.0").

func WithPort

func WithPort(port int) Option

WithPort sets the server port (default: 8080).

func WithReadHeaderTimeout

func WithReadHeaderTimeout(timeout time.Duration) Option

WithReadHeaderTimeout sets the read header timeout (default: 5s).

func WithReadTimeout

func WithReadTimeout(timeout time.Duration) Option

WithReadTimeout sets the read timeout (default: 10s).

func WithWriteTimeout

func WithWriteTimeout(timeout time.Duration) Option

WithWriteTimeout sets the write timeout (default: 10s).

type Server

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

Server runs the metrics HTTP server.

func NewServer

func NewServer(cfg *Config) (*Server, error)

NewServer initializes a new metrics server.

func (*Server) Close

func (s *Server) Close() error

Close shuts down the server.

func (*Server) Run

func (s *Server) Run(_ context.Context) error

Run starts the metrics server.

Jump to

Keyboard shortcuts

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