diff --git a/pkg/metrics/object.go b/pkg/metrics/object.go index ffa5d481..fae86cb4 100644 --- a/pkg/metrics/object.go +++ b/pkg/metrics/object.go @@ -2,6 +2,7 @@ package metrics import ( "fmt" + "strings" "time" "github.com/prometheus/client_golang/prometheus" @@ -46,7 +47,7 @@ const ( containerIDLabelKey = "cid" ) -func newMethodCallCounter(name string) methodCount { +func newObjectMethodCallCounter(name string) methodCount { return methodCount{ success: prometheus.NewCounter(prometheus.CounterOpts{ Namespace: namespace, @@ -75,125 +76,56 @@ func (m methodCount) Inc(success bool) { } } -// nolint: funlen func newObjectServiceMetrics() objectServiceMetrics { - var ( // Request counter metrics. - getCounter = newMethodCallCounter("get") - putCounter = newMethodCallCounter("put") - headCounter = newMethodCallCounter("head") - searchCounter = newMethodCallCounter("search") - deleteCounter = newMethodCallCounter("delete") - rangeCounter = newMethodCallCounter("range") - rangeHashCounter = newMethodCallCounter("range_hash") - ) - - var ( // Request duration metrics. - getDuration = prometheus.NewCounter(prometheus.CounterOpts{ - Namespace: namespace, - Subsystem: objectSubsystem, - Name: "get_req_duration", - Help: "Accumulated get request process duration", - }) - - putDuration = prometheus.NewCounter(prometheus.CounterOpts{ - Namespace: namespace, - Subsystem: objectSubsystem, - Name: "put_req_duration", - Help: "Accumulated put request process duration", - }) - - headDuration = prometheus.NewCounter(prometheus.CounterOpts{ - Namespace: namespace, - Subsystem: objectSubsystem, - Name: "head_req_duration", - Help: "Accumulated head request process duration", - }) - - searchDuration = prometheus.NewCounter(prometheus.CounterOpts{ - Namespace: namespace, - Subsystem: objectSubsystem, - Name: "search_req_duration", - Help: "Accumulated search request process duration", - }) - - deleteDuration = prometheus.NewCounter(prometheus.CounterOpts{ - Namespace: namespace, - Subsystem: objectSubsystem, - Name: "delete_req_duration", - Help: "Accumulated delete request process duration", - }) - - rangeDuration = prometheus.NewCounter(prometheus.CounterOpts{ - Namespace: namespace, - Subsystem: objectSubsystem, - Name: "range_req_duration", - Help: "Accumulated range request process duration", - }) - - rangeHashDuration = prometheus.NewCounter(prometheus.CounterOpts{ - Namespace: namespace, - Subsystem: objectSubsystem, - Name: "range_hash_req_duration", - Help: "Accumulated range hash request process duration", - }) - ) - - var ( // Object payload metrics. - putPayload = prometheus.NewCounter(prometheus.CounterOpts{ - Namespace: namespace, - Subsystem: objectSubsystem, - Name: "put_payload", - Help: "Accumulated payload size at object put method", - }) - - getPayload = prometheus.NewCounter(prometheus.CounterOpts{ - Namespace: namespace, - Subsystem: objectSubsystem, - Name: "get_payload", - Help: "Accumulated payload size at object get method", - }) - - shardsMetrics = prometheus.NewGaugeVec(prometheus.GaugeOpts{ - Namespace: namespace, - Subsystem: objectSubsystem, - Name: "counter", - Help: "Objects counters per shards", - }, - []string{shardIDLabelKey, counterTypeLabelKey}, - ) - - shardsReadonly = prometheus.NewGaugeVec(prometheus.GaugeOpts{ - Namespace: namespace, - Subsystem: objectSubsystem, - Name: "readonly", - Help: "Shard state", - }, - []string{shardIDLabelKey}, - ) - ) - return objectServiceMetrics{ - getCounter: getCounter, - putCounter: putCounter, - headCounter: headCounter, - searchCounter: searchCounter, - deleteCounter: deleteCounter, - rangeCounter: rangeCounter, - rangeHashCounter: rangeHashCounter, - getDuration: getDuration, - putDuration: putDuration, - headDuration: headDuration, - searchDuration: searchDuration, - deleteDuration: deleteDuration, - rangeDuration: rangeDuration, - rangeHashDuration: rangeHashDuration, - putPayload: putPayload, - getPayload: getPayload, - shardMetrics: shardsMetrics, - shardsReadonly: shardsReadonly, + getCounter: newObjectMethodCallCounter("get"), + putCounter: newObjectMethodCallCounter("put"), + headCounter: newObjectMethodCallCounter("head"), + searchCounter: newObjectMethodCallCounter("search"), + deleteCounter: newObjectMethodCallCounter("delete"), + rangeCounter: newObjectMethodCallCounter("range"), + rangeHashCounter: newObjectMethodCallCounter("range_hash"), + getDuration: newObjectMethodDurationCounter("get"), + putDuration: newObjectMethodDurationCounter("put"), + headDuration: newObjectMethodDurationCounter("head"), + searchDuration: newObjectMethodDurationCounter("search"), + deleteDuration: newObjectMethodDurationCounter("delete"), + rangeDuration: newObjectMethodDurationCounter("range"), + rangeHashDuration: newObjectMethodDurationCounter("range_hash"), + putPayload: newObjectMethodPayloadCounter("put"), + getPayload: newObjectMethodPayloadCounter("get"), + shardMetrics: newObjectGaugeVector("counter", "Objects counters per shards", []string{shardIDLabelKey, counterTypeLabelKey}), + shardsReadonly: newObjectGaugeVector("readonly", "Shard state", []string{shardIDLabelKey}), } } +func newObjectMethodPayloadCounter(method string) prometheus.Counter { + return prometheus.NewCounter(prometheus.CounterOpts{ + Namespace: namespace, + Subsystem: objectSubsystem, + Name: fmt.Sprintf("%s_payload", method), + Help: fmt.Sprintf("Accumulated payload size at object %s method", strings.ReplaceAll(method, "_", " ")), + }) +} + +func newObjectMethodDurationCounter(method string) prometheus.Counter { + return prometheus.NewCounter(prometheus.CounterOpts{ + Namespace: namespace, + Subsystem: objectSubsystem, + Name: fmt.Sprintf("%s_req_duration", method), + Help: fmt.Sprintf("Accumulated %s request process duration", strings.ReplaceAll(method, "_", " ")), + }) +} + +func newObjectGaugeVector(name, help string, labels []string) *prometheus.GaugeVec { + return prometheus.NewGaugeVec(prometheus.GaugeOpts{ + Namespace: namespace, + Subsystem: objectSubsystem, + Name: name, + Help: help, + }, labels) +} + func (m objectServiceMetrics) register() { m.getCounter.mustRegister() m.putCounter.mustRegister()