Skip to content
This repository has been archived by the owner on Dec 11, 2019. It is now read-only.

Commit

Permalink
Merge pull request #8 from benzcash/ben/added-chaintips
Browse files Browse the repository at this point in the history
Added initial chaintip collections
  • Loading branch information
benzcash authored Dec 5, 2019
2 parents e43beec + 6f40fe7 commit ae30e9f
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 0 deletions.
8 changes: 8 additions & 0 deletions collector.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -90,4 +97,5 @@ func init() {
prometheus.MustRegister(zcashdPeerConnTime)
prometheus.MustRegister(zcashdPeerBytesSent)
prometheus.MustRegister(zcashdPeerBytesRecv)
prometheus.MustRegister(zcashdChainTips)
}
28 changes: 28 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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 changes: 11 additions & 0 deletions rpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
}

0 comments on commit ae30e9f

Please sign in to comment.