neo-go/pkg/services/rpcsrv/prometheus.go

41 lines
731 B
Go
Raw Normal View History

package rpcsrv
2020-03-12 17:36:36 +00:00
import (
"strings"
"time"
2020-03-12 17:36:36 +00:00
"github.com/prometheus/client_golang/prometheus"
)
// Metrics used in monitoring service.
var (
2023-03-18 07:52:24 +00:00
rpcTimes = map[string]prometheus.Histogram{}
)
func addReqTimeMetric(name string, t time.Duration) {
hist, ok := rpcTimes[name]
if ok {
hist.Observe(t.Seconds())
}
2020-03-12 17:36:36 +00:00
}
func regCounter(call string) {
rpcTimes[call] = prometheus.NewHistogram(
prometheus.HistogramOpts{
Help: "RPC " + call + " call handling time",
Name: "rpc_" + strings.ToLower(call) + "_time",
Namespace: "neogo",
},
)
prometheus.MustRegister(rpcTimes[call])
}
func init() {
for call := range rpcHandlers {
regCounter(call)
}
for call := range rpcWsHandlers {
regCounter(call)
2020-03-12 17:36:36 +00:00
}
}