-
Notifications
You must be signed in to change notification settings - Fork 17
/
metrics.go
174 lines (161 loc) · 6.54 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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
package monitoring
import (
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/client_golang/prometheus/promauto"
relayMonitoring "github.com/smartcontractkit/chainlink-common/pkg/monitoring"
)
// Metrics is an interface for prometheus metrics. Makes testing easier.
type Metrics interface {
SetReportObservations(answer float64, accountAddress, feedID, chainID, contractStatus, contractType, feedName, feedPath, networkID, networkName string)
CleanupReportObservations(accountAddress, feedID, chainID, contractStatus, contractType, feedName, feedPath, networkID, networkName string)
SetProxyAnswersRaw(answer float64, proxyContractAddress, feedID, chainID, contractStatus, contractType, feedName, feedPath, networkID, networkName string)
SetProxyAnswers(answer float64, proxyContractAddress, feedID, chainID, contractStatus, contractType, feedName, feedPath, networkID, networkName string)
CleanupProxy(proxyContractAddress, feedID, chainID, contractStatus, contractType, feedName, feedPath, networkID, networkName string)
SetBalance(answer float64, contractAddress, alias, networkId, networkName, chainID string)
CleanupBalance(contractAddress, alias, networkId, networkName, chainID string)
}
var (
reportObservations = promauto.NewGaugeVec(
prometheus.GaugeOpts{
Name: "report_observations",
Help: "Reports # of observations included in a transmission report",
},
[]string{
"account_address",
"feed_id",
"chain_id",
"contract_status",
"contract_type",
"feed_name",
"feed_path",
"network_id",
"network_name",
},
)
proxyAnswersRaw = promauto.NewGaugeVec(
prometheus.GaugeOpts{
Name: "proxy_answers_raw",
Help: "Reports the latest raw answer from the proxy contract.",
},
[]string{"proxy_contract_address", "feed_id", "chain_id", "contract_status", "contract_type", "feed_name", "feed_path", "network_id", "network_name"},
)
proxyAnswers = promauto.NewGaugeVec(
prometheus.GaugeOpts{
Name: "proxy_answers",
Help: "Reports the latest answer from the proxy contract divided by the feed's multiplier parameter.",
},
[]string{"proxy_contract_address", "feed_id", "chain_id", "contract_status", "contract_type", "feed_name", "feed_path", "network_id", "network_name"},
)
contractBalance = promauto.NewGaugeVec(
prometheus.GaugeOpts{
Name: "strk_contract_balance",
Help: "Reports the latest STRK balance of a contract address",
},
[]string{"contract_address", "alias", "network_id", "network_name", "chain_id"},
)
)
// NewMetrics does wisott
func NewMetrics(log relayMonitoring.Logger) Metrics {
return &defaultMetrics{log}
}
type defaultMetrics struct {
log relayMonitoring.Logger
}
func (d *defaultMetrics) SetBalance(answer float64, contractAddress, alias, networkId, networkName, chainID string) {
contractBalance.With(prometheus.Labels{
"contract_address": contractAddress,
"alias": alias,
"network_id": networkId,
"network_name": networkName,
"chain_id": chainID,
}).Set(answer)
}
func (d *defaultMetrics) CleanupBalance(contractAddress, alias, networkId, networkName, chainID string) {
labels := prometheus.Labels{
"contract_address": contractAddress,
"alias": alias,
"network_id": networkId,
"network_name": networkName,
"chain_id": chainID,
}
if !contractBalance.Delete(labels) {
d.log.Errorw("failed to delete metric", "name", "strk_contract_balance", "labels", labels)
}
}
func (d *defaultMetrics) SetReportObservations(answer float64, accountAddress, feedID, chainID, contractStatus, contractType, feedName, feedPath, networkID, networkName string) {
reportObservations.With(prometheus.Labels{
"account_address": accountAddress,
"feed_id": feedID,
"chain_id": chainID,
"contract_status": contractStatus,
"contract_type": contractType,
"feed_name": feedName,
"feed_path": feedPath,
"network_id": networkID,
"network_name": networkName,
}).Set(answer)
}
func (d *defaultMetrics) CleanupReportObservations(accountAddress, feedID, chainID, contractStatus, contractType, feedName, feedPath, networkID, networkName string) {
labels := prometheus.Labels{
"account_address": accountAddress,
"feed_id": feedID,
"chain_id": chainID,
"contract_status": contractStatus,
"contract_type": contractType,
"feed_name": feedName,
"feed_path": feedPath,
"network_id": networkID,
"network_name": networkName,
}
if !reportObservations.Delete(labels) {
d.log.Errorw("failed to delete metric", "name", "report_observations", "labels", labels)
}
}
func (d *defaultMetrics) SetProxyAnswersRaw(answer float64, proxyContractAddress, feedID, chainID, contractStatus, contractType, feedName, feedPath, networkID, networkName string) {
proxyAnswersRaw.With(prometheus.Labels{
"proxy_contract_address": proxyContractAddress,
"feed_id": feedID,
"chain_id": chainID,
"contract_status": contractStatus,
"contract_type": contractType,
"feed_name": feedName,
"feed_path": feedPath,
"network_id": networkID,
"network_name": networkName,
}).Set(answer)
}
func (d *defaultMetrics) SetProxyAnswers(answer float64, proxyContractAddress, feedID, chainID, contractStatus, contractType, feedName, feedPath, networkID, networkName string) {
proxyAnswers.With(prometheus.Labels{
"proxy_contract_address": proxyContractAddress,
"feed_id": feedID,
"chain_id": chainID,
"contract_status": contractStatus,
"contract_type": contractType,
"feed_name": feedName,
"feed_path": feedPath,
"network_id": networkID,
"network_name": networkName,
}).Set(answer)
}
func (d *defaultMetrics) CleanupProxy(
proxyContractAddress, feedID, chainID, contractStatus, contractType string,
feedName, feedPath, networkID, networkName string,
) {
labels := prometheus.Labels{
"proxy_contract_address": proxyContractAddress,
"feed_id": feedID,
"chain_id": chainID,
"contract_status": contractStatus,
"contract_type": contractType,
"feed_name": feedName,
"feed_path": feedPath,
"network_id": networkID,
"network_name": networkName,
}
if !proxyAnswersRaw.Delete(labels) {
d.log.Errorw("failed to delete metric", "name", "proxy_answers_raw", "labels", labels)
}
if !proxyAnswers.Delete(labels) {
d.log.Errorw("failed to delete metric", "name", "proxy_answers", "labels", labels)
}
}