2022-07-21 16:21:44 +03:00
|
|
|
package rpcsrv
|
2019-10-29 20:51:17 +03:00
|
|
|
|
2020-03-12 20:36:36 +03:00
|
|
|
import (
|
2022-11-09 13:26:45 +03:00
|
|
|
"strings"
|
|
|
|
"time"
|
2020-03-12 20:36:36 +03:00
|
|
|
|
|
|
|
"github.com/prometheus/client_golang/prometheus"
|
|
|
|
)
|
2019-10-29 20:51:17 +03:00
|
|
|
|
|
|
|
// Metrics used in monitoring service.
|
2022-11-09 13:26:45 +03:00
|
|
|
var (
|
2023-03-18 10:52:24 +03:00
|
|
|
rpcTimes = map[string]prometheus.Histogram{}
|
2022-11-09 13:26:45 +03:00
|
|
|
)
|
2019-10-29 20:51:17 +03:00
|
|
|
|
2022-11-09 13:26:45 +03:00
|
|
|
func addReqTimeMetric(name string, t time.Duration) {
|
|
|
|
hist, ok := rpcTimes[name]
|
|
|
|
if ok {
|
|
|
|
hist.Observe(t.Seconds())
|
|
|
|
}
|
2020-03-12 20:36:36 +03:00
|
|
|
}
|
|
|
|
|
2022-03-21 23:18:00 +03:00
|
|
|
func regCounter(call string) {
|
2022-11-09 13:26:45 +03: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 23:18:00 +03:00
|
|
|
}
|
|
|
|
|
2019-10-29 20:51:17 +03:00
|
|
|
func init() {
|
2020-03-25 15:19:12 +03:00
|
|
|
for call := range rpcHandlers {
|
2022-03-21 23:18:00 +03:00
|
|
|
regCounter(call)
|
|
|
|
}
|
|
|
|
for call := range rpcWsHandlers {
|
|
|
|
regCounter(call)
|
2020-03-12 20:36:36 +03:00
|
|
|
}
|
2019-10-29 20:51:17 +03:00
|
|
|
}
|