# README
Metrics Middleware
The package core/workers/metricsmw
is used to record and expose metrics for an application. The metrics server is be provided over HTTP using the prometheus extraction protocol.
You can read more about using prometheus in go on the their offical website.
gRPC server metrics
server := grpc.NewServer(
grpc.StreamInterceptor(metrics.StreamServerInterceptor),
grpc.UnaryInterceptor(metrics.UnaryServerInterceptor),
)
gRPC client metrics
conn, err = grpc.Dial(
address,
grpc.WithUnaryInterceptor(metrics.UnaryClientInterceptor),
grpc.WithStreamInterceptor(metrics.StreamClientInterceptor)
)
HTTP server metrics
Using gorilla mux.
r := mux.NewRouter()
r.Use(mux.MiddlewareFunc(metrics.MeasureRequestsMiddleware))
Using standard net/http library.
http.Handle("/check", metrics.MeasureRequests(func(w http.ResponseWriter, r *http.Request) {
w.WriteHeader(200)
}))
Time series buckets
The collection of histogram metrics must put data into predefined buckets.
These have been set at: 0.2, 0.4, 0.6, 0.8, 1.0, 1.5, 2.0, 5.0, 10.0, 15.0
seconds.
more information can be found here: Prometheus Documentation
# Functions
MeasureRequests returns a middleware for collecting metrics on http requests.
MeasureRequestsHandler wraps the measure requests handler in a http handler.
Register registers all the metric collectors with prometheus.
# Variables
All represents a combination of all HTTP metric collectors.
DefaultServerMetrics is the default instance of ServerMetrics.
MeasureRequestsMiddleware wraps the measure requests handler in a gorilla mux middleware.
RequestDurationHistogram measures the duration in seconds for requests.
ResponseSizeHistogram measures the size in bytes for responses.
StreamClientInterceptor is a gRPC client-side interceptor that provides Prometheus monitoring for Streaming RPCs.
StreamServerInterceptor is a gRPC server-side interceptor that provides Prometheus monitoring for Streaming RPCs.
UnaryClientInterceptor is a gRPC client-side interceptor that provides Prometheus monitoring for Unary RPCs.
UnaryServerInterceptor is a gRPC server-side interceptor that provides Prometheus monitoring for Unary RPCs.
# Type aliases
MiddlewareFunc represents a middleware func for use with gorilla mux.