-
Notifications
You must be signed in to change notification settings - Fork 147
/
chain_webapi.go
71 lines (60 loc) · 2.22 KB
/
chain_webapi.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
package metrics
import (
"fmt"
"time"
"github.com/prometheus/client_golang/prometheus"
"github.com/iotaledger/wasp/packages/isc"
)
type ChainWebAPIMetricsProvider struct {
requests *prometheus.HistogramVec
evmRPCCalls *prometheus.HistogramVec
}
func newChainWebAPIMetricsProvider() *ChainWebAPIMetricsProvider {
return &ChainWebAPIMetricsProvider{
requests: prometheus.NewHistogramVec(prometheus.HistogramOpts{
Namespace: "iota_wasp",
Subsystem: "webapi",
Name: "webapi_requests",
Help: "Time elapsed (s) processing requests",
Buckets: execTimeBuckets,
}, []string{labelNameChain, labelNameWebapiRequestOperation, labelNameWebapiRequestStatusCode}),
evmRPCCalls: prometheus.NewHistogramVec(prometheus.HistogramOpts{
Namespace: "iota_wasp",
Subsystem: "webapi",
Name: "webapi_evm_rpc_calls",
Help: "Time elapsed (s) processing evm rpc requests",
Buckets: execTimeBuckets,
}, []string{labelNameChain, labelNameWebapiRequestOperation, labelNameWebapiEvmRPCSuccess}),
}
}
func (p *ChainWebAPIMetricsProvider) register(reg prometheus.Registerer) {
reg.MustRegister(
p.requests,
p.evmRPCCalls,
)
}
func (p *ChainWebAPIMetricsProvider) createForChain(chainID isc.ChainID) *ChainWebAPIMetrics {
return newChainWebAPIMetrics(p, chainID)
}
type ChainWebAPIMetrics struct {
collectors *ChainWebAPIMetricsProvider
chainID isc.ChainID
}
func newChainWebAPIMetrics(collectors *ChainWebAPIMetricsProvider, chainID isc.ChainID) *ChainWebAPIMetrics {
return &ChainWebAPIMetrics{
collectors: collectors,
chainID: chainID,
}
}
func (m *ChainWebAPIMetrics) WebAPIRequest(operation string, httpStatusCode int, duration time.Duration) {
labels := getChainLabels(m.chainID)
labels[labelNameWebapiRequestOperation] = operation
labels[labelNameWebapiRequestStatusCode] = fmt.Sprintf("%d", httpStatusCode)
m.collectors.requests.With(labels).Observe(duration.Seconds())
}
func (m *ChainWebAPIMetrics) EVMRPCCall(operation string, success bool, duration time.Duration) {
labels := getChainLabels(m.chainID)
labels[labelNameWebapiRequestOperation] = operation
labels[labelNameWebapiEvmRPCSuccess] = fmt.Sprintf("%v", success)
m.collectors.evmRPCCalls.With(labels).Observe(duration.Seconds())
}