forked from TrueCloudLab/frostfs-node
[#838] shard: Refactor updateMetrics
method
Signed-off-by: Dmitrii Stepanov <d.stepanov@yadro.com>
This commit is contained in:
parent
b892feeaf6
commit
29550fe600
1 changed files with 44 additions and 42 deletions
|
@ -398,52 +398,54 @@ const (
|
||||||
)
|
)
|
||||||
|
|
||||||
func (s *Shard) updateMetrics(ctx context.Context) {
|
func (s *Shard) updateMetrics(ctx context.Context) {
|
||||||
if s.cfg.metricsWriter != nil && !s.GetMode().NoMetabase() {
|
if s.cfg.metricsWriter == nil || s.GetMode().NoMetabase() {
|
||||||
cc, err := s.metaBase.ObjectCounters()
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
cc, err := s.metaBase.ObjectCounters()
|
||||||
|
if err != nil {
|
||||||
|
s.log.Warn(logs.ShardMetaObjectCounterRead,
|
||||||
|
zap.Error(err),
|
||||||
|
)
|
||||||
|
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
s.cfg.metricsWriter.SetObjectCounter(physical, cc.Phy())
|
||||||
|
s.cfg.metricsWriter.SetObjectCounter(logical, cc.Logic())
|
||||||
|
|
||||||
|
cnrList, err := s.metaBase.Containers(ctx)
|
||||||
|
if err != nil {
|
||||||
|
s.log.Warn(logs.ShardMetaCantReadContainerList, zap.Error(err))
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
var totalPayload uint64
|
||||||
|
|
||||||
|
for i := range cnrList {
|
||||||
|
size, err := s.metaBase.ContainerSize(cnrList[i])
|
||||||
if err != nil {
|
if err != nil {
|
||||||
s.log.Warn(logs.ShardMetaObjectCounterRead,
|
s.log.Warn(logs.ShardMetaCantReadContainerSize,
|
||||||
zap.Error(err),
|
zap.String("cid", cnrList[i].EncodeToString()),
|
||||||
)
|
zap.Error(err))
|
||||||
|
continue
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
s.metricsWriter.AddToContainerSize(cnrList[i].EncodeToString(), int64(size))
|
||||||
|
totalPayload += size
|
||||||
|
}
|
||||||
|
|
||||||
s.cfg.metricsWriter.SetObjectCounter(physical, cc.Phy())
|
s.metricsWriter.AddToPayloadSize(int64(totalPayload))
|
||||||
s.cfg.metricsWriter.SetObjectCounter(logical, cc.Logic())
|
|
||||||
|
|
||||||
cnrList, err := s.metaBase.Containers(ctx)
|
contCount, err := s.metaBase.ContainerCounters(ctx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
s.log.Warn(logs.ShardMetaCantReadContainerList, zap.Error(err))
|
s.log.Warn(logs.FailedToGetContainerCounters, zap.Error(err))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
for contID, count := range contCount.Physical {
|
||||||
var totalPayload uint64
|
s.metricsWriter.SetContainerObjectsCount(contID.EncodeToString(), physical, count)
|
||||||
|
}
|
||||||
for i := range cnrList {
|
for contID, count := range contCount.Logical {
|
||||||
size, err := s.metaBase.ContainerSize(cnrList[i])
|
s.metricsWriter.SetContainerObjectsCount(contID.EncodeToString(), logical, count)
|
||||||
if err != nil {
|
|
||||||
s.log.Warn(logs.ShardMetaCantReadContainerSize,
|
|
||||||
zap.String("cid", cnrList[i].EncodeToString()),
|
|
||||||
zap.Error(err))
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
s.metricsWriter.AddToContainerSize(cnrList[i].EncodeToString(), int64(size))
|
|
||||||
totalPayload += size
|
|
||||||
}
|
|
||||||
|
|
||||||
s.metricsWriter.AddToPayloadSize(int64(totalPayload))
|
|
||||||
|
|
||||||
contCount, err := s.metaBase.ContainerCounters(ctx)
|
|
||||||
if err != nil {
|
|
||||||
s.log.Warn(logs.FailedToGetContainerCounters, zap.Error(err))
|
|
||||||
return
|
|
||||||
}
|
|
||||||
for contID, count := range contCount.Physical {
|
|
||||||
s.metricsWriter.SetContainerObjectsCount(contID.EncodeToString(), physical, count)
|
|
||||||
}
|
|
||||||
for contID, count := range contCount.Logical {
|
|
||||||
s.metricsWriter.SetContainerObjectsCount(contID.EncodeToString(), logical, count)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue