-
Notifications
You must be signed in to change notification settings - Fork 18
/
metrics.go
98 lines (89 loc) · 2.57 KB
/
metrics.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
/*
* Copyright 2021 KardiaChain
* This file is part of the go-kardia library.
*
* The go-kardia library is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* The go-kardia library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with the go-kardia library. If not, see <http://www.gnu.org/licenses/>.
*/
package rpc
import (
"fmt"
"github.com/kardiachain/go-kardia/lib/metrics"
)
func init() {
for _, method := range kaiRPCMethods {
metrics.NewRegisteredGauge(method, metrics.RPCRegistry)
}
for _, method := range ethRPCMethods {
metrics.NewRegisteredGauge(method, metrics.RPCRegistry)
}
}
var (
rpcRequestGauge = metrics.NewRegisteredGauge("rpc/requests", nil)
successfulRequestGauge = metrics.NewRegisteredGauge("rpc/success", nil)
failedReqeustGauge = metrics.NewRegisteredGauge("rpc/failure", nil)
rpcServingTimer = metrics.NewRegisteredTimer("rpc/duration/all", nil)
)
func newRPCServingTimer(method string, valid bool) metrics.Timer {
flag := "success"
if !valid {
flag = "failure"
}
m := fmt.Sprintf("rpc/duration/%s/%s", method, flag)
return metrics.GetOrRegisterTimer(m, nil)
}
// pre-register types of RPC API call we want to track
var (
kaiRPCMethods = []string{
"kai_getBlockByHash",
"kai_getBlockByNumber",
"kai_blockNumber",
"kai_kardiaCall",
"account_nonce",
"account_balance",
"account_getCode",
"account_getStorageAt",
"kai_estimateGas",
"tx_sendRawTransaction",
"tx_getTransaction",
"tx_getTransactionReceipt",
"kai_gasPrice",
// KAI only
"kai_validator",
"kai_validators",
"kai_getValidatorSet",
"tx_pendingTransactions",
"debug_traceTransaction",
"debug_traceCall",
}
ethRPCMethods = []string{
"eth_getBlockByHash",
"eth_getBlockByNumber",
"eth_blockNumber",
"eth_call",
"eth_getTransactionCount",
"eth_getBalance",
"eth_getCode",
"eth_getStorageAt",
"eth_estimateGas",
"eth_sendRawTransaction",
"eth_getTransactionByHash",
"eth_getTransactionReceipt",
"eth_gasPrice",
// ETH only
"eth_chainId",
"eth_accounts",
"eth_getTransactionByBlockHashAndIndex",
"eth_getTransactionByBlockNumberAndIndex",
}
)