Merge pull request #8 from benzcash/ben/added-chaintips
Added initial chaintip collections
This commit is contained in:
commit
ae30e9f112
|
@ -52,6 +52,13 @@ var (
|
|||
Help: "Bytes received from peer node."},
|
||||
[]string{"addr", "addrlocal", "inbound", "banscore", "subver"},
|
||||
)
|
||||
zcashdChainTips = prometheus.NewGaugeVec(
|
||||
prometheus.GaugeOpts{
|
||||
Name: "zcash_chainips_at_height",
|
||||
Help: "Information about all known tips in the block tree.",
|
||||
},
|
||||
[]string{"hash", "branchlen", "status"},
|
||||
)
|
||||
)
|
||||
|
||||
// ZCASH_PEERS = Gauge("zcash_peers", "Number of peers")
|
||||
|
@ -90,4 +97,5 @@ func init() {
|
|||
prometheus.MustRegister(zcashdPeerConnTime)
|
||||
prometheus.MustRegister(zcashdPeerBytesSent)
|
||||
prometheus.MustRegister(zcashdPeerBytesRecv)
|
||||
prometheus.MustRegister(zcashdChainTips)
|
||||
}
|
||||
|
|
28
main.go
28
main.go
|
@ -56,6 +56,7 @@ func main() {
|
|||
go getMemPoolInfo()
|
||||
go getWalletInfo()
|
||||
go getPeerInfo()
|
||||
go getChainTips()
|
||||
log.Infoln("Listening on", *listenAddress)
|
||||
if err := http.ListenAndServe(*listenAddress, nil); err != nil {
|
||||
log.Fatal(err)
|
||||
|
@ -205,3 +206,30 @@ func getPeerInfo() {
|
|||
}
|
||||
|
||||
}
|
||||
|
||||
func getChainTips() {
|
||||
basicAuth := base64.StdEncoding.EncodeToString([]byte(*rpcUser + ":" + *rpcPassword))
|
||||
rpcClient := jsonrpc.NewClientWithOpts("http://"+*rpcHost+":"+*rpcPort,
|
||||
&jsonrpc.RPCClientOpts{
|
||||
CustomHeaders: map[string]string{
|
||||
"Authorization": "Basic " + basicAuth,
|
||||
}})
|
||||
var chaintips *GetChainTips
|
||||
|
||||
for {
|
||||
if err := rpcClient.CallFor(&chaintips, "getchaintips"); err != nil {
|
||||
log.Warnln("Error calling getchaintips", err)
|
||||
} else {
|
||||
for _, ct := range *chaintips {
|
||||
log.Infoln("Got chaintip: ", ct.Hash)
|
||||
zcashdChainTips.WithLabelValues(
|
||||
ct.Hash,
|
||||
strconv.Itoa(ct.Branchlen),
|
||||
ct.Status,
|
||||
).Set(float64(ct.Height))
|
||||
}
|
||||
}
|
||||
time.Sleep(time.Duration(30) * time.Second)
|
||||
}
|
||||
|
||||
}
|
||||
|
|
11
rpc.go
11
rpc.go
|
@ -51,3 +51,14 @@ type PeerInfo struct {
|
|||
SyncedHeaders int `json:"synced_headers"`
|
||||
SyncedBlocks int `json:"synced_blocks"`
|
||||
}
|
||||
|
||||
// GetChainTips Return information about all known tips in the block tree
|
||||
// https://zcash-rpc.github.io/getchaintips.html
|
||||
type GetChainTips []ChainTip
|
||||
|
||||
type ChainTip struct {
|
||||
Height int `json:"height"`
|
||||
Hash string `json:"hash"`
|
||||
Branchlen int `json:"branchlen"`
|
||||
Status string `json:"status"`
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue