diff --git a/collector.go b/collector.go index f43a2bb..5e895a7 100644 --- a/collector.go +++ b/collector.go @@ -6,6 +6,18 @@ import ( //Define the metrics we wish to expose var ( + zcashdBlockchainInfo = prometheus.NewGaugeVec( + prometheus.GaugeOpts{ + Name: "zcash_blockchain_info", + Help: "Information about the current state of the block chain"}, + []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{ @@ -85,6 +97,8 @@ var ( func init() { //Register metrics with prometheus + prometheus.MustRegister(zcashdBlockchainInfo) + prometheus.MustRegister(zcashdInfo) prometheus.MustRegister(zcashdBlocks) prometheus.MustRegister(zcashdDifficulty) prometheus.MustRegister(zcashdSizeOnDisk) diff --git a/main.go b/main.go index ff3d5c8..8d9ddf7 100644 --- a/main.go +++ b/main.go @@ -52,6 +52,7 @@ func main() { `)) }) + go getInfo() go getBlockchainInfo() go getMemPoolInfo() go getWalletInfo() @@ -64,6 +65,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, @@ -77,6 +99,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) diff --git a/rpc.go b/rpc.go index 4269cbe..5055907 100644 --- a/rpc.go +++ b/rpc.go @@ -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 {