Documentation
¶
Index ¶
- Variables
- func Context(ctx context.Context, svc string, opts ...Option) context.Context
- func HTTP(ctx context.Context) func(http.Handler) http.Handler
- func Handler(ctx context.Context, opts ...handlerOption) http.Handler
- func StreamServerInterceptor(ctx context.Context) grpc.StreamServerInterceptor
- func UnaryServerInterceptor(ctx context.Context) grpc.UnaryServerInterceptor
- func WithGatherer(gatherer prometheus.Gatherer) handlerOption
- func WithHandlerRegisterer(registerer prometheus.Registerer) handlerOption
- type Option
- type RouteResolver
Constants ¶
This section is empty.
Variables ¶
var ( DefaultDurationBuckets = []float64{10, 25, 50, 100, 250, 500, 1000, 2500, 5000, 10000} DefaultRequestSizeBuckets = []float64{10, 100, 500, 1000, 5000, 10000, 50000, 100000, 1000000, 10000000} DefaultResponseSizeBuckets = []float64{10, 100, 500, 1000, 5000, 10000, 50000, 100000, 1000000, 10000000} )
Functions ¶
func Context ¶
Context initializes the given context for the HTTP, UnaryInterceptor and StreamInterceptor functions.
func HTTP ¶
HTTP returns a middlware that metricss requests. The context must have been initialized with Context. HTTP collects the following metrics:
- `http.server.duration`: Histogram of request durations in milliseconds.
- `http.server.active_requests`: UpDownCounter of active requests.
- `http.server.request.size`: Histogram of request sizes in bytes.
- `http.server.response.size`: Histogram of response sizes in bytes.
All the metrics have the following labels:
- `http.verb`: The HTTP verb (`GET`, `POST` etc.).
- `http.host`: The value of the HTTP host header.
- `http.path`: The HTTP path.
- `http.status_code`: The HTTP status code.
Errors collecting or serving metrics are logged to the logger in the context if any.
func Handler ¶
Handler returns a HTTP handler that collect metrics and serves them using the Prometheus export formats. It uses the context logger configured via micro/log if any to log errors. By default Handler uses the default prometheus registry to gather metrics and to register its own metrics. Use options WithGatherer and WithHandlerRegisterer to override the default values.
func StreamServerInterceptor ¶
func StreamServerInterceptor(ctx context.Context) grpc.StreamServerInterceptor
StreamServerInterceptor creates a gRPC stream server interceptor that metricss the requests. The context must have been initialized with Context. The returned interceptor adds the following metrics:
- `grpc.server.active_requests`: UpDownCounter of active requests.
- `grpc.server.request.size`: Histogram of request sizes in bytes.
- `grpc.server.response.size`: Histogram of response sizes in bytes.
All the metrics have the following labels:
- `goa.method`: The method name as specified in the Goa design.
- `goa.service`: The service name as specified in the Goa design.
- `rpc.system`: A stream identifying the remoting system (e.g. `grpc`).
- `rpc.service`: Name of RPC service.
- `rpc.method`: Name of RPC method.
- `rpc.status_code`: The response status code.
Errors collecting or serving metrics are logged to the logger in the context if any.
func UnaryServerInterceptor ¶
func UnaryServerInterceptor(ctx context.Context) grpc.UnaryServerInterceptor
UnaryServerInterceptor creates a gRPC unary server interceptor that metricss the requests. The context must have been initialized with metrics.Context. The returned interceptor adds the following metrics:
- `grpc.server.duration`: Histogram of request durations in milliseconds.
- `grpc.server.active_requests`: UpDownCounter of active requests.
- `grpc.server.request.size`: Histogram of request sizes in bytes.
- `grpc.server.response.size`: Histogram of response sizes in bytes.
All the metrics have the following labels:
- `goa.method`: The method name as specified in the Goa design.
- `goa.service`: The service name as specified in the Goa design.
- `rpc.system`: A stream identifying the remoting system (e.g. `grpc`).
- `rpc.service`: Name of RPC service.
- `rpc.method`: Name of RPC method.
- `rpc.status_code`: The response status code.
Errors collecting or serving metrics are logged to the logger in the context if any.
func WithGatherer ¶
func WithGatherer(gatherer prometheus.Gatherer) handlerOption
WithGatherer returns an option that sets the prometheus gatherer used to collect the metrics.
func WithHandlerRegisterer ¶
func WithHandlerRegisterer(registerer prometheus.Registerer) handlerOption
WithHandlerRegisterer returns an option that sets the prometheus registerer.
Types ¶
type Option ¶
type Option func(*options)
Option is a function that configures the metricsation.
func WithDurationBuckets ¶
WithDurationBuckets returns an option that sets the duration buckets for the request duration histogram.
func WithRegisterer ¶
func WithRegisterer(registerer prometheus.Registerer) Option
WithRegisterer returns an option that sets the prometheus registerer.
func WithRequestSizeBuckets ¶
WithRequestSizeBuckets returns an option that sets the request size buckets for the request size histogram.
func WithResponseSizeBuckets ¶
WithResponseSizeBuckets returns an option that sets the response size buckets for the response size histogram.
func WithRouteResolver ¶ added in v0.9.0
func WithRouteResolver(resolver RouteResolver) Option
WithRouteResolver returns an option that sets the route resolver used to label metrics. The default uses the request path.
type RouteResolver ¶ added in v0.9.0
RouteResolver is a function that resolves the route of a request used to label metrics. Using a route resolver makes it possible to label all routes matching a pattern with the same label. As an example services using the github.com/go-chi/chi/v5 muxer can use chi.RouteContext(r.Context()).RoutePattern().