metrics

package
v0.16.0 Latest Latest
Warning

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

Go to latest
Published: Oct 9, 2026 License: MIT Imports: 16 Imported by: 0

Documentation

Overview

Package metrics provides Prometheus metrics collection for HTTP and gRPC services.

Usage:

metrics.Init("mf-user")
r.Use(metrics.GinMiddleware())
r.GET("/metrics", metrics.Handler())

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GRPCStreamServerInterceptor added in v0.11.0

func GRPCStreamServerInterceptor() grpc.StreamServerInterceptor

GRPCStreamServerInterceptor records streaming RPC lifetime and status codes.

func GRPCUnaryServerInterceptor added in v0.11.0

func GRPCUnaryServerInterceptor() grpc.UnaryServerInterceptor

GRPCUnaryServerInterceptor records unary gRPC latency and status codes.

func GinMiddleware

func GinMiddleware() gin.HandlerFunc

GinMiddleware returns a Gin middleware that records request metrics.

func Handler

func Handler() gin.HandlerFunc

Handler returns a Gin handler that serves the Prometheus metrics endpoint.

r.GET("/metrics", metrics.Handler())

func HandlerFromEnv added in v0.13.0

func HandlerFromEnv() gin.HandlerFunc

HandlerFromEnv is a convenience for services that keep metrics on their normal listener. It reads METRICS_TOKEN and METRICS_ALLOWED_CIDRS at startup.

func HandlerWithAccess added in v0.13.0

func HandlerWithAccess(token string, allowedCIDRs []string) gin.HandlerFunc

HandlerWithAccess serves metrics with optional bearer-token and source-CIDR protection. Metrics commonly contain operational details and should not be exposed on a public listener without one of these controls.

func Init

func Init(serviceName string)

Init sets the service label used by subsequent observations and ensures the collectors are registered. It is safe to call again after a config reload.

func ObserveCircuitBreaker added in v0.13.0

func ObserveCircuitBreaker(name, state string)

ObserveCircuitBreaker publishes the current state of one breaker.

func ObserveDBPool added in v0.13.0

func ObserveDBPool(name string, stats sql.DBStats)

ObserveDBPool records a database/sql connection pool snapshot.

func ObserveDependency added in v0.13.0

func ObserveDependency(dependency, operation, status string, duration time.Duration)

ObserveDependency records an outbound dependency call. Status should be a stable class or code (for example "ok", "timeout", or "503").

Types

This section is empty.

Jump to

Keyboard shortcuts

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