-
Notifications
You must be signed in to change notification settings - Fork 141
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
export internal status for monitor and debug #373
Open
laizy
wants to merge
1
commit into
DNAProject:master
Choose a base branch
from
laizy:expvar_status
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,6 +18,5 @@ Chain/* | |
/core/*/*_test.go | ||
/core/*/*/*_test.go | ||
/config/* | ||
node | ||
nodectl | ||
cscope* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
package ChainStore | ||
|
||
import ( | ||
// . "DNA/common" | ||
"expvar" | ||
"fmt" | ||
// "time" | ||
) | ||
|
||
type storeStatus struct { | ||
CurrHeaderHeight uint32 | ||
CurrBlockHeight uint32 | ||
HeaderCache map[uint32]string | ||
BlockCache map[uint32]string | ||
HeaderIndex map[uint32]string | ||
} | ||
|
||
func expvarStore(store *ChainStore) func() interface{} { | ||
|
||
return func() interface{} { | ||
headerHeight := store.GetHeaderHeight() | ||
blockHeight := store.GetHeight() | ||
store.mu.RLock() | ||
defer store.mu.RUnlock() | ||
|
||
ss := storeStatus{ | ||
HeaderIndex: make(map[uint32]string, len(store.headerIndex)), | ||
CurrHeaderHeight: headerHeight, | ||
CurrBlockHeight: blockHeight, | ||
HeaderCache: make(map[uint32]string, len(store.headerCache)), | ||
BlockCache: make(map[uint32]string, len(store.blockCache)), | ||
} | ||
|
||
for k, hash := range store.headerIndex { | ||
ss.HeaderIndex[k] = fmt.Sprintf("%x", hash) | ||
} | ||
|
||
for k, header := range store.headerCache { | ||
ss.HeaderCache[header.Blockdata.Height] = fmt.Sprintf("%x", k) | ||
} | ||
for k, block := range store.blockCache { | ||
ss.BlockCache[block.Blockdata.Height] = fmt.Sprintf("%x", k) | ||
} | ||
|
||
return ss | ||
} | ||
|
||
} | ||
|
||
func ExportStoreStatus(store *ChainStore) { | ||
|
||
expvar.Publish("dna_store", expvar.Func(expvarStore(store))) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
package node | ||
|
||
import ( | ||
. "DNA/net/protocol" | ||
"expvar" | ||
"fmt" | ||
"time" | ||
) | ||
|
||
type PeerStatus struct { | ||
State uint32 | ||
FlightHeights []uint32 | ||
LastContact string | ||
TryTimes uint32 | ||
Addr string // The address of the node | ||
Height uint64 // The node latest block height | ||
} | ||
|
||
type TxPoolStatus struct { | ||
TxCount int | ||
} | ||
|
||
type nodeStatus struct { | ||
Id uint64 | ||
TxnCnt uint64 // The transactions be transmit by this node | ||
RxTxnCnt uint64 // The transaction received by this node | ||
PublicKey string | ||
Peers []PeerStatus | ||
Connectings []string | ||
TxPool TxPoolStatus | ||
} | ||
|
||
func expvarNodeInfo(node *node) func() interface{} { | ||
|
||
return func() interface{} { | ||
pbkey, _ := node.publicKey.EncodePoint(true) | ||
|
||
ns := nodeStatus{ | ||
Id: node.id, | ||
TxnCnt: node.txnCnt, | ||
RxTxnCnt: node.rxTxnCnt, | ||
PublicKey: fmt.Sprintf("%x", pbkey), | ||
TxPool: TxPoolStatus{TxCount: node.TXNPool.Len()}, | ||
Connectings: node.ConnectingAddrs, | ||
} | ||
|
||
node.nbrNodes.RLock() | ||
for _, n := range node.nbrNodes.List { | ||
peer := PeerStatus{ | ||
State: n.state, | ||
Height: n.height, | ||
FlightHeights: n.flightHeights, | ||
LastContact: fmt.Sprintf("%gs", float64(time.Now().Sub(n.link.time))/float64(time.Second)), | ||
TryTimes: n.tryTimes, | ||
Addr: fmt.Sprintf("%s:%d", n.link.addr, n.link.port), | ||
} | ||
|
||
ns.Peers = append(ns.Peers, peer) | ||
} | ||
node.nbrNodes.RUnlock() | ||
|
||
return ns | ||
} | ||
} | ||
|
||
func ExportNodeStatus(nd Noder) { | ||
expvar.Publish("dna_node", expvar.Func(expvarNodeInfo(nd.(*node)))) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should add lock to guard node.nbrNodes.List
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed