Merge pull request #6 from benzcash/ben/add-peer-info
Added a few metrics for getpeerinfo
This commit is contained in:
commit
a872090498
29
collector.go
29
collector.go
|
@ -27,6 +27,31 @@ var (
|
|||
[]string{
|
||||
"type",
|
||||
})
|
||||
// []string{"id", "addr", "addrlocal", "services", "lastsend", "lastrecv", "bytessent", "bytesrecv", "conntime", "timeoffset", "pingtime", "pingwait", "version", "subver", "inbound", "startingheight", "banscore", "synced_headers", "synced_blocks"},
|
||||
zcashdPeerVerion = prometheus.NewGaugeVec(
|
||||
prometheus.GaugeOpts{
|
||||
Name: "zcash_peer_version",
|
||||
Help: "Peer node version."},
|
||||
[]string{"addr", "addrlocal", "inbound", "banscore", "subver"},
|
||||
)
|
||||
zcashdPeerConnTime = prometheus.NewGaugeVec(
|
||||
prometheus.GaugeOpts{
|
||||
Name: "zcash_peer_conn_time",
|
||||
Help: "Peer node connection time."},
|
||||
[]string{"addr", "addrlocal", "inbound", "banscore", "subver"},
|
||||
)
|
||||
zcashdPeerBytesSent = prometheus.NewGaugeVec(
|
||||
prometheus.GaugeOpts{
|
||||
Name: "zcash_peer_bytes_sent",
|
||||
Help: "Bytes sent to peer node."},
|
||||
[]string{"addr", "addrlocal", "inbound", "banscore", "subver"},
|
||||
)
|
||||
zcashdPeerBytesRecv = prometheus.NewGaugeVec(
|
||||
prometheus.GaugeOpts{
|
||||
Name: "zcash_peer_bytes_recv",
|
||||
Help: "Bytes received from peer node."},
|
||||
[]string{"addr", "addrlocal", "inbound", "banscore", "subver"},
|
||||
)
|
||||
)
|
||||
|
||||
// ZCASH_PEERS = Gauge("zcash_peers", "Number of peers")
|
||||
|
@ -61,4 +86,8 @@ func init() {
|
|||
prometheus.MustRegister(zcashdMemPoolBytes)
|
||||
prometheus.MustRegister(zcashdMemPoolUsage)
|
||||
prometheus.MustRegister(zcashdWalletBalance)
|
||||
prometheus.MustRegister(zcashdPeerVerion)
|
||||
prometheus.MustRegister(zcashdPeerConnTime)
|
||||
prometheus.MustRegister(zcashdPeerBytesSent)
|
||||
prometheus.MustRegister(zcashdPeerBytesRecv)
|
||||
}
|
||||
|
|
72
main.go
72
main.go
|
@ -55,6 +55,7 @@ func main() {
|
|||
go getBlockchainInfo()
|
||||
go getMemPoolInfo()
|
||||
go getWalletInfo()
|
||||
go getPeerInfo()
|
||||
log.Infoln("Listening on", *listenAddress)
|
||||
if err := http.ListenAndServe(*listenAddress, nil); err != nil {
|
||||
log.Fatal(err)
|
||||
|
@ -133,3 +134,74 @@ func getWalletInfo() {
|
|||
}
|
||||
|
||||
}
|
||||
|
||||
func getPeerInfo() {
|
||||
basicAuth := base64.StdEncoding.EncodeToString([]byte(*rpcUser + ":" + *rpcPassword))
|
||||
rpcClient := jsonrpc.NewClientWithOpts("http://"+*rpcHost+":"+*rpcPort,
|
||||
&jsonrpc.RPCClientOpts{
|
||||
CustomHeaders: map[string]string{
|
||||
"Authorization": "Basic " + basicAuth,
|
||||
}})
|
||||
var peerinfo *GetPeerInfo
|
||||
|
||||
for {
|
||||
if err := rpcClient.CallFor(&peerinfo, "getpeerinfo"); err != nil {
|
||||
log.Warnln("Error calling getchaintips", err)
|
||||
} else {
|
||||
for _, pi := range *peerinfo {
|
||||
log.Infoln("Got peerinfo: ", pi.Addr)
|
||||
zcashdPeerVerion.WithLabelValues(
|
||||
pi.Addr,
|
||||
pi.AddrLocal,
|
||||
strconv.FormatBool(pi.Inbound),
|
||||
strconv.Itoa(pi.Banscore),
|
||||
pi.Subver,
|
||||
).Set(float64(pi.Version))
|
||||
zcashdPeerConnTime.WithLabelValues(
|
||||
pi.Addr,
|
||||
pi.AddrLocal,
|
||||
strconv.FormatBool(pi.Inbound),
|
||||
strconv.Itoa(pi.Banscore),
|
||||
pi.Subver,
|
||||
).Set(float64(pi.Conntime))
|
||||
zcashdPeerBytesSent.WithLabelValues(
|
||||
pi.Addr,
|
||||
pi.AddrLocal,
|
||||
strconv.FormatBool(pi.Inbound),
|
||||
strconv.Itoa(pi.Banscore),
|
||||
pi.Subver,
|
||||
).Set(float64(pi.BytesSent))
|
||||
zcashdPeerBytesRecv.WithLabelValues(
|
||||
pi.Addr,
|
||||
pi.AddrLocal,
|
||||
strconv.FormatBool(pi.Inbound),
|
||||
strconv.Itoa(pi.Banscore),
|
||||
pi.Subver,
|
||||
).Set(float64(pi.BytesRecv))
|
||||
// zcashdPeerInfo.WithLabelValues(
|
||||
// strconv.Itoa(pi.ID),
|
||||
// pi.Addr,
|
||||
// pi.AddrLocal,
|
||||
// pi.Services,
|
||||
// strconv.Itoa(pi.LastSend),
|
||||
// strconv.Itoa(pi.LastRecv),
|
||||
// strconv.Itoa(pi.BytesSent),
|
||||
// strconv.Itoa(pi.BytesRecv),
|
||||
// strconv.Itoa(pi.Conntime),
|
||||
// strconv.Itoa(pi.Timeoffset),
|
||||
// strconv.FormatFloat(pi.PingTime, 'f', 2, 64),
|
||||
// strconv.Itoa(pi.PingWait),
|
||||
// strconv.Itoa(pi.Version),
|
||||
// pi.Subver,
|
||||
// strconv.FormatBool(pi.Inbound),
|
||||
// strconv.Itoa(pi.Startingheight),
|
||||
// strconv.Itoa(pi.Banscore),
|
||||
// strconv.Itoa(pi.SyncedHeaders),
|
||||
// strconv.Itoa(pi.SyncedBlocks),
|
||||
// ).Set(float64(pi.ID))
|
||||
}
|
||||
}
|
||||
time.Sleep(time.Duration(30) * time.Second)
|
||||
}
|
||||
|
||||
}
|
||||
|
|
26
rpc.go
26
rpc.go
|
@ -25,3 +25,29 @@ type ZGetTotalBalance struct {
|
|||
Private string `json:"private"`
|
||||
Total string `json:"total"`
|
||||
}
|
||||
|
||||
// GetPeerInfo Returns data about each connected network node
|
||||
// https://zcash-rpc.github.io/getpeerinfo.html
|
||||
type GetPeerInfo []PeerInfo
|
||||
|
||||
type PeerInfo struct {
|
||||
ID int `json:"id"`
|
||||
Addr string `json:"addr"`
|
||||
AddrLocal string `json:"addrlocal"`
|
||||
Services string `json:"services"`
|
||||
LastSend int `json:"lastsend"`
|
||||
LastRecv int `json:"lastrecv"`
|
||||
BytesSent int `json:"bytessent"`
|
||||
BytesRecv int `json:"bytesrecv"`
|
||||
Conntime int `json:"conntime"`
|
||||
Timeoffset int `json:"timeoffset"`
|
||||
PingTime float64 `json:"pingtime"`
|
||||
PingWait int `json:"pingwait"`
|
||||
Version int `json:"version"`
|
||||
Subver string `json:"subver"`
|
||||
Inbound bool `json:"inbound"`
|
||||
Startingheight int `json:"startingheight"`
|
||||
Banscore int `json:"banscore"`
|
||||
SyncedHeaders int `json:"synced_headers"`
|
||||
SyncedBlocks int `json:"synced_blocks"`
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue