@@ -18,6 +18,7 @@ package rpc
18
18
19
19
import (
20
20
"fmt"
21
+ "time"
21
22
22
23
"github.com/ethereum/go-ethereum/metrics"
23
24
)
@@ -26,14 +27,24 @@ var (
26
27
rpcRequestGauge = metrics .NewRegisteredGauge ("rpc/requests" , nil )
27
28
successfulRequestGauge = metrics .NewRegisteredGauge ("rpc/success" , nil )
28
29
failedRequestGauge = metrics .NewRegisteredGauge ("rpc/failure" , nil )
29
- rpcServingTimer = metrics .NewRegisteredTimer ("rpc/duration/all" , nil )
30
+
31
+ // serveTimeHistName is the prefix of the per-request serving time histograms.
32
+ serveTimeHistName = "rpc/duration"
33
+
34
+ rpcServingTimer = metrics .NewRegisteredTimer ("rpc/duration/all" , nil )
30
35
)
31
36
32
- func newRPCServingTimer (method string , valid bool ) metrics.Timer {
33
- flag := "success"
34
- if ! valid {
35
- flag = "failure"
37
+ // updateServeTimeHistogram tracks the serving time of a remote RPC call.
38
+ func updateServeTimeHistogram (method string , success bool , elapsed time.Duration ) {
39
+ note := "success"
40
+ if ! success {
41
+ note = "failure"
42
+ }
43
+ h := fmt .Sprintf ("%s/%s/%s" , serveTimeHistName , method , note )
44
+ sampler := func () metrics.Sample {
45
+ return metrics .ResettingSample (
46
+ metrics .NewExpDecaySample (1028 , 0.015 ),
47
+ )
36
48
}
37
- m := fmt .Sprintf ("rpc/duration/%s/%s" , method , flag )
38
- return metrics .GetOrRegisterTimer (m , nil )
49
+ metrics .GetOrRegisterHistogramLazy (h , nil , sampler ).Update (elapsed .Microseconds ())
39
50
}
0 commit comments