|
1 | 1 | package server |
2 | 2 |
|
3 | 3 | import ( |
4 | | - "sync" |
| 4 | + "fmt" |
5 | 5 |
|
6 | | - "github.com/prometheus/client_golang/prometheus" |
| 6 | + "github.com/VictoriaMetrics/metrics" |
7 | 7 | ) |
8 | 8 |
|
9 | | -const Namespace = "mev_boost" |
10 | | - |
11 | | -// labels |
| 9 | +var winningBidValue = metrics.NewHistogram("mev_boost_winning_bid_value") |
12 | 10 |
|
13 | 11 | const ( |
14 | | - Endpoint = "endpoint" |
15 | | - Relay = "relay" |
16 | | - HTTPStatusCode = "http_status_code" |
17 | | -) |
18 | | - |
19 | | -var ( |
20 | | - metricsInitOnce sync.Once |
21 | | - BeaconNodeStatus *prometheus.CounterVec |
22 | | - BidValues *prometheus.HistogramVec |
23 | | - BidsBelowMinBid *prometheus.CounterVec |
24 | | - WinningBidValue *prometheus.HistogramVec |
25 | | - RelayLatency *prometheus.HistogramVec |
26 | | - RelayStatusCode *prometheus.CounterVec |
27 | | - RelayLastSlot *prometheus.GaugeVec |
28 | | - MsIntoSlot *prometheus.HistogramVec |
| 12 | + beaconNodeStatusLabel = `mev_boost_beacon_node_status_code_total{http_status_code="%s",endpoint="%s"}` |
| 13 | + bidValuesLabel = `mev_boost_bid_values{relay="%s"}` |
| 14 | + bidsBelowMinBidLabel = `mev_boost_bids_below_min_bid_total{relay="%s"}` |
| 15 | + relayLatencyLabel = `mev_boost_relay_latency{endpoint="%s",relay="%s"}` |
| 16 | + relayStatusCodeLabel = `mev_boost_relay_status_code_total{http_status_code="%s",endpoint="%s",relay="%s"}` |
| 17 | + relayLastSlotLabel = `mev_boost_relay_last_slot{relay="%s"}` |
| 18 | + msIntoSlotLabel = `mev_boost_millisec_into_slot{endpoint="%s"}` |
29 | 19 | ) |
30 | 20 |
|
31 | | -func RegisterMetrics(registry *prometheus.Registry) { |
32 | | - metricsInitOnce.Do(func() { |
33 | | - BeaconNodeStatus = prometheus.NewCounterVec( |
34 | | - prometheus.CounterOpts{ |
35 | | - Namespace: Namespace, |
36 | | - Name: "beacon_node_status_code_total", |
37 | | - Help: "http status code returned to beacon node", |
38 | | - }, |
39 | | - []string{HTTPStatusCode, Endpoint}, |
40 | | - ) |
41 | | - |
42 | | - BidValues = prometheus.NewHistogramVec( |
43 | | - prometheus.HistogramOpts{ |
44 | | - Namespace: Namespace, |
45 | | - Name: "bid_values", |
46 | | - Help: "Value of the bids seen per relay", |
47 | | - }, |
48 | | - []string{Relay}, |
49 | | - ) |
50 | | - |
51 | | - BidsBelowMinBid = prometheus.NewCounterVec( |
52 | | - prometheus.CounterOpts{ |
53 | | - Namespace: Namespace, |
54 | | - Name: "bids_below_min_bid", |
55 | | - Help: "Number of bids per relay which are below the min bid", |
56 | | - }, |
57 | | - []string{Relay}, |
58 | | - ) |
59 | | - |
60 | | - WinningBidValue = prometheus.NewHistogramVec( |
61 | | - prometheus.HistogramOpts{ |
62 | | - Namespace: Namespace, |
63 | | - Name: "winning_bid_value", |
64 | | - Help: "Value of the winning bid", |
65 | | - }, |
66 | | - []string{}, |
67 | | - ) |
68 | | - |
69 | | - RelayLatency = prometheus.NewHistogramVec( |
70 | | - prometheus.HistogramOpts{ |
71 | | - Namespace: Namespace, |
72 | | - Name: "relay_latency", |
73 | | - Help: "http latency by relay", |
74 | | - }, |
75 | | - []string{Endpoint, Relay}, |
76 | | - ) |
77 | | - |
78 | | - RelayStatusCode = prometheus.NewCounterVec( |
79 | | - prometheus.CounterOpts{ |
80 | | - Namespace: Namespace, |
81 | | - Name: "relay_status_code_total", |
82 | | - Help: "http status code received by relay", |
83 | | - }, |
84 | | - []string{HTTPStatusCode, Endpoint, Relay}, |
85 | | - ) |
86 | | - |
87 | | - RelayLastSlot = prometheus.NewGaugeVec( |
88 | | - prometheus.GaugeOpts{ |
89 | | - Namespace: Namespace, |
90 | | - Name: "relay_last_slot", |
91 | | - Help: "Last slot for which relay delivered a header", |
92 | | - }, |
93 | | - []string{Relay}, |
94 | | - ) |
95 | | - |
96 | | - MsIntoSlot = prometheus.NewHistogramVec( |
97 | | - prometheus.HistogramOpts{ |
98 | | - Namespace: Namespace, |
99 | | - Name: "millisec_into_slot", |
100 | | - Help: "Milliseconds into the slot when endpoint was called", |
101 | | - }, |
102 | | - []string{Endpoint}, |
103 | | - ) |
104 | | - registry.MustRegister( |
105 | | - BeaconNodeStatus, |
106 | | - BidValues, |
107 | | - BidsBelowMinBid, |
108 | | - WinningBidValue, |
109 | | - RelayLatency, |
110 | | - RelayStatusCode, |
111 | | - RelayLastSlot, |
112 | | - MsIntoSlot, |
113 | | - ) |
114 | | - }) |
115 | | -} |
116 | | - |
117 | 21 | func IncrementBeaconNodeStatus(status, endpoint string) { |
118 | | - if BeaconNodeStatus != nil { |
119 | | - BeaconNodeStatus.WithLabelValues(status, endpoint).Inc() |
120 | | - } |
| 22 | + l := fmt.Sprintf(beaconNodeStatusLabel, status, endpoint) |
| 23 | + metrics.GetOrCreateCounter(l).Inc() |
121 | 24 | } |
122 | 25 |
|
123 | 26 | func RecordBidValue(relay string, value float64) { |
124 | | - if BidValues != nil { |
125 | | - BidValues.WithLabelValues(relay).Observe(value) |
126 | | - } |
| 27 | + l := fmt.Sprintf(bidValuesLabel, relay) |
| 28 | + metrics.GetOrCreateHistogram(l).Update(value) |
127 | 29 | } |
128 | 30 |
|
129 | 31 | func IncrementBidBelowMinBid(relay string) { |
130 | | - if BidsBelowMinBid != nil { |
131 | | - BidsBelowMinBid.WithLabelValues(relay).Inc() |
132 | | - } |
| 32 | + l := fmt.Sprintf(bidsBelowMinBidLabel, relay) |
| 33 | + metrics.GetOrCreateCounter(l).Inc() |
133 | 34 | } |
134 | 35 |
|
135 | 36 | func RecordWinningBidValue(value float64) { |
136 | | - if WinningBidValue != nil { |
137 | | - WinningBidValue.WithLabelValues().Observe(value) |
138 | | - } |
| 37 | + winningBidValue.Update(value) |
139 | 38 | } |
140 | 39 |
|
141 | 40 | func RecordRelayLatency(endpoint, relay string, latency float64) { |
142 | | - if RelayLatency != nil { |
143 | | - RelayLatency.WithLabelValues(endpoint, relay).Observe(latency) |
144 | | - } |
| 41 | + l := fmt.Sprintf(relayLatencyLabel, endpoint, relay) |
| 42 | + metrics.GetOrCreateHistogram(l).Update(latency) |
145 | 43 | } |
146 | 44 |
|
147 | 45 | func RecordRelayStatusCode(httpStatus, endpoint, relay string) { |
148 | | - if RelayStatusCode != nil { |
149 | | - RelayStatusCode.WithLabelValues(httpStatus, endpoint, relay).Inc() |
150 | | - } |
| 46 | + l := fmt.Sprintf(relayStatusCodeLabel, httpStatus, endpoint, relay) |
| 47 | + metrics.GetOrCreateCounter(l).Inc() |
151 | 48 | } |
152 | 49 |
|
153 | 50 | func RecordRelayLastSlot(relay string, slot uint64) { |
154 | | - if RelayLastSlot != nil { |
155 | | - RelayLastSlot.WithLabelValues(relay).Set(float64(slot)) |
156 | | - } |
| 51 | + l := fmt.Sprintf(relayLastSlotLabel, relay) |
| 52 | + metrics.GetOrCreateGauge(l, nil).Set(float64(slot)) |
| 53 | +} |
| 54 | + |
| 55 | +func RecordMsIntoSlot(endpoint string, ms float64) { |
| 56 | + l := fmt.Sprintf(msIntoSlotLabel, endpoint) |
| 57 | + metrics.GetOrCreateHistogram(l).Update(ms) |
157 | 58 | } |
0 commit comments