diff --git a/core/chain_manager.go b/core/chain_manager.go index b87f65893f..3b9b7517be 100644 --- a/core/chain_manager.go +++ b/core/chain_manager.go @@ -13,7 +13,6 @@ import ( "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/core/state" "github.com/ethereum/go-ethereum/core/types" - "github.com/ethereum/go-ethereum/ethdb" "github.com/ethereum/go-ethereum/event" "github.com/ethereum/go-ethereum/logger" "github.com/ethereum/go-ethereum/logger/glog" @@ -31,10 +30,6 @@ var ( blockNumPre = []byte("block-num-") blockInsertTimer = metrics.GetOrRegisterTimer("core/BlockInsertions", metrics.DefaultRegistry) - blockdbGetMeter = metrics.GetOrRegisterMeter("core/blockdb/Gets", metrics.DefaultRegistry) - blockdbPutMeter = metrics.GetOrRegisterMeter("core/blockdb/Puts", metrics.DefaultRegistry) - statedbGetMeter = metrics.GetOrRegisterMeter("core/statedb/Gets", metrics.DefaultRegistry) - statedbPutMeter = metrics.GetOrRegisterMeter("core/statedb/Puts", metrics.DefaultRegistry) ) const ( @@ -126,15 +121,6 @@ func NewChainManager(genesis *types.Block, blockDb, stateDb common.Database, pow cache: NewBlockCache(blockCacheLimit), pow: pow, } - // Instrument the block and state databases - if db, ok := blockDb.(*ethdb.LDBDatabase); ok { - db.GetMeter = blockdbGetMeter - db.PutMeter = blockdbPutMeter - } - if db, ok := stateDb.(*ethdb.LDBDatabase); ok { - db.GetMeter = statedbGetMeter - db.PutMeter = statedbPutMeter - } // Check the genesis block given to the chain manager. If the genesis block mismatches block number 0 // throw an error. If no block or the same block's found continue. if g := bc.GetBlockByNumber(0); g != nil && g.Hash() != genesis.Hash() { diff --git a/eth/backend.go b/eth/backend.go index 37fe66abfa..5969c238c6 100644 --- a/eth/backend.go +++ b/eth/backend.go @@ -29,6 +29,7 @@ import ( "github.com/ethereum/go-ethereum/p2p/discover" "github.com/ethereum/go-ethereum/p2p/nat" "github.com/ethereum/go-ethereum/whisper" + "github.com/rcrowley/go-metrics" ) const ( @@ -248,14 +249,32 @@ func New(config *Config) (*Ethereum, error) { if err != nil { return nil, fmt.Errorf("blockchain db err: %v", err) } + blockDb.(*ethdb.LDBDatabase).GetMeter = metrics.GetOrRegisterMeter("eth/db/block/Gets", metrics.DefaultRegistry) + blockDb.(*ethdb.LDBDatabase).PutMeter = metrics.GetOrRegisterMeter("eth/db/block/Puts", metrics.DefaultRegistry) + blockDb.(*ethdb.LDBDatabase).DelMeter = metrics.GetOrRegisterMeter("eth/db/block/Dels", metrics.DefaultRegistry) + blockDb.(*ethdb.LDBDatabase).ReadMeter = metrics.GetOrRegisterMeter("eth/db/block/Reads", metrics.DefaultRegistry) + blockDb.(*ethdb.LDBDatabase).WriteMeter = metrics.GetOrRegisterMeter("eth/db/block/Writes", metrics.DefaultRegistry) + stateDb, err := newdb(filepath.Join(config.DataDir, "state")) if err != nil { return nil, fmt.Errorf("state db err: %v", err) } + stateDb.(*ethdb.LDBDatabase).GetMeter = metrics.GetOrRegisterMeter("eth/db/state/Gets", metrics.DefaultRegistry) + stateDb.(*ethdb.LDBDatabase).PutMeter = metrics.GetOrRegisterMeter("eth/db/state/Puts", metrics.DefaultRegistry) + stateDb.(*ethdb.LDBDatabase).DelMeter = metrics.GetOrRegisterMeter("eth/db/state/Dels", metrics.DefaultRegistry) + stateDb.(*ethdb.LDBDatabase).ReadMeter = metrics.GetOrRegisterMeter("eth/db/state/Reads", metrics.DefaultRegistry) + stateDb.(*ethdb.LDBDatabase).WriteMeter = metrics.GetOrRegisterMeter("eth/db/state/Writes", metrics.DefaultRegistry) + extraDb, err := newdb(filepath.Join(config.DataDir, "extra")) if err != nil { return nil, fmt.Errorf("extra db err: %v", err) } + extraDb.(*ethdb.LDBDatabase).GetMeter = metrics.GetOrRegisterMeter("eth/db/extra/Gets", metrics.DefaultRegistry) + extraDb.(*ethdb.LDBDatabase).PutMeter = metrics.GetOrRegisterMeter("eth/db/extra/Puts", metrics.DefaultRegistry) + extraDb.(*ethdb.LDBDatabase).DelMeter = metrics.GetOrRegisterMeter("eth/db/extra/Dels", metrics.DefaultRegistry) + extraDb.(*ethdb.LDBDatabase).ReadMeter = metrics.GetOrRegisterMeter("eth/db/extra/Reads", metrics.DefaultRegistry) + extraDb.(*ethdb.LDBDatabase).WriteMeter = metrics.GetOrRegisterMeter("eth/db/extra/Writes", metrics.DefaultRegistry) + nodeDb := filepath.Join(config.DataDir, "nodes") // Perform database sanity checks diff --git a/eth/fetcher/fetcher.go b/eth/fetcher/fetcher.go index 13c65121b5..07a32b9f1c 100644 --- a/eth/fetcher/fetcher.go +++ b/eth/fetcher/fetcher.go @@ -126,11 +126,11 @@ func New(getBlock blockRetrievalFn, validateBlock blockValidatorFn, broadcastBlo chainHeight: chainHeight, insertChain: insertChain, dropPeer: dropPeer, - announceMeter: metrics.GetOrRegisterMeter("eth/RemoteAnnounces", metrics.DefaultRegistry), - announceTimer: metrics.GetOrRegisterTimer("eth/LocalAnnounces", metrics.DefaultRegistry), - broadcastMeter: metrics.GetOrRegisterMeter("eth/RemoteBroadcasts", metrics.DefaultRegistry), - broadcastTimer: metrics.GetOrRegisterTimer("eth/LocalBroadcasts", metrics.DefaultRegistry), - discardMeter: metrics.GetOrRegisterMeter("eth/DiscardedBlocks", metrics.DefaultRegistry), + announceMeter: metrics.GetOrRegisterMeter("eth/sync/RemoteAnnounces", metrics.DefaultRegistry), + announceTimer: metrics.GetOrRegisterTimer("eth/sync/LocalAnnounces", metrics.DefaultRegistry), + broadcastMeter: metrics.GetOrRegisterMeter("eth/sync/RemoteBroadcasts", metrics.DefaultRegistry), + broadcastTimer: metrics.GetOrRegisterTimer("eth/sync/LocalBroadcasts", metrics.DefaultRegistry), + discardMeter: metrics.GetOrRegisterMeter("eth/sync/DiscardedBlocks", metrics.DefaultRegistry), } } diff --git a/ethdb/database.go b/ethdb/database.go index 48cb37f7c5..13b4ef449a 100644 --- a/ethdb/database.go +++ b/ethdb/database.go @@ -17,8 +17,11 @@ type LDBDatabase struct { fn string // filename for reporting db *leveldb.DB // LevelDB instance - GetMeter metrics.Meter // Meter for measuring the database get requests - PutMeter metrics.Meter // Meter for measuring the database put requests + GetMeter metrics.Meter // Meter for measuring the database get request counts + PutMeter metrics.Meter // Meter for measuring the database put request counts + DelMeter metrics.Meter // Meter for measuring the database delete request counts + ReadMeter metrics.Meter // Meter for measuring the database get request data usage + WriteMeter metrics.Meter // Meter for measuring the database put request data usage } // NewLDBDatabase returns a LevelDB wrapped object. LDBDatabase does not persist data by @@ -47,7 +50,10 @@ func NewLDBDatabase(file string) (*LDBDatabase, error) { func (self *LDBDatabase) Put(key []byte, value []byte) error { dat := rle.Compress(value) if self.PutMeter != nil { - self.PutMeter.Mark(int64(len(dat))) + self.PutMeter.Mark(1) + } + if self.WriteMeter != nil { + self.WriteMeter.Mark(int64(len(dat))) } return self.db.Put(key, dat, nil) } @@ -59,13 +65,19 @@ func (self *LDBDatabase) Get(key []byte) ([]byte, error) { return nil, err } if self.GetMeter != nil { - self.GetMeter.Mark(int64(len(dat))) + self.GetMeter.Mark(1) + } + if self.ReadMeter != nil { + self.ReadMeter.Mark(int64(len(dat))) } return rle.Decompress(dat) } // Delete deletes the key from the queue and database func (self *LDBDatabase) Delete(key []byte) error { + if self.DelMeter != nil { + self.DelMeter.Mark(1) + } return self.db.Delete(key, nil) }