forked from TrueCloudLab/frostfs-node
[#602] metrics: Add blobovnicza items counter
Signed-off-by: Dmitrii Stepanov <d.stepanov@yadro.com>
This commit is contained in:
parent
c4e1d8eb07
commit
f2811f8585
8 changed files with 70 additions and 18 deletions
|
@ -68,8 +68,10 @@ func (b *Blobovnicza) Init() error {
|
|||
zap.Uint64("storage size limit", b.fullSizeLimit),
|
||||
)
|
||||
|
||||
if size := b.dataSize.Load(); size != 0 {
|
||||
b.log.Debug(logs.BlobovniczaAlreadyInitialized, zap.Uint64("size", size))
|
||||
size := b.dataSize.Load()
|
||||
items := b.itemsCount.Load()
|
||||
if size != 0 || items != 0 {
|
||||
b.log.Debug(logs.BlobovniczaAlreadyInitialized, zap.Uint64("size", size), zap.Uint64("items", items))
|
||||
return nil
|
||||
}
|
||||
|
||||
|
@ -96,14 +98,17 @@ func (b *Blobovnicza) Init() error {
|
|||
}
|
||||
}
|
||||
|
||||
return b.initializeSize()
|
||||
return b.initializeCounters()
|
||||
}
|
||||
|
||||
func (b *Blobovnicza) initializeSize() error {
|
||||
func (b *Blobovnicza) initializeCounters() error {
|
||||
var size uint64
|
||||
var items uint64
|
||||
err := b.boltDB.View(func(tx *bbolt.Tx) error {
|
||||
return b.iterateAllBuckets(tx, func(lower, upper uint64, b *bbolt.Bucket) (bool, error) {
|
||||
size += uint64(b.Stats().KeyN) * upper
|
||||
keysN := uint64(b.Stats().KeyN)
|
||||
size += keysN * upper
|
||||
items += keysN
|
||||
return false, nil
|
||||
})
|
||||
})
|
||||
|
@ -111,7 +116,9 @@ func (b *Blobovnicza) initializeSize() error {
|
|||
return fmt.Errorf("can't determine DB size: %w", err)
|
||||
}
|
||||
b.dataSize.Store(size)
|
||||
b.itemsCount.Store(items)
|
||||
b.metrics.AddOpenBlobovniczaSize(size)
|
||||
b.metrics.AddOpenBlobovniczaItems(items)
|
||||
return nil
|
||||
}
|
||||
|
||||
|
@ -136,7 +143,9 @@ func (b *Blobovnicza) Close() error {
|
|||
|
||||
b.metrics.DecOpenBlobovniczaCount()
|
||||
b.metrics.SubOpenBlobovniczaSize(b.dataSize.Load())
|
||||
b.metrics.SubOpenBlobovniczaItems(b.itemsCount.Load())
|
||||
b.dataSize.Store(0)
|
||||
b.itemsCount.Store(0)
|
||||
|
||||
b.opened = false
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue