forked from TrueCloudLab/frostfs-node
[#213] metrics: Refactor engine metrics
Resolve funlen linter for newEngineMetrics function. Signed-off-by: Dmitrii Stepanov <d.stepanov@yadro.com>
This commit is contained in:
parent
b689027d57
commit
38ae71cc7d
1 changed files with 40 additions and 107 deletions
|
@ -1,6 +1,8 @@
|
||||||
package metrics
|
package metrics
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/prometheus/client_golang/prometheus"
|
"github.com/prometheus/client_golang/prometheus"
|
||||||
|
@ -26,118 +28,49 @@ type (
|
||||||
|
|
||||||
const engineSubsystem = "engine"
|
const engineSubsystem = "engine"
|
||||||
|
|
||||||
// nolint: funlen
|
|
||||||
func newEngineMetrics() engineMetrics {
|
func newEngineMetrics() engineMetrics {
|
||||||
var (
|
|
||||||
listContainersDuration = prometheus.NewCounter(prometheus.CounterOpts{
|
|
||||||
Namespace: namespace,
|
|
||||||
Subsystem: engineSubsystem,
|
|
||||||
Name: "list_containers_duration",
|
|
||||||
Help: "Accumulated duration of engine list containers operations",
|
|
||||||
})
|
|
||||||
|
|
||||||
estimateContainerSizeDuration = prometheus.NewCounter(prometheus.CounterOpts{
|
|
||||||
Namespace: namespace,
|
|
||||||
Subsystem: engineSubsystem,
|
|
||||||
Name: "estimate_container_size_duration",
|
|
||||||
Help: "Accumulated duration of engine container size estimate operations",
|
|
||||||
})
|
|
||||||
|
|
||||||
deleteDuration = prometheus.NewCounter(prometheus.CounterOpts{
|
|
||||||
Namespace: namespace,
|
|
||||||
Subsystem: engineSubsystem,
|
|
||||||
Name: "delete_duration",
|
|
||||||
Help: "Accumulated duration of engine delete operations",
|
|
||||||
})
|
|
||||||
|
|
||||||
existsDuration = prometheus.NewCounter(prometheus.CounterOpts{
|
|
||||||
Namespace: namespace,
|
|
||||||
Subsystem: engineSubsystem,
|
|
||||||
Name: "exists_duration",
|
|
||||||
Help: "Accumulated duration of engine exists operations",
|
|
||||||
})
|
|
||||||
|
|
||||||
getDuration = prometheus.NewCounter(prometheus.CounterOpts{
|
|
||||||
Namespace: namespace,
|
|
||||||
Subsystem: engineSubsystem,
|
|
||||||
Name: "get_duration",
|
|
||||||
Help: "Accumulated duration of engine get operations",
|
|
||||||
})
|
|
||||||
|
|
||||||
headDuration = prometheus.NewCounter(prometheus.CounterOpts{
|
|
||||||
Namespace: namespace,
|
|
||||||
Subsystem: engineSubsystem,
|
|
||||||
Name: "head_duration",
|
|
||||||
Help: "Accumulated duration of engine head operations",
|
|
||||||
})
|
|
||||||
|
|
||||||
inhumeDuration = prometheus.NewCounter(prometheus.CounterOpts{
|
|
||||||
Namespace: namespace,
|
|
||||||
Subsystem: engineSubsystem,
|
|
||||||
Name: "inhume_duration",
|
|
||||||
Help: "Accumulated duration of engine inhume operations",
|
|
||||||
})
|
|
||||||
|
|
||||||
putDuration = prometheus.NewCounter(prometheus.CounterOpts{
|
|
||||||
Namespace: namespace,
|
|
||||||
Subsystem: engineSubsystem,
|
|
||||||
Name: "put_duration",
|
|
||||||
Help: "Accumulated duration of engine put operations",
|
|
||||||
})
|
|
||||||
|
|
||||||
rangeDuration = prometheus.NewCounter(prometheus.CounterOpts{
|
|
||||||
Namespace: namespace,
|
|
||||||
Subsystem: engineSubsystem,
|
|
||||||
Name: "range_duration",
|
|
||||||
Help: "Accumulated duration of engine range operations",
|
|
||||||
})
|
|
||||||
|
|
||||||
searchDuration = prometheus.NewCounter(prometheus.CounterOpts{
|
|
||||||
Namespace: namespace,
|
|
||||||
Subsystem: engineSubsystem,
|
|
||||||
Name: "search_duration",
|
|
||||||
Help: "Accumulated duration of engine search operations",
|
|
||||||
})
|
|
||||||
|
|
||||||
listObjectsDuration = prometheus.NewCounter(prometheus.CounterOpts{
|
|
||||||
Namespace: namespace,
|
|
||||||
Subsystem: engineSubsystem,
|
|
||||||
Name: "list_objects_duration",
|
|
||||||
Help: "Accumulated duration of engine list objects operations",
|
|
||||||
})
|
|
||||||
|
|
||||||
containerSize = prometheus.NewGaugeVec(prometheus.GaugeOpts{
|
|
||||||
Namespace: namespace,
|
|
||||||
Subsystem: engineSubsystem,
|
|
||||||
Name: "container_size",
|
|
||||||
Help: "Accumulated size of all objects in a container",
|
|
||||||
}, []string{containerIDLabelKey})
|
|
||||||
|
|
||||||
payloadSize = prometheus.NewGaugeVec(prometheus.GaugeOpts{
|
|
||||||
Namespace: namespace,
|
|
||||||
Subsystem: engineSubsystem,
|
|
||||||
Name: "payload_size",
|
|
||||||
Help: "Accumulated size of all objects in a shard",
|
|
||||||
}, []string{shardIDLabelKey})
|
|
||||||
)
|
|
||||||
|
|
||||||
return engineMetrics{
|
return engineMetrics{
|
||||||
listContainersDuration: listContainersDuration,
|
listContainersDuration: newEngineMethodDurationCounter("list_containers_"),
|
||||||
estimateContainerSizeDuration: estimateContainerSizeDuration,
|
estimateContainerSizeDuration: newEngineCounter("estimate_container_size_duration", "Accumulated duration of engine container size estimate operations"),
|
||||||
deleteDuration: deleteDuration,
|
deleteDuration: newEngineMethodDurationCounter("delete"),
|
||||||
existsDuration: existsDuration,
|
existsDuration: newEngineMethodDurationCounter("exists"),
|
||||||
getDuration: getDuration,
|
getDuration: newEngineMethodDurationCounter("get"),
|
||||||
headDuration: headDuration,
|
headDuration: newEngineMethodDurationCounter("head"),
|
||||||
inhumeDuration: inhumeDuration,
|
inhumeDuration: newEngineMethodDurationCounter("inhume"),
|
||||||
putDuration: putDuration,
|
putDuration: newEngineMethodDurationCounter("put"),
|
||||||
rangeDuration: rangeDuration,
|
rangeDuration: newEngineMethodDurationCounter("range"),
|
||||||
searchDuration: searchDuration,
|
searchDuration: newEngineMethodDurationCounter("search"),
|
||||||
listObjectsDuration: listObjectsDuration,
|
listObjectsDuration: newEngineMethodDurationCounter("list_objects"),
|
||||||
containerSize: *containerSize,
|
containerSize: *newEngineGaugeVector("container_size", "Accumulated size of all objects in a container", []string{containerIDLabelKey}),
|
||||||
payloadSize: *payloadSize,
|
payloadSize: *newEngineGaugeVector("payload_size", "Accumulated size of all objects in a shard", []string{shardIDLabelKey}),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func newEngineCounter(name, help string) prometheus.Counter {
|
||||||
|
return prometheus.NewCounter(prometheus.CounterOpts{
|
||||||
|
Namespace: namespace,
|
||||||
|
Subsystem: engineSubsystem,
|
||||||
|
Name: name,
|
||||||
|
Help: help,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
func newEngineMethodDurationCounter(method string) prometheus.Counter {
|
||||||
|
return newEngineCounter(
|
||||||
|
fmt.Sprintf("%s_duration", method),
|
||||||
|
fmt.Sprintf("Accumulated duration of engine %s operations", strings.ReplaceAll(method, "_", " ")),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
func newEngineGaugeVector(name, help string, labels []string) *prometheus.GaugeVec {
|
||||||
|
return prometheus.NewGaugeVec(prometheus.GaugeOpts{
|
||||||
|
Namespace: namespace,
|
||||||
|
Subsystem: engineSubsystem,
|
||||||
|
Name: name,
|
||||||
|
Help: help,
|
||||||
|
}, labels)
|
||||||
|
}
|
||||||
|
|
||||||
func (m engineMetrics) register() {
|
func (m engineMetrics) register() {
|
||||||
prometheus.MustRegister(m.listContainersDuration)
|
prometheus.MustRegister(m.listContainersDuration)
|
||||||
prometheus.MustRegister(m.estimateContainerSizeDuration)
|
prometheus.MustRegister(m.estimateContainerSizeDuration)
|
||||||
|
|
Loading…
Reference in a new issue