[#426] Put prometheus behind pkg/metrics
Signed-off-by: Alex Vanin <alexey@nspcc.ru>
This commit is contained in:
parent
3c0e47e6fd
commit
b8e10571c6
19 changed files with 561 additions and 311 deletions
|
@ -2,112 +2,26 @@ package engine
|
|||
|
||||
import (
|
||||
"time"
|
||||
|
||||
"github.com/prometheus/client_golang/prometheus"
|
||||
)
|
||||
|
||||
const (
|
||||
namespace = "neofs_node"
|
||||
subsystem = "engine"
|
||||
)
|
||||
|
||||
var (
|
||||
listContainersDuration = prometheus.NewCounter(prometheus.CounterOpts{
|
||||
Namespace: namespace,
|
||||
Subsystem: subsystem,
|
||||
Name: "list_containers_duration",
|
||||
Help: "Accumulated duration of engine list containers operations",
|
||||
})
|
||||
|
||||
estimateContainerSizeDuration = prometheus.NewCounter(prometheus.CounterOpts{
|
||||
Namespace: namespace,
|
||||
Subsystem: subsystem,
|
||||
Name: "estimate_container_size_duration",
|
||||
Help: "Accumulated duration of engine container size estimate operations",
|
||||
})
|
||||
|
||||
deleteDuration = prometheus.NewCounter(prometheus.CounterOpts{
|
||||
Namespace: namespace,
|
||||
Subsystem: subsystem,
|
||||
Name: "delete_duration",
|
||||
Help: "Accumulated duration of engine delete operations",
|
||||
})
|
||||
|
||||
existsDuration = prometheus.NewCounter(prometheus.CounterOpts{
|
||||
Namespace: namespace,
|
||||
Subsystem: subsystem,
|
||||
Name: "exists_duration",
|
||||
Help: "Accumulated duration of engine exists operations",
|
||||
})
|
||||
|
||||
getDuration = prometheus.NewCounter(prometheus.CounterOpts{
|
||||
Namespace: namespace,
|
||||
Subsystem: subsystem,
|
||||
Name: "get_duration",
|
||||
Help: "Accumulated duration of engine get operations",
|
||||
})
|
||||
|
||||
headDuration = prometheus.NewCounter(prometheus.CounterOpts{
|
||||
Namespace: namespace,
|
||||
Subsystem: subsystem,
|
||||
Name: "head_duration",
|
||||
Help: "Accumulated duration of engine head operations",
|
||||
})
|
||||
|
||||
inhumeDuration = prometheus.NewCounter(prometheus.CounterOpts{
|
||||
Namespace: namespace,
|
||||
Subsystem: subsystem,
|
||||
Name: "inhume_duration",
|
||||
Help: "Accumulated duration of engine inhume operations",
|
||||
})
|
||||
|
||||
putDuration = prometheus.NewCounter(prometheus.CounterOpts{
|
||||
Namespace: namespace,
|
||||
Subsystem: subsystem,
|
||||
Name: "put_duration",
|
||||
Help: "Accumulated duration of engine put operations",
|
||||
})
|
||||
|
||||
rangeDuration = prometheus.NewCounter(prometheus.CounterOpts{
|
||||
Namespace: namespace,
|
||||
Subsystem: subsystem,
|
||||
Name: "range_duration",
|
||||
Help: "Accumulated duration of engine range operations",
|
||||
})
|
||||
|
||||
searchDuration = prometheus.NewCounter(prometheus.CounterOpts{
|
||||
Namespace: namespace,
|
||||
Subsystem: subsystem,
|
||||
Name: "search_duration",
|
||||
Help: "Accumulated duration of engine search operations",
|
||||
})
|
||||
|
||||
listObjectsDuration = prometheus.NewCounter(prometheus.CounterOpts{
|
||||
Namespace: namespace,
|
||||
Subsystem: subsystem,
|
||||
Name: "list_objects_duration",
|
||||
Help: "Accumulated duration of engine list objects operations",
|
||||
})
|
||||
)
|
||||
|
||||
func registerMetrics() {
|
||||
prometheus.MustRegister(listContainersDuration)
|
||||
prometheus.MustRegister(estimateContainerSizeDuration)
|
||||
prometheus.MustRegister(deleteDuration)
|
||||
prometheus.MustRegister(existsDuration)
|
||||
prometheus.MustRegister(getDuration)
|
||||
prometheus.MustRegister(headDuration)
|
||||
prometheus.MustRegister(inhumeDuration)
|
||||
prometheus.MustRegister(putDuration)
|
||||
prometheus.MustRegister(rangeDuration)
|
||||
prometheus.MustRegister(searchDuration)
|
||||
prometheus.MustRegister(listObjectsDuration)
|
||||
type MetricRegister interface {
|
||||
AddListContainersDuration(d time.Duration)
|
||||
AddEstimateContainerSizeDuration(d time.Duration)
|
||||
AddDeleteDuration(d time.Duration)
|
||||
AddExistsDuration(d time.Duration)
|
||||
AddGetDuration(d time.Duration)
|
||||
AddHeadDuration(d time.Duration)
|
||||
AddInhumeDuration(d time.Duration)
|
||||
AddPutDuration(d time.Duration)
|
||||
AddRangeDuration(d time.Duration)
|
||||
AddSearchDuration(d time.Duration)
|
||||
AddListObjectsDuration(d time.Duration)
|
||||
}
|
||||
|
||||
func elapsed(c prometheus.Counter) func() {
|
||||
func elapsed(addFunc func(d time.Duration)) func() {
|
||||
t := time.Now()
|
||||
|
||||
return func() {
|
||||
c.Add(float64(time.Since(t)))
|
||||
addFunc(time.Since(t))
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue