mirror of
https://github.com/3ybactuk/marketplace-go-service-project.git
synced 2025-10-30 05:53:45 +03:00
32 lines
850 B
Go
32 lines
850 B
Go
package metrics
|
|
|
|
import (
|
|
"time"
|
|
|
|
"github.com/prometheus/client_golang/prometheus"
|
|
"github.com/prometheus/client_golang/prometheus/promauto"
|
|
)
|
|
|
|
var (
|
|
dbQueryCounter = promauto.NewCounterVec(prometheus.CounterOpts{
|
|
Namespace: "app",
|
|
Name: "db_queries_total",
|
|
Help: "Total DB queries",
|
|
}, []string{"category", "error"})
|
|
|
|
dbQueryDurationHistogram = promauto.NewHistogramVec(prometheus.HistogramOpts{
|
|
Namespace: "app",
|
|
Name: "db_query_duration_seconds",
|
|
Help: "Latency of DB queries, seconds",
|
|
Buckets: prometheus.DefBuckets,
|
|
}, []string{"category", "error"})
|
|
)
|
|
|
|
func IncDBQueryCount(cat, errLabel string) {
|
|
dbQueryCounter.WithLabelValues(cat, errLabel).Inc()
|
|
}
|
|
|
|
func StoreDBQueryDuration(cat, errLabel string, d time.Duration) {
|
|
dbQueryDurationHistogram.WithLabelValues(cat, errLabel).Observe(d.Seconds())
|
|
}
|