feat(monitor):add monitor point

This commit is contained in:
jiangzhe 2020-05-21 19:08:53 +08:00
parent 4fc2202c7d
commit 1e47675fd1
6 changed files with 74 additions and 4 deletions

View File

@ -5,6 +5,7 @@ import (
"fmt"
"net"
grpc_prometheus "github.com/grpc-ecosystem/go-grpc-prometheus"
"github.com/meshplus/bitxhub-model/pb"
"github.com/meshplus/bitxhub/internal/coreapi/api"
"github.com/meshplus/bitxhub/internal/loggers"
@ -25,12 +26,15 @@ type ChainBrokerService struct {
func NewChainBrokerService(api api.CoreAPI, config *repo.Config) (*ChainBrokerService, error) {
ctx, cancel := context.WithCancel(context.Background())
server := grpc.NewServer(
grpc.StreamInterceptor(grpc_prometheus.StreamServerInterceptor),
grpc.UnaryInterceptor(grpc_prometheus.UnaryServerInterceptor),
grpc.MaxConcurrentStreams(1000))
return &ChainBrokerService{
logger: loggers.Logger(loggers.API),
config: config,
api: api,
server: grpc.NewServer(grpc.MaxConcurrentStreams(1000)),
server: server,
ctx: ctx,
cancel: cancel,
}, nil

1
go.mod
View File

@ -14,6 +14,7 @@ require (
github.com/gobuffalo/packr v1.30.1
github.com/gogo/protobuf v1.3.1
github.com/golang/mock v1.4.3
github.com/grpc-ecosystem/go-grpc-prometheus v1.2.0
github.com/grpc-ecosystem/grpc-gateway v1.13.0
github.com/hokaccha/go-prettyjson v0.0.0-20190818114111-108c894c2c0e
github.com/libp2p/go-libp2p-core v0.3.0

View File

@ -47,6 +47,7 @@ func (exec *BlockExecutor) fetchPendingExecuteEvent(num uint64) *pb.Block {
}
func (exec *BlockExecutor) processExecuteEvent(block *pb.Block) {
current := time.Now()
exec.logger.WithFields(logrus.Fields{
"height": block.BlockHeader.Number,
"count": len(block.Transactions),
@ -80,7 +81,8 @@ func (exec *BlockExecutor) processExecuteEvent(block *pb.Block) {
"receipt_root": block.BlockHeader.ReceiptRoot.ShortString(),
"state_root": block.BlockHeader.StateRoot.ShortString(),
}).Debug("block meta")
calcBlockSize.Observe(float64(block.Size()))
executeBlockDuration.Observe(float64(time.Since(current)) / float64(time.Second))
exec.postBlockEvent(block)
exec.clear()
@ -189,6 +191,7 @@ func (exec *BlockExecutor) applyTransactions(txs []*pb.Transaction) []*pb.Receip
receipts = append(receipts, receipt)
}
applyTxsDuration.Observe(float64(time.Since(current)) / float64(time.Second))
exec.logger.WithFields(logrus.Fields{
"time": time.Since(current),
"count": len(txs),
@ -316,6 +319,6 @@ func (exec *BlockExecutor) calcMerkleRoots(txs []*pb.Transaction, receipts []*pb
}
exec.logger.WithField("time", time.Since(current)).Debug("calculate merkle roots")
calcMerkleDuration.Observe(float64(time.Since(current)) / float64(time.Second))
return root, receiptRoot, nil
}

View File

@ -0,0 +1,41 @@
package executor
import "github.com/prometheus/client_golang/prometheus"
var (
applyTxsDuration = prometheus.NewHistogram(prometheus.HistogramOpts{
Namespace: "bitxhub",
Subsystem: "executor",
Name: "apply_transactions_duration_seconds",
Help: "The total latency of transactions apply",
Buckets: prometheus.ExponentialBuckets(0.001, 2, 14),
})
executeBlockDuration = prometheus.NewHistogram(prometheus.HistogramOpts{
Namespace: "bitxhub",
Subsystem: "executor",
Name: "execute_block_duration_second",
Help: "The total latency of block execute",
Buckets: prometheus.ExponentialBuckets(0.001, 2, 10),
})
calcMerkleDuration = prometheus.NewHistogram(prometheus.HistogramOpts{
Namespace: "bitxhub",
Subsystem: "executor",
Name: "calc_merkle_duration_seconds",
Help: "The total latency of merkle calc",
Buckets: prometheus.ExponentialBuckets(0.001, 2, 10),
})
calcBlockSize = prometheus.NewHistogram(prometheus.HistogramOpts{
Namespace: "bitxhub",
Subsystem: "executor",
Name: "calc_block_size",
Help: "The size of current block calc",
Buckets: prometheus.ExponentialBuckets(1024, 2, 12),
})
)
func init() {
prometheus.MustRegister(applyTxsDuration)
prometheus.MustRegister(calcMerkleDuration)
prometheus.MustRegister(calcBlockSize)
prometheus.MustRegister(executeBlockDuration)
}

View File

@ -3,6 +3,7 @@ package ledger
import (
"fmt"
"sync"
"time"
"github.com/meshplus/bitxhub-kit/types"
"github.com/meshplus/bitxhub-model/pb"
@ -92,6 +93,7 @@ func New(repoRoot string, blockchainStore storage.Storage, logger logrus.FieldLo
// PersistBlockData persists block data
func (l *ChainLedger) PersistBlockData(blockData *BlockData) {
current := time.Now()
block := blockData.Block
receipts := blockData.Receipts
accounts := blockData.Accounts
@ -110,6 +112,8 @@ func (l *ChainLedger) PersistBlockData(blockData *BlockData) {
"hash": block.BlockHash.ShortString(),
"count": len(block.Transactions),
}).Info("Persist block")
PersistBlockDuration.Observe(float64(time.Since(current)) / float64(time.Second))
}
// Rollback rollback ledger to history version

View File

@ -0,0 +1,17 @@
package ledger
import "github.com/prometheus/client_golang/prometheus"
var (
PersistBlockDuration = prometheus.NewHistogram(prometheus.HistogramOpts{
Namespace: "bitxhub",
Subsystem: "ledger",
Name: "persist_block_duration_second",
Help: "The total latency of block persist",
Buckets: prometheus.ExponentialBuckets(0.001, 2, 10),
})
)
func init() {
prometheus.MustRegister(PersistBlockDuration)
}