Documentation ¶
Overview ¶
Package metricsmw is used to record and expose metrics for an application.
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
var ( // RequestCounter counts the number of requests for a combination of method, code and path. RequestCounter = prometheus.NewCounterVec( prometheus.CounterOpts{ Name: "http_request_total", Help: "A running count for HTTP requests", }, []string{"method", "code", "path"}, ) // RequestDurationHistogram measures the duration in nanoseconds for requests. RequestDurationHistogram = prometheus.NewHistogramVec( prometheus.HistogramOpts{ Name: "http_request_duration_nanoseconds", Help: "Duration in nanoseconds of each request", }, []string{"method", "code", "path"}, ) // ResponseSizeHistogram measures the size in bytes for responses. ResponseSizeHistogram = prometheus.NewHistogramVec( prometheus.HistogramOpts{ Name: "http_response_byte_size", Help: "Size in bytes of each response", }, []string{"method", "code", "path"}, ) // All represents a combination of all HTTP metric collectors. All = []prometheus.Collector{ RequestCounter, RequestDurationHistogram, ResponseSizeHistogram, } )
var DefaultServerMetrics = grpc_prometheus.DefaultServerMetrics
DefaultServerMetrics is the default instance of ServerMetrics. It is intended to be used in conjunction the default Prometheus metrics registry.
var MeasureRequestsMiddleware = MiddlewareFunc(MeasureRequestsHandler)
MeasureRequestsMiddleware wraps the measure requests handler in a gorilla mux middleware.
var StreamClientInterceptor = grpc_prometheus.StreamClientInterceptor
StreamClientInterceptor is a gRPC client-side interceptor that provides Prometheus monitoring for Streaming RPCs.
var StreamServerInterceptor = grpc_prometheus.StreamServerInterceptor
StreamServerInterceptor is a gRPC server-side interceptor that provides Prometheus monitoring for Streaming RPCs.
var UnaryClientInterceptor = grpc_prometheus.UnaryClientInterceptor
UnaryClientInterceptor is a gRPC client-side interceptor that provides Prometheus monitoring for Unary RPCs.
var UnaryServerInterceptor = grpc_prometheus.UnaryServerInterceptor
UnaryServerInterceptor is a gRPC server-side interceptor that provides Prometheus monitoring for Unary RPCs.
Functions ¶
func MeasureRequests ¶
func MeasureRequests(next http.HandlerFunc) http.HandlerFunc
MeasureRequests returns a middleware for collecting metrics on http requests.
Example ¶
package main import ( "net/http" "github.com/LUSHDigital/core/middleware/metricsmw" ) func main() { http.Handle("/check", metricsmw.MeasureRequests(func(w http.ResponseWriter, r *http.Request) { w.WriteHeader(200) })) }
Output:
func MeasureRequestsHandler ¶
MeasureRequestsHandler wraps the measure requests handler in a http handler.
Types ¶
type MiddlewareFunc ¶
MiddlewareFunc represents a middleware func for use with gorilla mux.
func (MiddlewareFunc) Middleware ¶
func (mw MiddlewareFunc) Middleware(handler http.Handler) http.Handler
Middleware allows MiddlewareFunc to implement the middleware interface.