Documentation ¶
Overview ¶
Package gohttpmetrics knows how to measure http metrics in different metric formats, it comes with a middleware that can be used for different frameworks and also the the main Go net/http handler:
package main import ( "log" "net/http" "github.com/prometheus/client_golang/prometheus/promhttp" httpmetrics "github.com/slok/go-http-metrics/metrics/prometheus" httpmiddleware "github.com/slok/go-http-metrics/middleware" httpstdmiddleware "github.com/slok/go-http-metrics/middleware/std" ) func main() { // Create our middleware. mdlw := httpmiddleware.New(httpmiddleware.Config{ Recorder: httpmetrics.NewRecorder(httpmetrics.Config{}), }) // Our handler. myHandler := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { w.WriteHeader(http.StatusOK) w.Write([]byte("hello world!")) }) h := httpstdmiddleware.Handler("", mdlw, myHandler) // Serve metrics. log.Printf("serving metrics at: %s", ":9090") go http.ListenAndServe(":9090", promhttp.Handler()) // Serve our handler. log.Printf("listening at: %s", ":8080") if err := http.ListenAndServe(":8080", h); err != nil { log.Panicf("error while serving: %s", err) } }
Directories ¶
Path | Synopsis |
---|---|
examples
|
|
internal
|
|
mocks
Package mocks will have all the mocks of the library.
|
Package mocks will have all the mocks of the library. |
Package middleware will measure metrics of different http handler types using a `metrics.Recorder`.
|
Package middleware will measure metrics of different http handler types using a `metrics.Recorder`. |
chi
Package std is a helper package to get a standard `http.Handler` compatible middleware.
|
Package std is a helper package to get a standard `http.Handler` compatible middleware. |
echo
Package echo is a helper package to get an echo compatible middleware
|
Package echo is a helper package to get an echo compatible middleware |
fasthttp
Package fasthttp is a helper package to get a fasthttp compatible middleware.
|
Package fasthttp is a helper package to get a fasthttp compatible middleware. |
gin
Package gin is a helper package to get a gin compatible middleware.
|
Package gin is a helper package to get a gin compatible middleware. |
goji
Package goji is a helper package to get a goji compatible middleware.
|
Package goji is a helper package to get a goji compatible middleware. |
gorestful
Package gorestful is a helper package to get a gorestful compatible middleware.
|
Package gorestful is a helper package to get a gorestful compatible middleware. |
httprouter
Package httprouter is a helper package to get a httprouter compatible middleware.
|
Package httprouter is a helper package to get a httprouter compatible middleware. |
iris
Package iris is a helper package to get an Iris compatible middleware.
|
Package iris is a helper package to get an Iris compatible middleware. |
negroni
Package negroni is a helper package to get a negroni compatible middleware.
|
Package negroni is a helper package to get a negroni compatible middleware. |
std
Package std is a helper package to get a standard `http.Handler` compatible middleware.
|
Package std is a helper package to get a standard `http.Handler` compatible middleware. |
Click to show internal directories.
Click to hide internal directories.