forked from cerc-io/plugeth
rpc: swap out timer metrics to histograms
This commit is contained in:
parent
138f0d7494
commit
106a162b7c
@ -346,7 +346,7 @@ func (h *handler) handleCall(cp *callProc, msg *jsonrpcMessage) *jsonrpcMessage
|
|||||||
successfulRequestGauge.Inc(1)
|
successfulRequestGauge.Inc(1)
|
||||||
}
|
}
|
||||||
rpcServingTimer.UpdateSince(start)
|
rpcServingTimer.UpdateSince(start)
|
||||||
newRPCServingTimer(msg.Method, answer.Error == nil).UpdateSince(start)
|
updateServeTimeHistogram(msg.Method, answer.Error == nil, time.Since(start))
|
||||||
}
|
}
|
||||||
return answer
|
return answer
|
||||||
}
|
}
|
||||||
|
@ -18,6 +18,7 @@ package rpc
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"time"
|
||||||
|
|
||||||
"github.com/ethereum/go-ethereum/metrics"
|
"github.com/ethereum/go-ethereum/metrics"
|
||||||
)
|
)
|
||||||
@ -26,14 +27,24 @@ var (
|
|||||||
rpcRequestGauge = metrics.NewRegisteredGauge("rpc/requests", nil)
|
rpcRequestGauge = metrics.NewRegisteredGauge("rpc/requests", nil)
|
||||||
successfulRequestGauge = metrics.NewRegisteredGauge("rpc/success", nil)
|
successfulRequestGauge = metrics.NewRegisteredGauge("rpc/success", nil)
|
||||||
failedRequestGauge = metrics.NewRegisteredGauge("rpc/failure", nil)
|
failedRequestGauge = metrics.NewRegisteredGauge("rpc/failure", nil)
|
||||||
rpcServingTimer = metrics.NewRegisteredTimer("rpc/duration/all", nil)
|
|
||||||
|
// serveTimeHistName is the prefix of the per-request serving time histograms.
|
||||||
|
serveTimeHistName = "rpc/duration"
|
||||||
|
|
||||||
|
rpcServingTimer = metrics.NewRegisteredTimer("rpc/duration/all", nil)
|
||||||
)
|
)
|
||||||
|
|
||||||
func newRPCServingTimer(method string, valid bool) metrics.Timer {
|
// updateServeTimeHistogram tracks the serving time of a remote RPC call.
|
||||||
flag := "success"
|
func updateServeTimeHistogram(method string, success bool, elapsed time.Duration) {
|
||||||
if !valid {
|
note := "success"
|
||||||
flag = "failure"
|
if !success {
|
||||||
|
note = "failure"
|
||||||
}
|
}
|
||||||
m := fmt.Sprintf("rpc/duration/%s/%s", method, flag)
|
h := fmt.Sprintf("%s/%s/%s", serveTimeHistName, method, note)
|
||||||
return metrics.GetOrRegisterTimer(m, nil)
|
sampler := func() metrics.Sample {
|
||||||
|
return metrics.ResettingSample(
|
||||||
|
metrics.NewExpDecaySample(1028, 0.015),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
metrics.GetOrRegisterHistogramLazy(h, nil, sampler).Update(elapsed.Microseconds())
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user