add prometheus metrics
This commit is contained in:
@@ -11,6 +11,10 @@ import (
|
||||
"github.com/juju/zaputil/zapctx"
|
||||
"go.uber.org/zap"
|
||||
"moul.io/chizap"
|
||||
|
||||
"github.com/prometheus/client_golang/prometheus"
|
||||
"github.com/prometheus/client_golang/prometheus/promauto"
|
||||
"github.com/prometheus/client_golang/prometheus/promhttp"
|
||||
)
|
||||
|
||||
func someFunc(ctx context.Context) {
|
||||
@@ -34,7 +38,12 @@ func main() {
|
||||
WithUserAgent: true,
|
||||
}))
|
||||
|
||||
counter := promauto.NewCounter(prometheus.CounterOpts{
|
||||
Namespace: "teta", Name: "testcounter", Help: "Main endpoint request counter",
|
||||
})
|
||||
|
||||
r.Get("/", func(w http.ResponseWriter, r *http.Request) {
|
||||
counter.Inc()
|
||||
ctx := zapctx.WithLogger(r.Context(), logger)
|
||||
someFunc(ctx)
|
||||
_, err := w.Write([]byte("welcome"))
|
||||
@@ -43,6 +52,9 @@ func main() {
|
||||
}
|
||||
})
|
||||
|
||||
http.Handle("/metrics", promhttp.Handler())
|
||||
go http.ListenAndServe(":9000", nil) //nolint:errcheck
|
||||
|
||||
logger.Info("Server started")
|
||||
http.ListenAndServe(":8080", r) //nolint:errcheck
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user