2022-07-21 13:21:44 +00:00
|
|
|
package rpcsrv
|
2019-10-29 17:51:17 +00:00
|
|
|
|
2020-03-12 17:36:36 +00:00
|
|
|
import (
|
2022-11-09 10:26:45 +00:00
|
|
|
"strings"
|
|
|
|
"time"
|
2020-03-12 17:36:36 +00:00
|
|
|
|
|
|
|
"github.com/prometheus/client_golang/prometheus"
|
|
|
|
)
|
2019-10-29 17:51:17 +00:00
|
|
|
|
|
|
|
// Metrics used in monitoring service.
|
2022-11-09 10:26:45 +00:00
|
|
|
var (
|
2023-03-18 07:52:24 +00:00
|
|
|
rpcTimes = map[string]prometheus.Histogram{}
|
2022-11-09 10:26:45 +00:00
|
|
|
)
|
2019-10-29 17:51:17 +00:00
|
|
|
|
2022-11-09 10:26:45 +00:00
|
|
|
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
|
|
|
}
|
|
|
|
|
2022-03-21 20:18:00 +00:00
|
|
|
func regCounter(call string) {
|
2022-11-09 10:26:45 +00:00
|
|
|
rpcTimes[call] = prometheus.NewHistogram(
|
|
|
|
prometheus.HistogramOpts{
|
|
|
|
Help: "RPC " + call + " call handling time",
|
|
|
|
Name: "rpc_" + strings.ToLower(call) + "_time",
|
|
|
|
Namespace: "neogo",
|
|
|
|
},
|
|
|
|
)
|
|
|
|
prometheus.MustRegister(rpcTimes[call])
|
2022-03-21 20:18:00 +00:00
|
|
|
}
|
|
|
|
|
2019-10-29 17:51:17 +00:00
|
|
|
func init() {
|
2020-03-25 12:19:12 +00:00
|
|
|
for call := range rpcHandlers {
|
2022-03-21 20:18:00 +00:00
|
|
|
regCounter(call)
|
|
|
|
}
|
|
|
|
for call := range rpcWsHandlers {
|
|
|
|
regCounter(call)
|
2020-03-12 17:36:36 +00:00
|
|
|
}
|
2019-10-29 17:51:17 +00:00
|
|
|
}
|