Prometheus metrics exporter for fasthttp. On every method creates two metrics: total and failure.
For example you want to register path /user/:id/some-method
in your fasthttp server.
Library will create metrics based on OpenMetrics:
{prefix}_user_some_method_requests_total
{prefix}_user_some_method_requests_failure_total
go get github.com/fruiting/fasthttp-prometheus
import (
"github.com/buaazp/fasthttprouter"
fasthttpprometheus "github.com/fruiting/fasthttp-prometheus"
"github.com/valyala/fasthttp"
"go.uber.org/zap"
)
func main() {
wrappedRouter := fasthttpprometheus.NewHandler(fasthttprouter.New(), "test_service", zap.NewExample())
wrappedRouter.GET("/ping", func(ctx *fasthttp.RequestCtx) {
ctx.SuccessString("text/plain; charset=utf-8", "PONG")
})
fasthttp.ListenAndServe(":8080", wrappedRouter.Handler)
}
Benchmark shows about 10% speed reduction of fasthttp. On MacBook M1 Pro on the same list of registered routes fasthttp shows 8900-9200 ns/op and 9600-10000 ns/op if fasthttp is wrapped by this library.
- Run unit tests
go test ./...
- Run benchmarks
go test -bench=.
- Push, make pull request
Roman Spirin