Added getinfo

Signed-off-by: Ben Wilson <ben@z.cash>
This commit is contained in:
Ben Wilson 2019-12-05 22:05:51 -05:00 committed by Ben Wilson
parent e43beec110
commit e417a94a9f
3 changed files with 46 additions and 0 deletions

View File

@ -6,6 +6,18 @@ import (
//Define the metrics we wish to expose
var (
zcashdBlockchainInfo = prometheus.NewGaugeVec(
prometheus.GaugeOpts{
Name: "zcash_network",
Help: "Current network name as defined in BIP70"},
[]string{"network", "blocks"},
)
zcashdInfo = prometheus.NewGaugeVec(
prometheus.GaugeOpts{
Name: "zcashd_info",
Help: "Node state info"},
[]string{"version"},
)
zcashdBlocks = prometheus.NewGauge(prometheus.GaugeOpts{
Name: "zcash_blocks", Help: "the current number of blocks processed in the server"})
zcashdDifficulty = prometheus.NewGauge(prometheus.GaugeOpts{
@ -78,6 +90,8 @@ var (
func init() {
//Register metrics with prometheus
prometheus.MustRegister(zcashdBlockchainInfo)
prometheus.MustRegister(zcashdInfo)
prometheus.MustRegister(zcashdBlocks)
prometheus.MustRegister(zcashdDifficulty)
prometheus.MustRegister(zcashdSizeOnDisk)

26
main.go
View File

@ -52,6 +52,7 @@ func main() {
</body>
</html>`))
})
go getInfo()
go getBlockchainInfo()
go getMemPoolInfo()
go getWalletInfo()
@ -63,6 +64,27 @@ func main() {
}
func getInfo() {
basicAuth := base64.StdEncoding.EncodeToString([]byte(*rpcUser + ":" + *rpcPassword))
rpcClient := jsonrpc.NewClientWithOpts("http://"+*rpcHost+":"+*rpcPort,
&jsonrpc.RPCClientOpts{
CustomHeaders: map[string]string{
"Authorization": "Basic " + basicAuth,
}})
var info *GetInfo
for {
if err := rpcClient.CallFor(&info, "getinfo"); err != nil {
log.Warnln("Error calling getinfo", err)
} else {
zcashdInfo.WithLabelValues(
strconv.Itoa(info.Version)).Set(1)
}
time.Sleep(time.Duration(30) * time.Second)
}
}
func getBlockchainInfo() {
basicAuth := base64.StdEncoding.EncodeToString([]byte(*rpcUser + ":" + *rpcPassword))
rpcClient := jsonrpc.NewClientWithOpts("http://"+*rpcHost+":"+*rpcPort,
@ -76,6 +98,10 @@ func getBlockchainInfo() {
if err := rpcClient.CallFor(&blockinfo, "getblockchaininfo"); err != nil {
log.Warnln("Error calling getblockchaininfo", err)
} else {
zcashdBlockchainInfo.WithLabelValues(
blockinfo.Chain, strconv.Itoa(blockinfo.Blocks)).Set(1)
zcashdBlocks.Set(float64(blockinfo.Blocks))
zcashdDifficulty.Set(blockinfo.Difficulty)
zcashdVerificationProgress.Set(blockinfo.VerificationProgress)

6
rpc.go
View File

@ -10,6 +10,12 @@ type GetBlockchainInfo struct {
SizeOnDisk float64 `json:"size_on_disk"`
}
// GetInfo Returns an object containing various state info.
// https://zcash-rpc.github.io/getinfo.html
type GetInfo struct {
Version int `json:"version"`
}
// GetMemPoolInfo return the zcashd rpc `getmempoolinfo`
// https://zcash-rpc.github.io/getmempoolinfo.html
type GetMemPoolInfo struct {