Documentation
¶
Overview ¶
`http_metrics` provides client and server side reporting of HTTP stats.
The middleware (server-side) or tripperware (client-side) must be given a reporter to record the stats for each request.
Prometheus-based reporter implementations for client and server metrics are included. The user may choose what level of detail is included using options to these reporters.
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Middleware ¶
func Middleware(reporter Reporter) httpwares.Middleware
Middleware returns a http.Handler middleware that exports request metrics. If the tags middleware is used, this should be placed after tags to pick up metadata. This middleware assumes HTTP/1.x-style requests/response behaviour. It will not work with servers that use hijacking, pushing, or other similar features.
Example ¶
r := chi.NewRouter()
r.Use(http_ctxtags.Middleware("default"))
r.Use(http_metrics.Middleware(http_prometheus.ServerMetrics(http_prometheus.WithLatency())))
r.Get("/", func(w http.ResponseWriter, r *http.Request) {
w.WriteHeader(200)
})
http.ListenAndServe(":8888", r)
func Tripperware ¶
func Tripperware(reporter Reporter) httpwares.Tripperware
Tripperware returns a new client-side ware that exports request metrics. If the tags tripperware is used, this should be placed after tags to pick up metadata.
Example ¶
c := httpwares.WrapClient(
http.DefaultClient,
http_ctxtags.Tripperware(),
http_metrics.Tripperware(http_prometheus.ClientMetrics(http_prometheus.WithName("testclient"))),
)
c.Get("example.org/foo")
Types ¶
type Tracker ¶
type Tracker interface {
// The exchange has started. This is called immediately after Reporter.Track.
// On the client, this is called before any data is sent.
// On the server, this is called after headers have been parsed.
RequestStarted()
// The request body has been read to EOF or closed, whichever comes first.
// On the client, this is called when the transport completes sending the request.
// On the server, this is called when the handler completes reading the request, and may be omitted.
RequestRead(duration time.Duration, size int)
// The handling of the response has started.
// On the client, this is called after the response headers have been parsed.
// On the server, this is called before any data is written.
ResponseStarted(duration time.Duration, status int, header http.Header)
// The response has completed.
// On the client, this is called when the body is read to EOF or closed, whichever comes first, and may be omitted.
// On the server, this is called when the handler returns and has therefore completed writing the response.
ResponseDone(duration time.Duration, status int, size int)
}
Receives events about a tracked request.