mirror of
https://github.com/3ybactuk/marketplace-go-service-project.git
synced 2025-10-30 14:03:45 +03:00
[hw-7] add metrics, tracing
This commit is contained in:
31
loms/internal/infra/grpc/metrics/db.go
Normal file
31
loms/internal/infra/grpc/metrics/db.go
Normal file
@@ -0,0 +1,31 @@
|
||||
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())
|
||||
}
|
||||
Reference in New Issue
Block a user