mirror of
https://github.com/nspcc-dev/neo-go.git
synced 2024-11-23 03:38:35 +00:00
rpc: unify counter metrics update
This commit is contained in:
parent
db2c4c7598
commit
9e6785bed9
2 changed files with 56 additions and 267 deletions
|
@ -1,249 +1,63 @@
|
||||||
package server
|
package server
|
||||||
|
|
||||||
import "github.com/prometheus/client_golang/prometheus"
|
import (
|
||||||
|
"fmt"
|
||||||
|
|
||||||
|
"github.com/prometheus/client_golang/prometheus"
|
||||||
|
)
|
||||||
|
|
||||||
// Metrics used in monitoring service.
|
// Metrics used in monitoring service.
|
||||||
var (
|
var (
|
||||||
getapplicationlogCalled = prometheus.NewCounter(
|
rpcCalls = []string{
|
||||||
prometheus.CounterOpts{
|
"getaccountstate",
|
||||||
Help: "Number of calls to getapplicationlog rpc endpoint",
|
"getapplicationlog",
|
||||||
Name: "getapplicationlog_called",
|
"getassetstate",
|
||||||
Namespace: "neogo",
|
"getbestblock",
|
||||||
},
|
"getbestblockhash",
|
||||||
)
|
"getblockcount",
|
||||||
getbestblockhashCalled = prometheus.NewCounter(
|
"getblockhash",
|
||||||
prometheus.CounterOpts{
|
"getblockheader",
|
||||||
Help: "Number of calls to getbestblockhash rpc endpoint",
|
"getblocksysfee",
|
||||||
Name: "getbestblockhash_called",
|
"getclaimable",
|
||||||
Namespace: "neogo",
|
"getconnectioncount",
|
||||||
},
|
"getcontractstate",
|
||||||
)
|
"getnep5balances",
|
||||||
|
"getnep5transfers",
|
||||||
|
"getpeers",
|
||||||
|
"getrawmempool",
|
||||||
|
"getrawtransaction",
|
||||||
|
"getstorage",
|
||||||
|
"gettransactionheight",
|
||||||
|
"gettxout",
|
||||||
|
"getunclaimed",
|
||||||
|
"getunspents",
|
||||||
|
"getvalidators",
|
||||||
|
"getversion",
|
||||||
|
"sendrawtransaction",
|
||||||
|
"submitblock",
|
||||||
|
"validateaddress",
|
||||||
|
}
|
||||||
|
|
||||||
getbestblockCalled = prometheus.NewCounter(
|
rpcCounter = map[string]prometheus.Counter{}
|
||||||
prometheus.CounterOpts{
|
|
||||||
Help: "Number of calls to getbestblock rpc endpoint",
|
|
||||||
Name: "getbestblock_called",
|
|
||||||
Namespace: "neogo",
|
|
||||||
},
|
|
||||||
)
|
|
||||||
|
|
||||||
getblockcountCalled = prometheus.NewCounter(
|
|
||||||
prometheus.CounterOpts{
|
|
||||||
Help: "Number of calls to getblockcount rpc endpoint",
|
|
||||||
Name: "getblockcount_called",
|
|
||||||
Namespace: "neogo",
|
|
||||||
},
|
|
||||||
)
|
|
||||||
|
|
||||||
getblockHashCalled = prometheus.NewCounter(
|
|
||||||
prometheus.CounterOpts{
|
|
||||||
Help: "Number of calls to getblockhash rpc endpoint",
|
|
||||||
Name: "getblockhash_called",
|
|
||||||
Namespace: "neogo",
|
|
||||||
},
|
|
||||||
)
|
|
||||||
|
|
||||||
getblockheaderCalled = prometheus.NewCounter(
|
|
||||||
prometheus.CounterOpts{
|
|
||||||
Help: "Number of calls to getblockheader rpc endpoint",
|
|
||||||
Name: "getblockheader_called",
|
|
||||||
Namespace: "neogo",
|
|
||||||
},
|
|
||||||
)
|
|
||||||
|
|
||||||
getblocksysfeeCalled = prometheus.NewCounter(
|
|
||||||
prometheus.CounterOpts{
|
|
||||||
Help: "Number of calls to getblocksysfee rpc endpoint",
|
|
||||||
Name: "getblocksysfee_called",
|
|
||||||
Namespace: "neogo",
|
|
||||||
},
|
|
||||||
)
|
|
||||||
|
|
||||||
getclaimableCalled = prometheus.NewCounter(
|
|
||||||
prometheus.CounterOpts{
|
|
||||||
Help: "Number of calls to getclaimable rpc endpoint",
|
|
||||||
Name: "getclaimable_called",
|
|
||||||
Namespace: "neogo",
|
|
||||||
},
|
|
||||||
)
|
|
||||||
|
|
||||||
getconnectioncountCalled = prometheus.NewCounter(
|
|
||||||
prometheus.CounterOpts{
|
|
||||||
Help: "Number of calls to getconnectioncount rpc endpoint",
|
|
||||||
Name: "getconnectioncount_called",
|
|
||||||
Namespace: "neogo",
|
|
||||||
},
|
|
||||||
)
|
|
||||||
|
|
||||||
getcontractstateCalled = prometheus.NewCounter(
|
|
||||||
prometheus.CounterOpts{
|
|
||||||
Help: "Number of calls to getcontractstate rpc endpoint",
|
|
||||||
Name: "getcontractstate_called",
|
|
||||||
Namespace: "neogo",
|
|
||||||
},
|
|
||||||
)
|
|
||||||
getvalidatorsCalled = prometheus.NewCounter(
|
|
||||||
prometheus.CounterOpts{
|
|
||||||
Help: "Number of calls to getvalidators rpc endpoint",
|
|
||||||
Name: "getvalidators_called",
|
|
||||||
Namespace: "neogo",
|
|
||||||
},
|
|
||||||
)
|
|
||||||
|
|
||||||
getnep5balancesCalled = prometheus.NewCounter(
|
|
||||||
prometheus.CounterOpts{
|
|
||||||
Help: "Number of calls to getnep5balances rpc endpoint",
|
|
||||||
Name: "getnep5balances_called",
|
|
||||||
Namespace: "neogo",
|
|
||||||
},
|
|
||||||
)
|
|
||||||
|
|
||||||
getnep5transfersCalled = prometheus.NewCounter(
|
|
||||||
prometheus.CounterOpts{
|
|
||||||
Help: "Number of calls to getnep5transfers rpc endpoint",
|
|
||||||
Name: "getnep5transfers_called",
|
|
||||||
Namespace: "neogo",
|
|
||||||
},
|
|
||||||
)
|
|
||||||
|
|
||||||
getversionCalled = prometheus.NewCounter(
|
|
||||||
prometheus.CounterOpts{
|
|
||||||
Help: "Number of calls to getversion rpc endpoint",
|
|
||||||
Name: "getversion_called",
|
|
||||||
Namespace: "neogo",
|
|
||||||
},
|
|
||||||
)
|
|
||||||
|
|
||||||
getpeersCalled = prometheus.NewCounter(
|
|
||||||
prometheus.CounterOpts{
|
|
||||||
Help: "Number of calls to getpeers rpc endpoint",
|
|
||||||
Name: "getpeers_called",
|
|
||||||
Namespace: "neogo",
|
|
||||||
},
|
|
||||||
)
|
|
||||||
|
|
||||||
getrawmempoolCalled = prometheus.NewCounter(
|
|
||||||
prometheus.CounterOpts{
|
|
||||||
Help: "Number of calls to getrawmempool rpc endpoint",
|
|
||||||
Name: "getrawmempool_called",
|
|
||||||
Namespace: "neogo",
|
|
||||||
},
|
|
||||||
)
|
|
||||||
|
|
||||||
validateaddressCalled = prometheus.NewCounter(
|
|
||||||
prometheus.CounterOpts{
|
|
||||||
Help: "Number of calls to validateaddress rpc endpoint",
|
|
||||||
Name: "validateaddress_called",
|
|
||||||
Namespace: "neogo",
|
|
||||||
},
|
|
||||||
)
|
|
||||||
|
|
||||||
getassetstateCalled = prometheus.NewCounter(
|
|
||||||
prometheus.CounterOpts{
|
|
||||||
Help: "Number of calls to getassetstate rpc endpoint",
|
|
||||||
Name: "getassetstate_called",
|
|
||||||
Namespace: "neogo",
|
|
||||||
},
|
|
||||||
)
|
|
||||||
|
|
||||||
getaccountstateCalled = prometheus.NewCounter(
|
|
||||||
prometheus.CounterOpts{
|
|
||||||
Help: "Number of calls to getaccountstate rpc endpoint",
|
|
||||||
Name: "getaccountstate_called",
|
|
||||||
Namespace: "neogo",
|
|
||||||
},
|
|
||||||
)
|
|
||||||
|
|
||||||
gettransactionheightCalled = prometheus.NewCounter(
|
|
||||||
prometheus.CounterOpts{
|
|
||||||
Help: "Number of calls to gettransactionheight rpc endpoint",
|
|
||||||
Name: "gettransactionheight_called",
|
|
||||||
Namespace: "neogo",
|
|
||||||
},
|
|
||||||
)
|
|
||||||
|
|
||||||
gettxoutCalled = prometheus.NewCounter(
|
|
||||||
prometheus.CounterOpts{
|
|
||||||
Help: "Number of calls to gettxout rpc endpoint",
|
|
||||||
Name: "gettxout_called",
|
|
||||||
Namespace: "neogo",
|
|
||||||
},
|
|
||||||
)
|
|
||||||
|
|
||||||
getrawtransactionCalled = prometheus.NewCounter(
|
|
||||||
prometheus.CounterOpts{
|
|
||||||
Help: "Number of calls to getrawtransaction rpc endpoint",
|
|
||||||
Name: "getrawtransaction_called",
|
|
||||||
Namespace: "neogo",
|
|
||||||
},
|
|
||||||
)
|
|
||||||
|
|
||||||
getunclaimedCalled = prometheus.NewCounter(
|
|
||||||
prometheus.CounterOpts{
|
|
||||||
Help: "Number of calls to getunclaimed rpc endpoint",
|
|
||||||
Name: "getunclaimed_called",
|
|
||||||
Namespace: "neogo",
|
|
||||||
},
|
|
||||||
)
|
|
||||||
|
|
||||||
getunspentsCalled = prometheus.NewCounter(
|
|
||||||
prometheus.CounterOpts{
|
|
||||||
Help: "Number of calls to getunspents rpc endpoint",
|
|
||||||
Name: "getunspents_called",
|
|
||||||
Namespace: "neogo",
|
|
||||||
},
|
|
||||||
)
|
|
||||||
|
|
||||||
sendrawtransactionCalled = prometheus.NewCounter(
|
|
||||||
prometheus.CounterOpts{
|
|
||||||
Help: "Number of calls to sendrawtransaction rpc endpoint",
|
|
||||||
Name: "sendrawtransaction_called",
|
|
||||||
Namespace: "neogo",
|
|
||||||
},
|
|
||||||
)
|
|
||||||
|
|
||||||
submitblockCalled = prometheus.NewCounter(
|
|
||||||
prometheus.CounterOpts{
|
|
||||||
Help: "Number of calls to submitblock rpc endpoint",
|
|
||||||
Name: "submitblock_called",
|
|
||||||
Namespace: "neogo",
|
|
||||||
},
|
|
||||||
)
|
|
||||||
|
|
||||||
getstorageCalled = prometheus.NewCounter(
|
|
||||||
prometheus.CounterOpts{
|
|
||||||
Help: "Number of calls to getstorage rpc endpoint",
|
|
||||||
Name: "getstorage_called",
|
|
||||||
Namespace: "neogo",
|
|
||||||
},
|
|
||||||
)
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
func incCounter(name string) {
|
||||||
prometheus.MustRegister(
|
ctr, ok := rpcCounter[name]
|
||||||
getapplicationlogCalled,
|
if ok {
|
||||||
getbestblockhashCalled,
|
ctr.Inc()
|
||||||
getbestblockCalled,
|
}
|
||||||
getblockcountCalled,
|
}
|
||||||
getblockHashCalled,
|
|
||||||
getblockheaderCalled,
|
func init() {
|
||||||
getblocksysfeeCalled,
|
for i := range rpcCalls {
|
||||||
getconnectioncountCalled,
|
ctr := prometheus.NewCounter(
|
||||||
getcontractstateCalled,
|
prometheus.CounterOpts{
|
||||||
getvalidatorsCalled,
|
Help: fmt.Sprintf("Number of calls to %s rpc endpoint", rpcCalls[i]),
|
||||||
getversionCalled,
|
Name: fmt.Sprintf("%s_called", rpcCalls[i]),
|
||||||
getpeersCalled,
|
Namespace: "neogo",
|
||||||
getrawmempoolCalled,
|
},
|
||||||
validateaddressCalled,
|
)
|
||||||
getassetstateCalled,
|
prometheus.MustRegister(ctr)
|
||||||
getaccountstateCalled,
|
rpcCounter[rpcCalls[i]] = ctr
|
||||||
getunclaimedCalled,
|
}
|
||||||
getunspentsCalled,
|
|
||||||
gettransactionheightCalled,
|
|
||||||
gettxoutCalled,
|
|
||||||
getrawtransactionCalled,
|
|
||||||
sendrawtransactionCalled,
|
|
||||||
submitblockCalled,
|
|
||||||
getstorageCalled,
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -153,18 +153,17 @@ func (s *Server) methodHandler(w http.ResponseWriter, req *request.In, reqParams
|
||||||
resultsErr error
|
resultsErr error
|
||||||
)
|
)
|
||||||
|
|
||||||
|
incCounter(req.Method)
|
||||||
|
|
||||||
Methods:
|
Methods:
|
||||||
switch req.Method {
|
switch req.Method {
|
||||||
case "getapplicationlog":
|
case "getapplicationlog":
|
||||||
getapplicationlogCalled.Inc()
|
|
||||||
results, resultsErr = s.getApplicationLog(reqParams)
|
results, resultsErr = s.getApplicationLog(reqParams)
|
||||||
|
|
||||||
case "getbestblockhash":
|
case "getbestblockhash":
|
||||||
getbestblockhashCalled.Inc()
|
|
||||||
results = "0x" + s.chain.CurrentBlockHash().StringLE()
|
results = "0x" + s.chain.CurrentBlockHash().StringLE()
|
||||||
|
|
||||||
case "getblock":
|
case "getblock":
|
||||||
getbestblockCalled.Inc()
|
|
||||||
var hash util.Uint256
|
var hash util.Uint256
|
||||||
|
|
||||||
param, ok := reqParams.Value(0)
|
param, ok := reqParams.Value(0)
|
||||||
|
@ -208,11 +207,9 @@ Methods:
|
||||||
}
|
}
|
||||||
|
|
||||||
case "getblockcount":
|
case "getblockcount":
|
||||||
getblockcountCalled.Inc()
|
|
||||||
results = s.chain.BlockHeight() + 1
|
results = s.chain.BlockHeight() + 1
|
||||||
|
|
||||||
case "getblockhash":
|
case "getblockhash":
|
||||||
getblockHashCalled.Inc()
|
|
||||||
param, ok := reqParams.ValueWithType(0, request.NumberT)
|
param, ok := reqParams.ValueWithType(0, request.NumberT)
|
||||||
if !ok {
|
if !ok {
|
||||||
resultsErr = response.ErrInvalidParams
|
resultsErr = response.ErrInvalidParams
|
||||||
|
@ -227,34 +224,26 @@ Methods:
|
||||||
results = s.chain.GetHeaderHash(num)
|
results = s.chain.GetHeaderHash(num)
|
||||||
|
|
||||||
case "getblockheader":
|
case "getblockheader":
|
||||||
getblockheaderCalled.Inc()
|
|
||||||
results, resultsErr = s.getBlockHeader(reqParams)
|
results, resultsErr = s.getBlockHeader(reqParams)
|
||||||
|
|
||||||
case "getblocksysfee":
|
case "getblocksysfee":
|
||||||
getblocksysfeeCalled.Inc()
|
|
||||||
results, resultsErr = s.getBlockSysFee(reqParams)
|
results, resultsErr = s.getBlockSysFee(reqParams)
|
||||||
|
|
||||||
case "getclaimable":
|
case "getclaimable":
|
||||||
getclaimableCalled.Inc()
|
|
||||||
results, resultsErr = s.getClaimable(reqParams)
|
results, resultsErr = s.getClaimable(reqParams)
|
||||||
|
|
||||||
case "getconnectioncount":
|
case "getconnectioncount":
|
||||||
getconnectioncountCalled.Inc()
|
|
||||||
results = s.coreServer.PeerCount()
|
results = s.coreServer.PeerCount()
|
||||||
|
|
||||||
case "getnep5balances":
|
case "getnep5balances":
|
||||||
getnep5balancesCalled.Inc()
|
|
||||||
results, resultsErr = s.getNEP5Balances(reqParams)
|
results, resultsErr = s.getNEP5Balances(reqParams)
|
||||||
|
|
||||||
case "getnep5transfers":
|
case "getnep5transfers":
|
||||||
getnep5transfersCalled.Inc()
|
|
||||||
results, resultsErr = s.getNEP5Transfers(reqParams)
|
results, resultsErr = s.getNEP5Transfers(reqParams)
|
||||||
case "getvalidators":
|
case "getvalidators":
|
||||||
getvalidatorsCalled.Inc()
|
|
||||||
results, resultsErr = s.getValidators()
|
results, resultsErr = s.getValidators()
|
||||||
|
|
||||||
case "getversion":
|
case "getversion":
|
||||||
getversionCalled.Inc()
|
|
||||||
results = result.Version{
|
results = result.Version{
|
||||||
Port: s.coreServer.Port,
|
Port: s.coreServer.Port,
|
||||||
Nonce: s.coreServer.ID(),
|
Nonce: s.coreServer.ID(),
|
||||||
|
@ -262,7 +251,6 @@ Methods:
|
||||||
}
|
}
|
||||||
|
|
||||||
case "getpeers":
|
case "getpeers":
|
||||||
getpeersCalled.Inc()
|
|
||||||
peers := result.NewGetPeers()
|
peers := result.NewGetPeers()
|
||||||
peers.AddUnconnected(s.coreServer.UnconnectedPeers())
|
peers.AddUnconnected(s.coreServer.UnconnectedPeers())
|
||||||
peers.AddConnected(s.coreServer.ConnectedPeers())
|
peers.AddConnected(s.coreServer.ConnectedPeers())
|
||||||
|
@ -270,7 +258,6 @@ Methods:
|
||||||
results = peers
|
results = peers
|
||||||
|
|
||||||
case "getrawmempool":
|
case "getrawmempool":
|
||||||
getrawmempoolCalled.Inc()
|
|
||||||
mp := s.chain.GetMemPool()
|
mp := s.chain.GetMemPool()
|
||||||
hashList := make([]util.Uint256, 0)
|
hashList := make([]util.Uint256, 0)
|
||||||
for _, item := range mp.GetVerifiedTransactions() {
|
for _, item := range mp.GetVerifiedTransactions() {
|
||||||
|
@ -279,11 +266,9 @@ Methods:
|
||||||
results = hashList
|
results = hashList
|
||||||
|
|
||||||
case "getstorage":
|
case "getstorage":
|
||||||
getstorageCalled.Inc()
|
|
||||||
results, resultsErr = s.getStorage(reqParams)
|
results, resultsErr = s.getStorage(reqParams)
|
||||||
|
|
||||||
case "validateaddress":
|
case "validateaddress":
|
||||||
validateaddressCalled.Inc()
|
|
||||||
param, ok := reqParams.Value(0)
|
param, ok := reqParams.Value(0)
|
||||||
if !ok {
|
if !ok {
|
||||||
resultsErr = response.ErrInvalidParams
|
resultsErr = response.ErrInvalidParams
|
||||||
|
@ -292,7 +277,6 @@ Methods:
|
||||||
results = validateAddress(param.Value)
|
results = validateAddress(param.Value)
|
||||||
|
|
||||||
case "getassetstate":
|
case "getassetstate":
|
||||||
getassetstateCalled.Inc()
|
|
||||||
param, ok := reqParams.ValueWithType(0, request.StringT)
|
param, ok := reqParams.ValueWithType(0, request.StringT)
|
||||||
if !ok {
|
if !ok {
|
||||||
resultsErr = response.ErrInvalidParams
|
resultsErr = response.ErrInvalidParams
|
||||||
|
@ -313,31 +297,24 @@ Methods:
|
||||||
}
|
}
|
||||||
|
|
||||||
case "getaccountstate":
|
case "getaccountstate":
|
||||||
getaccountstateCalled.Inc()
|
|
||||||
results, resultsErr = s.getAccountState(reqParams, false)
|
results, resultsErr = s.getAccountState(reqParams, false)
|
||||||
|
|
||||||
case "getcontractstate":
|
case "getcontractstate":
|
||||||
getcontractstateCalled.Inc()
|
|
||||||
results, resultsErr = s.getContractState(reqParams)
|
results, resultsErr = s.getContractState(reqParams)
|
||||||
|
|
||||||
case "getrawtransaction":
|
case "getrawtransaction":
|
||||||
getrawtransactionCalled.Inc()
|
|
||||||
results, resultsErr = s.getrawtransaction(reqParams)
|
results, resultsErr = s.getrawtransaction(reqParams)
|
||||||
|
|
||||||
case "gettransactionheight":
|
case "gettransactionheight":
|
||||||
gettransactionheightCalled.Inc()
|
|
||||||
results, resultsErr = s.getTransactionHeight(reqParams)
|
results, resultsErr = s.getTransactionHeight(reqParams)
|
||||||
|
|
||||||
case "gettxout":
|
case "gettxout":
|
||||||
gettxoutCalled.Inc()
|
|
||||||
results, resultsErr = s.getTxOut(reqParams)
|
results, resultsErr = s.getTxOut(reqParams)
|
||||||
|
|
||||||
case "getunclaimed":
|
case "getunclaimed":
|
||||||
getunclaimedCalled.Inc()
|
|
||||||
results, resultsErr = s.getUnclaimed(reqParams)
|
results, resultsErr = s.getUnclaimed(reqParams)
|
||||||
|
|
||||||
case "getunspents":
|
case "getunspents":
|
||||||
getunspentsCalled.Inc()
|
|
||||||
results, resultsErr = s.getAccountState(reqParams, true)
|
results, resultsErr = s.getAccountState(reqParams, true)
|
||||||
|
|
||||||
case "invoke":
|
case "invoke":
|
||||||
|
@ -350,11 +327,9 @@ Methods:
|
||||||
results, resultsErr = s.invokescript(reqParams)
|
results, resultsErr = s.invokescript(reqParams)
|
||||||
|
|
||||||
case "submitblock":
|
case "submitblock":
|
||||||
submitblockCalled.Inc()
|
|
||||||
results, resultsErr = s.submitBlock(reqParams)
|
results, resultsErr = s.submitBlock(reqParams)
|
||||||
|
|
||||||
case "sendrawtransaction":
|
case "sendrawtransaction":
|
||||||
sendrawtransactionCalled.Inc()
|
|
||||||
results, resultsErr = s.sendrawtransaction(reqParams)
|
results, resultsErr = s.sendrawtransaction(reqParams)
|
||||||
|
|
||||||
default:
|
default:
|
||||||
|
|
Loading…
Reference in a new issue