All checks were successful
DCO action / DCO (pull_request) Successful in 2m40s
Vulncheck / Vulncheck (pull_request) Successful in 4m30s
Build / Build Components (1.22) (pull_request) Successful in 4m53s
Build / Build Components (1.21) (pull_request) Successful in 4m59s
Pre-commit hooks / Pre-commit (pull_request) Successful in 5m48s
Tests and linters / gopls check (pull_request) Successful in 5m35s
Tests and linters / Staticcheck (pull_request) Successful in 7m22s
Tests and linters / Lint (pull_request) Successful in 8m35s
Tests and linters / Tests with -race (pull_request) Successful in 10m37s
Tests and linters / Tests (1.21) (pull_request) Successful in 10m49s
Tests and linters / Tests (1.22) (pull_request) Successful in 11m2s
Signed-off-by: Dmitrii Stepanov <d.stepanov@yadro.com>
35 lines
895 B
Go
35 lines
895 B
Go
package metrics
|
|
|
|
import (
|
|
"strconv"
|
|
"time"
|
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-observability/metrics"
|
|
"github.com/prometheus/client_golang/prometheus"
|
|
)
|
|
|
|
var cacheRequests = metrics.NewHistogramVec(prometheus.HistogramOpts{
|
|
Namespace: namespace,
|
|
Subsystem: commonCacheSubsystem,
|
|
Name: "request_duration_seconds",
|
|
Help: "Accumulated common cache request process duration",
|
|
}, []string{hitLabel, methodLabel, cacheLabel})
|
|
|
|
type CacheMetrics struct {
|
|
cache string
|
|
}
|
|
|
|
// NewCacheMetrics returns new CacheMetrics instance for cache specified.
|
|
func NewCacheMetrics(cache string) *CacheMetrics {
|
|
return &CacheMetrics{
|
|
cache: cache,
|
|
}
|
|
}
|
|
|
|
func (m *CacheMetrics) AddMethodDuration(method string, d time.Duration, hit bool) {
|
|
cacheRequests.With(prometheus.Labels{
|
|
hitLabel: strconv.FormatBool(hit),
|
|
methodLabel: method,
|
|
cacheLabel: m.cache,
|
|
}).Observe(d.Seconds())
|
|
}
|