mirror of
https://github.com/anyproto/any-sync.git
synced 2025-06-07 21:47:02 +09:00
26 lines
579 B
Go
26 lines
579 B
Go
package metric
|
|
|
|
import (
|
|
"github.com/prometheus/client_golang/prometheus"
|
|
"go.uber.org/zap"
|
|
"storj.io/drpc"
|
|
"time"
|
|
"unicode/utf8"
|
|
)
|
|
|
|
type prometheusDRPC struct {
|
|
drpc.Handler
|
|
SummaryVec *prometheus.SummaryVec
|
|
}
|
|
|
|
func (ph *prometheusDRPC) HandleRPC(stream drpc.Stream, rpc string) (err error) {
|
|
st := time.Now()
|
|
defer func() {
|
|
if utf8.ValidString(rpc) {
|
|
ph.SummaryVec.WithLabelValues(rpc).Observe(time.Since(st).Seconds())
|
|
} else {
|
|
log.WarnCtx(stream.Context(), "invalid rpc string", zap.String("rpc", rpc))
|
|
}
|
|
}()
|
|
return ph.Handler.HandleRPC(stream, rpc)
|
|
}
|