forked from TrueCloudLab/frostfs-node
[#424] metrics: Drop embedded metrics
It was not obvious where metrics are used. Signed-off-by: Dmitrii Stepanov <d.stepanov@yadro.com>
This commit is contained in:
parent
1b364d8cf4
commit
c348ae35b0
10 changed files with 173 additions and 285 deletions
|
@ -7,23 +7,40 @@ import (
|
|||
"github.com/prometheus/client_golang/prometheus"
|
||||
)
|
||||
|
||||
type (
|
||||
engineMetrics struct {
|
||||
methodDuration *prometheus.HistogramVec
|
||||
type EngineMetrics interface {
|
||||
AddMethodDuration(method string, d time.Duration)
|
||||
AddToContainerSize(cnrID string, size int64)
|
||||
IncErrorCounter(shardID string)
|
||||
ClearErrorCounter(shardID string)
|
||||
DeleteShardMetrics(shardID string)
|
||||
AddToObjectCounter(shardID, objectType string, delta int)
|
||||
SetObjectCounter(shardID, objectType string, v uint64)
|
||||
AddToPayloadCounter(shardID string, size int64)
|
||||
SetReadonly(shardID string, readonly bool)
|
||||
|
||||
containerSize *prometheus.GaugeVec
|
||||
payloadSize *prometheus.GaugeVec
|
||||
errorCounter *prometheus.GaugeVec
|
||||
}
|
||||
)
|
||||
WriteCache() WriteCacheMetrics
|
||||
GC() GCMetrics
|
||||
}
|
||||
|
||||
type engineMetrics struct {
|
||||
methodDuration *prometheus.HistogramVec
|
||||
objectCounter *prometheus.GaugeVec
|
||||
containerSize *prometheus.GaugeVec
|
||||
payloadSize *prometheus.GaugeVec
|
||||
errorCounter *prometheus.GaugeVec
|
||||
shardsReadonly *prometheus.GaugeVec
|
||||
|
||||
gc *gcMetrics
|
||||
writeCache *writeCacheMetrics
|
||||
}
|
||||
|
||||
const (
|
||||
engineSubsystem = "engine"
|
||||
engineMethod = "method"
|
||||
)
|
||||
|
||||
func newEngineMetrics() engineMetrics {
|
||||
return engineMetrics{
|
||||
func newEngineMetrics() *engineMetrics {
|
||||
return &engineMetrics{
|
||||
containerSize: newEngineGaugeVector("container_size_bytes", "Accumulated size of all objects in a container", []string{containerIDLabelKey}),
|
||||
payloadSize: newEngineGaugeVector("payload_size_bytes", "Accumulated size of all objects in a shard", []string{shardIDLabelKey}),
|
||||
errorCounter: newEngineGaugeVector("error_counter", "Shard's error counter", []string{shardIDLabelKey}),
|
||||
|
@ -33,6 +50,10 @@ func newEngineMetrics() engineMetrics {
|
|||
Name: "request_duration_seconds",
|
||||
Help: "Duration of Engine requests",
|
||||
}, []string{engineMethod}),
|
||||
objectCounter: newEngineGaugeVector("object_counter", "Objects counters per shards", []string{shardIDLabelKey, counterTypeLabelKey}),
|
||||
shardsReadonly: newEngineGaugeVector("mode", "Shard mode", []string{shardIDLabelKey}),
|
||||
gc: newGCMetrics(),
|
||||
writeCache: newWriteCacheMetrics(),
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -51,23 +72,63 @@ func (m *engineMetrics) AddMethodDuration(method string, d time.Duration) {
|
|||
}).Observe(d.Seconds())
|
||||
}
|
||||
|
||||
func (m engineMetrics) AddToContainerSize(cnrID string, size int64) {
|
||||
func (m *engineMetrics) AddToContainerSize(cnrID string, size int64) {
|
||||
m.containerSize.With(prometheus.Labels{containerIDLabelKey: cnrID}).Add(float64(size))
|
||||
}
|
||||
|
||||
func (m engineMetrics) AddToPayloadCounter(shardID string, size int64) {
|
||||
func (m *engineMetrics) AddToPayloadCounter(shardID string, size int64) {
|
||||
m.payloadSize.With(prometheus.Labels{shardIDLabelKey: shardID}).Add(float64(size))
|
||||
}
|
||||
|
||||
func (m engineMetrics) IncErrorCounter(shardID string) {
|
||||
func (m *engineMetrics) IncErrorCounter(shardID string) {
|
||||
m.errorCounter.With(prometheus.Labels{shardIDLabelKey: shardID}).Inc()
|
||||
}
|
||||
|
||||
func (m engineMetrics) ClearErrorCounter(shardID string) {
|
||||
func (m *engineMetrics) ClearErrorCounter(shardID string) {
|
||||
m.errorCounter.With(prometheus.Labels{shardIDLabelKey: shardID}).Set(0)
|
||||
}
|
||||
|
||||
func (m engineMetrics) DeleteShardMetrics(shardID string) {
|
||||
func (m *engineMetrics) DeleteShardMetrics(shardID string) {
|
||||
m.errorCounter.Delete(prometheus.Labels{shardIDLabelKey: shardID})
|
||||
m.payloadSize.Delete(prometheus.Labels{shardIDLabelKey: shardID})
|
||||
m.objectCounter.DeletePartialMatch(prometheus.Labels{shardIDLabelKey: shardID})
|
||||
m.shardsReadonly.Delete(prometheus.Labels{shardIDLabelKey: shardID})
|
||||
}
|
||||
|
||||
func (m *engineMetrics) AddToObjectCounter(shardID, objectType string, delta int) {
|
||||
m.objectCounter.With(
|
||||
prometheus.Labels{
|
||||
shardIDLabelKey: shardID,
|
||||
counterTypeLabelKey: objectType,
|
||||
},
|
||||
).Add(float64(delta))
|
||||
}
|
||||
|
||||
func (m *engineMetrics) SetObjectCounter(shardID, objectType string, v uint64) {
|
||||
m.objectCounter.With(
|
||||
prometheus.Labels{
|
||||
shardIDLabelKey: shardID,
|
||||
counterTypeLabelKey: objectType,
|
||||
},
|
||||
).Set(float64(v))
|
||||
}
|
||||
|
||||
func (m *engineMetrics) SetReadonly(shardID string, readonly bool) {
|
||||
var flag float64
|
||||
if readonly {
|
||||
flag = 1
|
||||
}
|
||||
m.shardsReadonly.With(
|
||||
prometheus.Labels{
|
||||
shardIDLabelKey: shardID,
|
||||
},
|
||||
).Set(flag)
|
||||
}
|
||||
|
||||
func (m *engineMetrics) WriteCache() WriteCacheMetrics {
|
||||
return m.writeCache
|
||||
}
|
||||
|
||||
func (m *engineMetrics) GC() GCMetrics {
|
||||
return m.gc
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue