metrics: add pending tx and peer count
This commit is contained in:
parent
1f43c3410a
commit
c50906ede1
@ -18,8 +18,18 @@ type (
|
|||||||
}
|
}
|
||||||
|
|
||||||
BatchMetricsResponse struct {
|
BatchMetricsResponse struct {
|
||||||
GasPrice uint64
|
GasPrice uint64
|
||||||
BlockNumber uint64
|
BlockNumber uint64
|
||||||
|
PeerCount uint64
|
||||||
|
PendingTx []pendingTx
|
||||||
|
PendingTxCount int
|
||||||
|
Enode string
|
||||||
|
}
|
||||||
|
|
||||||
|
pendingTx struct {
|
||||||
|
Hash string `json:"hash"`
|
||||||
|
From string `json:"from"`
|
||||||
|
To string `json:"to"`
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -68,6 +78,9 @@ func batchMetricsCall() (bool, BatchMetricsResponse) {
|
|||||||
// The rpc call id here is guranteed to be in order of appearance starting from index 0
|
// The rpc call id here is guranteed to be in order of appearance starting from index 0
|
||||||
jsonrpc.NewRequest("eth_gasPrice"),
|
jsonrpc.NewRequest("eth_gasPrice"),
|
||||||
jsonrpc.NewRequest("eth_blockNumber"),
|
jsonrpc.NewRequest("eth_blockNumber"),
|
||||||
|
jsonrpc.NewRequest("net_peerCount"),
|
||||||
|
jsonrpc.NewRequest("parity_pendingTransactions"),
|
||||||
|
jsonrpc.NewRequest("parity_enode"),
|
||||||
})
|
})
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -97,5 +110,31 @@ func batchMetricsCall() (bool, BatchMetricsResponse) {
|
|||||||
batchResponse.BlockNumber = util.Hex2Int(val)
|
batchResponse.BlockNumber = util.Hex2Int(val)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if peerCount, ok := rpcResponses[2]; ok {
|
||||||
|
val, err := peerCount.GetString()
|
||||||
|
if err != nil {
|
||||||
|
return false, batchResponse
|
||||||
|
}
|
||||||
|
batchResponse.PeerCount = util.Hex2Int(val)
|
||||||
|
}
|
||||||
|
|
||||||
|
if pendingTransactionsArray, ok := rpcResponses[3]; ok {
|
||||||
|
var pendingTransactions = []pendingTx{}
|
||||||
|
err := pendingTransactionsArray.GetObject(&pendingTransactions)
|
||||||
|
if err != nil {
|
||||||
|
return false, batchResponse
|
||||||
|
}
|
||||||
|
batchResponse.PendingTxCount = len(pendingTransactions)
|
||||||
|
batchResponse.PendingTx = pendingTransactions
|
||||||
|
}
|
||||||
|
|
||||||
|
if enode, ok := rpcResponses[4]; ok {
|
||||||
|
val, err := enode.GetString()
|
||||||
|
if err != nil {
|
||||||
|
return false, batchResponse
|
||||||
|
}
|
||||||
|
batchResponse.Enode = val
|
||||||
|
}
|
||||||
|
|
||||||
return true, batchResponse
|
return true, batchResponse
|
||||||
}
|
}
|
||||||
|
@ -23,7 +23,7 @@ func healthHandler(c *gin.Context) {
|
|||||||
|
|
||||||
if !allOk {
|
if !allOk {
|
||||||
// choose a better status code if available
|
// choose a better status code if available
|
||||||
c.JSON(http.StatusExpectationFailed, gin.H{
|
c.JSON(http.StatusServiceUnavailable, gin.H{
|
||||||
"message": "could not get node health status",
|
"message": "could not get node health status",
|
||||||
})
|
})
|
||||||
return
|
return
|
||||||
@ -40,14 +40,18 @@ func metricsHandler(c *gin.Context) {
|
|||||||
|
|
||||||
if !allOk {
|
if !allOk {
|
||||||
// choose a better status code if available
|
// choose a better status code if available
|
||||||
c.JSON(http.StatusExpectationFailed, gin.H{
|
c.JSON(http.StatusServiceUnavailable, gin.H{
|
||||||
"message": "could not get node metrics",
|
"message": "could not get node metrics",
|
||||||
})
|
})
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
c.JSON(http.StatusOK, gin.H{
|
c.JSON(http.StatusOK, gin.H{
|
||||||
"gasPrice": data.GasPrice,
|
"gasPrice": data.GasPrice,
|
||||||
"blockNumber": data.BlockNumber,
|
"blockNumber": data.BlockNumber,
|
||||||
|
"peerCount": data.PeerCount,
|
||||||
|
"pendingTransactionsCount": data.PendingTxCount,
|
||||||
|
"pendingTransactions": data.PendingTx,
|
||||||
|
"enode": data.Enode,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user