mirror of
https://github.com/3ybactuk/marketplace-go-service-project.git
synced 2025-10-30 05:53:45 +03:00
32 lines
955 B
Go
32 lines
955 B
Go
package metrics
|
|
|
|
import (
|
|
"time"
|
|
|
|
"github.com/prometheus/client_golang/prometheus"
|
|
"github.com/prometheus/client_golang/prometheus/promauto"
|
|
)
|
|
|
|
var (
|
|
requestCounter = promauto.NewCounterVec(prometheus.CounterOpts{
|
|
Namespace: "app",
|
|
Name: "requests_total",
|
|
Help: "Total amount of request by handler",
|
|
}, []string{"method", "path", "status_code"})
|
|
|
|
requestDurationHistogram = promauto.NewHistogramVec(prometheus.HistogramOpts{
|
|
Namespace: "app",
|
|
Name: "request_duration_seconds",
|
|
Help: "Latency of handler processing, seconds",
|
|
Buckets: prometheus.DefBuckets,
|
|
}, []string{"method", "path", "status_code"})
|
|
)
|
|
|
|
func IncRequestHandlerCount(method, path, statusCode string) {
|
|
requestCounter.WithLabelValues(method, path, statusCode).Inc()
|
|
}
|
|
|
|
func StoreHandlerRequestDuration(method, path, statusCode string, d time.Duration) {
|
|
requestDurationHistogram.WithLabelValues(method, path, statusCode).Observe(d.Seconds())
|
|
}
|