mirror of
https://github.com/nspcc-dev/neo-go.git
synced 2024-11-23 13:38:35 +00:00
d0b1015b2c
They're a bit more useful and they're naturally grouped under rpc prefix. Simple counters will be removed eventually to avoid duplication.
55 lines
1.1 KiB
Go
55 lines
1.1 KiB
Go
package rpcsrv
|
|
|
|
import (
|
|
"fmt"
|
|
"strings"
|
|
"time"
|
|
|
|
"github.com/prometheus/client_golang/prometheus"
|
|
)
|
|
|
|
// Metrics used in monitoring service.
|
|
var (
|
|
rpcCounter = map[string]prometheus.Counter{}
|
|
rpcTimes = map[string]prometheus.Histogram{}
|
|
)
|
|
|
|
func addReqTimeMetric(name string, t time.Duration) {
|
|
hist, ok := rpcTimes[name]
|
|
if ok {
|
|
hist.Observe(t.Seconds())
|
|
}
|
|
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 (obsolete, to be removed)", call),
|
|
Name: fmt.Sprintf("%s_called", call),
|
|
Namespace: "neogo",
|
|
},
|
|
)
|
|
prometheus.MustRegister(ctr)
|
|
rpcCounter[call] = ctr
|
|
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)
|
|
}
|
|
}
|