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 ¶
- func GRPCStreamServerInterceptor() grpc.StreamServerInterceptor
- func GRPCUnaryServerInterceptor() grpc.UnaryServerInterceptor
- func GinMiddleware() gin.HandlerFunc
- func Handler() gin.HandlerFunc
- func HandlerFromEnv() gin.HandlerFunc
- func HandlerWithAccess(token string, allowedCIDRs []string) gin.HandlerFunc
- func Init(serviceName string)
- func ObserveCircuitBreaker(name, state string)
- func ObserveDBPool(name string, stats sql.DBStats)
- func ObserveDependency(dependency, operation, status string, duration time.Duration)
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
ObserveDBPool records a database/sql connection pool snapshot.
func ObserveDependency ¶ added in v0.13.0
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.