Merge pull request #11 from benzcash/ben/add-node-version-info
Added getinfo
This commit is contained in:
commit
3f2326d8bb
14
collector.go
14
collector.go
|
@ -6,6 +6,18 @@ import (
|
||||||
|
|
||||||
//Define the metrics we wish to expose
|
//Define the metrics we wish to expose
|
||||||
var (
|
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{
|
zcashdBlocks = prometheus.NewGauge(prometheus.GaugeOpts{
|
||||||
Name: "zcash_blocks", Help: "the current number of blocks processed in the server"})
|
Name: "zcash_blocks", Help: "the current number of blocks processed in the server"})
|
||||||
zcashdDifficulty = prometheus.NewGauge(prometheus.GaugeOpts{
|
zcashdDifficulty = prometheus.NewGauge(prometheus.GaugeOpts{
|
||||||
|
@ -85,6 +97,8 @@ var (
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
//Register metrics with prometheus
|
//Register metrics with prometheus
|
||||||
|
prometheus.MustRegister(zcashdBlockchainInfo)
|
||||||
|
prometheus.MustRegister(zcashdInfo)
|
||||||
prometheus.MustRegister(zcashdBlocks)
|
prometheus.MustRegister(zcashdBlocks)
|
||||||
prometheus.MustRegister(zcashdDifficulty)
|
prometheus.MustRegister(zcashdDifficulty)
|
||||||
prometheus.MustRegister(zcashdSizeOnDisk)
|
prometheus.MustRegister(zcashdSizeOnDisk)
|
||||||
|
|
26
main.go
26
main.go
|
@ -52,6 +52,7 @@ func main() {
|
||||||
</body>
|
</body>
|
||||||
</html>`))
|
</html>`))
|
||||||
})
|
})
|
||||||
|
go getInfo()
|
||||||
go getBlockchainInfo()
|
go getBlockchainInfo()
|
||||||
go getMemPoolInfo()
|
go getMemPoolInfo()
|
||||||
go getWalletInfo()
|
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() {
|
func getBlockchainInfo() {
|
||||||
basicAuth := base64.StdEncoding.EncodeToString([]byte(*rpcUser + ":" + *rpcPassword))
|
basicAuth := base64.StdEncoding.EncodeToString([]byte(*rpcUser + ":" + *rpcPassword))
|
||||||
rpcClient := jsonrpc.NewClientWithOpts("http://"+*rpcHost+":"+*rpcPort,
|
rpcClient := jsonrpc.NewClientWithOpts("http://"+*rpcHost+":"+*rpcPort,
|
||||||
|
@ -77,6 +99,10 @@ func getBlockchainInfo() {
|
||||||
if err := rpcClient.CallFor(&blockinfo, "getblockchaininfo"); err != nil {
|
if err := rpcClient.CallFor(&blockinfo, "getblockchaininfo"); err != nil {
|
||||||
log.Warnln("Error calling getblockchaininfo", err)
|
log.Warnln("Error calling getblockchaininfo", err)
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
|
zcashdBlockchainInfo.WithLabelValues(
|
||||||
|
blockinfo.Chain, strconv.Itoa(blockinfo.Blocks)).Set(1)
|
||||||
|
|
||||||
zcashdBlocks.Set(float64(blockinfo.Blocks))
|
zcashdBlocks.Set(float64(blockinfo.Blocks))
|
||||||
zcashdDifficulty.Set(blockinfo.Difficulty)
|
zcashdDifficulty.Set(blockinfo.Difficulty)
|
||||||
zcashdVerificationProgress.Set(blockinfo.VerificationProgress)
|
zcashdVerificationProgress.Set(blockinfo.VerificationProgress)
|
||||||
|
|
6
rpc.go
6
rpc.go
|
@ -10,6 +10,12 @@ type GetBlockchainInfo struct {
|
||||||
SizeOnDisk float64 `json:"size_on_disk"`
|
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`
|
// GetMemPoolInfo return the zcashd rpc `getmempoolinfo`
|
||||||
// https://zcash-rpc.github.io/getmempoolinfo.html
|
// https://zcash-rpc.github.io/getmempoolinfo.html
|
||||||
type GetMemPoolInfo struct {
|
type GetMemPoolInfo struct {
|
||||||
|
|
Loading…
Reference in New Issue