neo-go/pkg/rpc/server/prometheus.go

32 lines
582 B
Go
Raw Normal View History

package server
2020-03-12 17:36:36 +00:00
import (
"fmt"
"github.com/prometheus/client_golang/prometheus"
)
// Metrics used in monitoring service.
var rpcCounter = map[string]prometheus.Counter{}
2020-03-12 17:36:36 +00:00
func incCounter(name string) {
ctr, ok := rpcCounter[name]
if ok {
ctr.Inc()
}
}
func init() {
for call := range rpcHandlers {
2020-03-12 17:36:36 +00:00
ctr := prometheus.NewCounter(
prometheus.CounterOpts{
Help: fmt.Sprintf("Number of calls to %s rpc endpoint", call),
Name: fmt.Sprintf("%s_called", call),
2020-03-12 17:36:36 +00:00
Namespace: "neogo",
},
)
prometheus.MustRegister(ctr)
rpcCounter[call] = ctr
2020-03-12 17:36:36 +00:00
}
}