github.com/amazechain/amc@v0.1.3/modules/rpc/jsonrpc/metrics.go (about) 1 package jsonrpc 2 3 import ( 4 "fmt" 5 "github.com/amazechain/amc/internal/metrics/prometheus" 6 ) 7 8 var ( 9 rpcMetricsLabels = map[bool]map[string]string{} 10 rpcRequestGauge = prometheus.GetOrCreateCounter("rpc_total") 11 failedReqeustGauge = prometheus.GetOrCreateCounter("rpc_failure") 12 ) 13 14 func createRPCMetricsLabel(method string, valid bool) string { 15 status := "failure" 16 if valid { 17 status = "success" 18 } 19 20 return fmt.Sprintf(`rpc_duration_seconds{method="%s",success="%s"}`, method, status) 21 22 } 23 24 func newRPCServingTimerMS(method string, valid bool) prometheus.Summary { 25 label, ok := rpcMetricsLabels[valid][method] 26 if !ok { 27 label = createRPCMetricsLabel(method, valid) 28 } 29 30 return prometheus.GetOrCreateSummary(label) 31 }