github.com/nspcc-dev/neo-go@v0.105.2-0.20240517133400-6be757af3eba/pkg/services/rpcsrv/prometheus.go (about) 1 package rpcsrv 2 3 import ( 4 "strings" 5 "time" 6 7 "github.com/prometheus/client_golang/prometheus" 8 ) 9 10 // Metrics used in monitoring service. 11 var ( 12 rpcTimes = map[string]prometheus.Histogram{} 13 ) 14 15 func addReqTimeMetric(name string, t time.Duration) { 16 hist, ok := rpcTimes[name] 17 if ok { 18 hist.Observe(t.Seconds()) 19 } 20 } 21 22 func regCounter(call string) { 23 rpcTimes[call] = prometheus.NewHistogram( 24 prometheus.HistogramOpts{ 25 Help: "RPC " + call + " call handling time", 26 Name: "rpc_" + strings.ToLower(call) + "_time", 27 Namespace: "neogo", 28 }, 29 ) 30 prometheus.MustRegister(rpcTimes[call]) 31 } 32 33 func init() { 34 for call := range rpcHandlers { 35 regCounter(call) 36 } 37 for call := range rpcWsHandlers { 38 regCounter(call) 39 } 40 }