2020-02-17 12:17:02 +00:00
|
|
|
package server
|
2019-10-29 17:51:17 +00:00
|
|
|
|
2020-03-12 17:36:36 +00:00
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
|
|
|
|
"github.com/prometheus/client_golang/prometheus"
|
|
|
|
)
|
2019-10-29 17:51:17 +00:00
|
|
|
|
|
|
|
// Metrics used in monitoring service.
|
|
|
|
var (
|
2020-03-12 17:36:36 +00:00
|
|
|
rpcCalls = []string{
|
|
|
|
"getaccountstate",
|
|
|
|
"getapplicationlog",
|
|
|
|
"getassetstate",
|
|
|
|
"getbestblock",
|
|
|
|
"getbestblockhash",
|
|
|
|
"getblockcount",
|
|
|
|
"getblockhash",
|
|
|
|
"getblockheader",
|
|
|
|
"getblocksysfee",
|
|
|
|
"getclaimable",
|
|
|
|
"getconnectioncount",
|
|
|
|
"getcontractstate",
|
|
|
|
"getnep5balances",
|
|
|
|
"getnep5transfers",
|
|
|
|
"getpeers",
|
|
|
|
"getrawmempool",
|
|
|
|
"getrawtransaction",
|
|
|
|
"getstorage",
|
|
|
|
"gettransactionheight",
|
|
|
|
"gettxout",
|
|
|
|
"getunclaimed",
|
|
|
|
"getunspents",
|
|
|
|
"getvalidators",
|
|
|
|
"getversion",
|
|
|
|
"sendrawtransaction",
|
|
|
|
"submitblock",
|
|
|
|
"validateaddress",
|
|
|
|
}
|
|
|
|
|
|
|
|
rpcCounter = map[string]prometheus.Counter{}
|
2019-10-29 17:51:17 +00:00
|
|
|
)
|
|
|
|
|
2020-03-12 17:36:36 +00:00
|
|
|
func incCounter(name string) {
|
|
|
|
ctr, ok := rpcCounter[name]
|
|
|
|
if ok {
|
|
|
|
ctr.Inc()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-10-29 17:51:17 +00:00
|
|
|
func init() {
|
2020-03-12 17:36:36 +00:00
|
|
|
for i := range rpcCalls {
|
|
|
|
ctr := prometheus.NewCounter(
|
|
|
|
prometheus.CounterOpts{
|
|
|
|
Help: fmt.Sprintf("Number of calls to %s rpc endpoint", rpcCalls[i]),
|
|
|
|
Name: fmt.Sprintf("%s_called", rpcCalls[i]),
|
|
|
|
Namespace: "neogo",
|
|
|
|
},
|
|
|
|
)
|
|
|
|
prometheus.MustRegister(ctr)
|
|
|
|
rpcCounter[rpcCalls[i]] = ctr
|
|
|
|
}
|
2019-10-29 17:51:17 +00:00
|
|
|
}
|