Refactor metrics #213
1 changed files with 47 additions and 115 deletions
|
@ -2,6 +2,7 @@ package metrics
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/prometheus/client_golang/prometheus"
|
"github.com/prometheus/client_golang/prometheus"
|
||||||
|
@ -46,7 +47,7 @@ const (
|
||||||
containerIDLabelKey = "cid"
|
containerIDLabelKey = "cid"
|
||||||
)
|
)
|
||||||
|
|
||||||
func newMethodCallCounter(name string) methodCount {
|
func newObjectMethodCallCounter(name string) methodCount {
|
||||||
return methodCount{
|
return methodCount{
|
||||||
success: prometheus.NewCounter(prometheus.CounterOpts{
|
success: prometheus.NewCounter(prometheus.CounterOpts{
|
||||||
Namespace: namespace,
|
Namespace: namespace,
|
||||||
|
@ -75,125 +76,56 @@ func (m methodCount) Inc(success bool) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// nolint: funlen
|
|
||||||
func newObjectServiceMetrics() objectServiceMetrics {
|
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{
|
return objectServiceMetrics{
|
||||||
fyrchik marked this conversation as resolved
Outdated
|
|||||||
getCounter: getCounter,
|
getCounter: newObjectMethodCallCounter("get"),
|
||||||
putCounter: putCounter,
|
putCounter: newObjectMethodCallCounter("put"),
|
||||||
headCounter: headCounter,
|
headCounter: newObjectMethodCallCounter("head"),
|
||||||
searchCounter: searchCounter,
|
searchCounter: newObjectMethodCallCounter("search"),
|
||||||
deleteCounter: deleteCounter,
|
deleteCounter: newObjectMethodCallCounter("delete"),
|
||||||
rangeCounter: rangeCounter,
|
rangeCounter: newObjectMethodCallCounter("range"),
|
||||||
rangeHashCounter: rangeHashCounter,
|
rangeHashCounter: newObjectMethodCallCounter("range_hash"),
|
||||||
getDuration: getDuration,
|
getDuration: newObjectMethodDurationCounter("get"),
|
||||||
putDuration: putDuration,
|
putDuration: newObjectMethodDurationCounter("put"),
|
||||||
headDuration: headDuration,
|
headDuration: newObjectMethodDurationCounter("head"),
|
||||||
searchDuration: searchDuration,
|
searchDuration: newObjectMethodDurationCounter("search"),
|
||||||
deleteDuration: deleteDuration,
|
deleteDuration: newObjectMethodDurationCounter("delete"),
|
||||||
rangeDuration: rangeDuration,
|
rangeDuration: newObjectMethodDurationCounter("range"),
|
||||||
rangeHashDuration: rangeHashDuration,
|
rangeHashDuration: newObjectMethodDurationCounter("range_hash"),
|
||||||
putPayload: putPayload,
|
putPayload: newObjectMethodPayloadCounter("put"),
|
||||||
getPayload: getPayload,
|
getPayload: newObjectMethodPayloadCounter("get"),
|
||||||
shardMetrics: shardsMetrics,
|
shardMetrics: newObjectGaugeVector("counter", "Objects counters per shards", []string{shardIDLabelKey, counterTypeLabelKey}),
|
||||||
shardsReadonly: shardsReadonly,
|
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() {
|
func (m objectServiceMetrics) register() {
|
||||||
m.getCounter.mustRegister()
|
m.getCounter.mustRegister()
|
||||||
m.putCounter.mustRegister()
|
m.putCounter.mustRegister()
|
||||||
|
|
Loading…
Add table
Reference in a new issue
We have duration for all methods, what about combining them together, inside
newMethodCallCounter
?I didn't catch the thought.
duration
andcall counter
are different metrics.Yes, but they all are generic and parametrized by method.
So, maybe not
newMethodCallCounter
, butnewMethodCallMetrics
?Done.
newMethodCallMetrics
- too general, metrics can be different.