Documentation ¶
Index ¶
- func GetChiPathPattern(ctx context.Context) string
- func Handler(registry *prometheus.Registry) http.Handler
- func NewHTTPServerMetricsMiddleware(registry *prometheus.Registry, serviceName string, ...) func(next http.Handler) http.Handler
- type Middleware
- type ProxyResponseWriter
- type StatusResponseWriter
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func GetChiPathPattern ¶
GetChiPathPattern will use the chi context to return the Route Pattern associated with the provided requests context.
Types ¶
type Middleware ¶
type Middleware struct {
// contains filtered or unexported fields
}
Middleware is a handler which exposes prometheus metrics. Requests will log the total number of requests partitioned by code, status and path. Latency will log the total duration of requests partitioned by code, status and path. getPathPattern allows you to pass a function which will group paths by specified patterns. If not value is assigned, the requests and latency will be partitioned by the standalone path on the incoming request.
func (*Middleware) MonitorMetrics ¶
func (m *Middleware) MonitorMetrics(next http.Handler) http.Handler
MonitorMetrics returns a http.Handler which will monitor the incoming request metrics and update the prometheus metric values.
type ProxyResponseWriter ¶
type ProxyResponseWriter interface { http.ResponseWriter Status() int }
ProxyResponseWriter is a proxy for a http.ResponseWriter allowing you to access the various parts of the response at a later date.
func NewStatusResponseWriter ¶
func NewStatusResponseWriter(w http.ResponseWriter) ProxyResponseWriter
NewStatusResponseWriter returns a ProxyResponseWriter which allows us to access the outgoing response status.
type StatusResponseWriter ¶
type StatusResponseWriter struct { http.ResponseWriter // contains filtered or unexported fields }
StatusResponseWriter implements the http.ResponseWriter interface and allows us access to the response status through the .Status() function.
func (*StatusResponseWriter) Status ¶
func (w *StatusResponseWriter) Status() int
Status returns the status assigned to the outgoing http response.
func (*StatusResponseWriter) Write ¶
func (w *StatusResponseWriter) Write(data []byte) (int, error)
Write is a wrapper around the ResponseWriter.Write function call which checks to see if the Status has been written, and defaults to http.StatusOK if not.
func (*StatusResponseWriter) WriteHeader ¶
func (w *StatusResponseWriter) WriteHeader(code int)
WriteHeader captures the assigned response code for access at a later time, and writes the response header accordingly.