mirror of
https://github.com/nspcc-dev/neo-go.git
synced 2024-11-23 03:38:35 +00:00
43a59adbd0
`server` is not a good package name and it's an internal service, so it can be just about anywhere.
38 lines
683 B
Go
38 lines
683 B
Go
package rpcsrv
|
|
|
|
import (
|
|
"fmt"
|
|
|
|
"github.com/prometheus/client_golang/prometheus"
|
|
)
|
|
|
|
// Metrics used in monitoring service.
|
|
var rpcCounter = map[string]prometheus.Counter{}
|
|
|
|
func incCounter(name string) {
|
|
ctr, ok := rpcCounter[name]
|
|
if ok {
|
|
ctr.Inc()
|
|
}
|
|
}
|
|
|
|
func regCounter(call string) {
|
|
ctr := prometheus.NewCounter(
|
|
prometheus.CounterOpts{
|
|
Help: fmt.Sprintf("Number of calls to %s rpc endpoint", call),
|
|
Name: fmt.Sprintf("%s_called", call),
|
|
Namespace: "neogo",
|
|
},
|
|
)
|
|
prometheus.MustRegister(ctr)
|
|
rpcCounter[call] = ctr
|
|
}
|
|
|
|
func init() {
|
|
for call := range rpcHandlers {
|
|
regCounter(call)
|
|
}
|
|
for call := range rpcWsHandlers {
|
|
regCounter(call)
|
|
}
|
|
}
|