diff --git a/chain/cache.go b/chain/cache.go index a14ff2ae1..2b995491b 100644 --- a/chain/cache.go +++ b/chain/cache.go @@ -20,7 +20,7 @@ func newCache(maxSize int) *cache { func (c *cache) GetOrLoad(key interface{}, load func() (interface{}, error)) (interface{}, error) { if value, ok := c.Get(key); ok { - metricBlockReadCounter().AddWithLabel(1, map[string]string{"type": "cache"}) + metricBlockRepositoryCounter().AddWithLabel(1, map[string]string{"type": "read", "target": "cache"}) return value, nil } value, err := load() diff --git a/chain/metrics.go b/chain/metrics.go index 9b669aa43..6baa870f1 100644 --- a/chain/metrics.go +++ b/chain/metrics.go @@ -4,11 +4,8 @@ import ( "github.com/vechain/thor/v2/metrics" ) -var metricBlockWriteCounter = metrics.LazyLoadCounter("block_write_count") -var metricBlockReadCounter = metrics.LazyLoadCounterVec("block_read_count", []string{"type"}) +var metricBlockRepositoryCounter = metrics.LazyLoadCounterVec("block_repository_count", []string{"type", "target"}) -var metricTransactionWriteCounter = metrics.LazyLoadCounter("transaction_write_count") -var metricTransactionReadCounter = metrics.LazyLoadCounter("transaction_read_count") +var metricTransactionRepositoryCounter = metrics.LazyLoadCounterVec("transaction_repository_count", []string{"type"}) -var metricReceiptWriteCounter = metrics.LazyLoadCounter("receipt_write_count") -var metricReceiptReadCounter = metrics.LazyLoadCounter("receipt_read_count") \ No newline at end of file +var metricReceiptRepositoryCounter = metrics.LazyLoadCounterVec("receipt_repository_count", []string{"type"}) \ No newline at end of file diff --git a/chain/persist.go b/chain/persist.go index 9db70b2b1..dd21e01f0 100644 --- a/chain/persist.go +++ b/chain/persist.go @@ -90,6 +90,6 @@ func loadBlockSummary(r kv.Getter, id thor.Bytes32) (*BlockSummary, error) { if err := loadRLP(r, id[:], &summary); err != nil { return nil, err } - metricBlockReadCounter().AddWithLabel(1, map[string]string{"type": "disk"}) + metricBlockRepositoryCounter().AddWithLabel(1, map[string]string{"type": "read", "target": "disk"}) return &summary, nil } diff --git a/chain/repository.go b/chain/repository.go index b9dea4dda..0a7f4623f 100644 --- a/chain/repository.go +++ b/chain/repository.go @@ -171,7 +171,7 @@ func (r *Repository) saveBlock(block *block.Block, receipts tx.Receipts, conflic return nil, err } } - metricTransactionWriteCounter().Add(int64(len(txs))) + metricTransactionRepositoryCounter().AddWithLabel(int64(len(txs)), map[string]string{"type": "write"}) // save receipts for i, receipt := range receipts { @@ -180,7 +180,7 @@ func (r *Repository) saveBlock(block *block.Block, receipts tx.Receipts, conflic return nil, err } } - metricReceiptWriteCounter().Add(int64(len(receipts))) + metricReceiptRepositoryCounter().AddWithLabel(int64(len(receipts)), map[string]string{"type": "write"}) } if err := indexChainHead(headPutter, header); err != nil { return nil, err @@ -190,7 +190,7 @@ func (r *Repository) saveBlock(block *block.Block, receipts tx.Receipts, conflic if err := saveBlockSummary(hdrPutter, &summary); err != nil { return nil, err } - metricBlockWriteCounter().Add(1) + metricBlockRepositoryCounter().AddWithLabel(1, map[string]string{"type": "write", "target": "disk"}) if asBest { if err := propPutter.Put(bestBlockIDKey, id[:]); err != nil { @@ -314,7 +314,7 @@ func (r *Repository) GetBlockTransactions(id thor.Bytes32) (tx.Transactions, err return nil, err } } - metricTransactionReadCounter().Add(int64(len(txs))) + metricTransactionRepositoryCounter().AddWithLabel(int64(len(txs)), map[string]string{"type": "read"}) return txs, nil } return nil, nil @@ -358,7 +358,7 @@ func (r *Repository) GetBlockReceipts(id thor.Bytes32) (tx.Receipts, error) { return nil, err } } - metricReceiptReadCounter().Add(int64(len(receipts))) + metricReceiptRepositoryCounter().AddWithLabel(int64(len(receipts)), map[string]string{"type": "read"}) return receipts, nil } return nil, nil