Skip to content

Commit 75ef195

Browse files
committed
port to victoria metrics
1 parent 1f8ac47 commit 75ef195

File tree

4 files changed

+42
-169
lines changed

4 files changed

+42
-169
lines changed

go.mod

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,13 @@ module github.com/flashbots/mev-boost
33
go 1.24.0
44

55
require (
6+
github.com/VictoriaMetrics/metrics v1.40.1
67
github.com/ethereum/go-ethereum v1.15.9
78
github.com/flashbots/go-boost-utils v1.9.0
89
github.com/flashbots/go-utils v0.10.0
910
github.com/google/uuid v1.6.0
1011
github.com/gorilla/mux v1.8.1
1112
github.com/holiman/uint256 v1.3.2
12-
github.com/prometheus/client_golang v1.20.5
1313
github.com/prysmaticlabs/go-bitfield v0.0.0-20240618144021-706c95b2dd15
1414
github.com/sirupsen/logrus v1.9.3
1515
github.com/stretchr/testify v1.10.0
@@ -18,9 +18,7 @@ require (
1818
)
1919

2020
require (
21-
github.com/beorn7/perks v1.0.1 // indirect
2221
github.com/bits-and-blooms/bitset v1.22.0 // indirect
23-
github.com/cespare/xxhash/v2 v2.3.0 // indirect
2422
github.com/consensys/bavard v0.1.30 // indirect
2523
github.com/consensys/gnark-crypto v0.17.0 // indirect
2624
github.com/crate-crypto/go-ipa v0.0.0-20240724233137-53bbb0ceb27a // indirect
@@ -30,17 +28,13 @@ require (
3028
github.com/ethereum/go-verkle v0.2.2 // indirect
3129
github.com/goccy/go-yaml v1.17.1 // indirect
3230
github.com/gofrs/flock v0.12.1 // indirect
33-
github.com/klauspost/compress v1.17.9 // indirect
3431
github.com/mmcloughlin/addchain v0.4.0 // indirect
35-
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect
36-
github.com/prometheus/client_model v0.6.1 // indirect
37-
github.com/prometheus/common v0.55.0 // indirect
38-
github.com/prometheus/procfs v0.15.1 // indirect
3932
github.com/rivo/uniseg v0.4.7 // indirect
4033
github.com/supranational/blst v0.3.14 // indirect
34+
github.com/valyala/fastrand v1.1.0 // indirect
35+
github.com/valyala/histogram v1.2.0 // indirect
4136
github.com/yusufpapurcu/wmi v1.2.4 // indirect
4237
golang.org/x/sync v0.13.0 // indirect
43-
google.golang.org/protobuf v1.34.2 // indirect
4438
rsc.io/tmplfunc v0.0.3 // indirect
4539
)
4640

go.sum

Lines changed: 6 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
github.com/VictoriaMetrics/fastcache v1.12.2 h1:N0y9ASrJ0F6h0QaC3o6uJb3NIZ9VKLjCM7NQbSmF7WI=
22
github.com/VictoriaMetrics/fastcache v1.12.2/go.mod h1:AmC+Nzz1+3G2eCPapF6UcsnkThDcMsQicp4xDukwJYI=
3+
github.com/VictoriaMetrics/metrics v1.40.1 h1:FrF5uJRpIVj9fayWcn8xgiI+FYsKGMslzPuOXjdeyR4=
4+
github.com/VictoriaMetrics/metrics v1.40.1/go.mod h1:XE4uudAAIRaJE614Tl5HMrtoEU6+GDZO4QTnNSsZRuA=
35
github.com/attestantio/go-builder-client v0.7.2 h1:bOrtysEIZd9bEM+mAeT6OtAo6LSAft/qylBLwFoFwZ0=
46
github.com/attestantio/go-builder-client v0.7.2/go.mod h1:+NADxbaknI5yxl+0mCkMa/VciVsesxRMGNP/poDfV08=
57
github.com/attestantio/go-eth2-client v0.27.1 h1:g7bm+gG/p+gfzYdEuxuAepVWYb8EO+2KojV5/Lo2BxM=
68
github.com/attestantio/go-eth2-client v0.27.1/go.mod h1:fvULSL9WtNskkOB4i+Yyr6BKpNHXvmpGZj9969fCrfY=
7-
github.com/beorn7/perks v1.0.1 h1:VlbKKnNfV8bJzeqoa4cOKqO6bYr3WgKZxO8Z16+hsOM=
8-
github.com/beorn7/perks v1.0.1/go.mod h1:G2ZrVWU2WbWT9wwq4/hrbKbnv/1ERSJQ0ibhJ6rlkpw=
99
github.com/bits-and-blooms/bitset v1.22.0 h1:Tquv9S8+SGaS3EhyA+up3FXzmkhxPGjQQCkcs2uw7w4=
1010
github.com/bits-and-blooms/bitset v1.22.0/go.mod h1:7hO7Gc7Pp1vODcmWvKMRA9BNmbv6a/7QIWpPxHddWR8=
1111
github.com/cespare/xxhash/v2 v2.3.0 h1:UL815xU9SqsFlibzuggzjXhog7bL6oX9BbNZnL2UFvs=
@@ -61,8 +61,6 @@ github.com/huandu/go-clone v1.7.2 h1:3+Aq0Ed8XK+zKkLjE2dfHg0XrpIfcohBE1K+c8Usxoo
6161
github.com/huandu/go-clone v1.7.2/go.mod h1:ReGivhG6op3GYr+UY3lS6mxjKp7MIGTknuU5TbTVaXE=
6262
github.com/huandu/go-clone/generic v1.6.0 h1:Wgmt/fUZ28r16F2Y3APotFD59sHk1p78K0XLdbUYN5U=
6363
github.com/huandu/go-clone/generic v1.6.0/go.mod h1:xgd9ZebcMsBWWcBx5mVMCoqMX24gLWr5lQicr+nVXNs=
64-
github.com/klauspost/compress v1.17.9 h1:6KIumPrER1LHsvBVuDa0r5xaG0Es51mhhB9BQB2qeMA=
65-
github.com/klauspost/compress v1.17.9/go.mod h1:Di0epgTjJY877eYKx5yC51cX2A2Vl2ibi7bDH9ttBbw=
6664
github.com/klauspost/cpuid/v2 v2.2.10 h1:tBs3QSyvjDyFTq3uoc/9xFpCuOsJQFNPiAhYdw2skhE=
6765
github.com/klauspost/cpuid/v2 v2.2.10/go.mod h1:hqwkgyIinND0mEev00jJYCxPNVRVXFQeu1XKlok6oO0=
6866
github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE=
@@ -83,22 +81,12 @@ github.com/mitchellh/mapstructure v1.5.0/go.mod h1:bFUtVrKA4DC2yAKiSyO/QUcy7e+RR
8381
github.com/mmcloughlin/addchain v0.4.0 h1:SobOdjm2xLj1KkXN5/n0xTIWyZA2+s99UCY1iPfkHRY=
8482
github.com/mmcloughlin/addchain v0.4.0/go.mod h1:A86O+tHqZLMNO4w6ZZ4FlVQEadcoqkyU72HC5wJ4RlU=
8583
github.com/mmcloughlin/profile v0.1.1/go.mod h1:IhHD7q1ooxgwTgjxQYkACGA77oFTDdFVejUS1/tS/qU=
86-
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 h1:C3w9PqII01/Oq1c1nUAm88MOHcQC9l5mIlSMApZMrHA=
87-
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822/go.mod h1:+n7T8mK8HuQTcFwEeznm/DIxMOiR9yIdICNftLE1DvQ=
8884
github.com/olekukonko/tablewriter v0.0.5 h1:P2Ga83D34wi1o9J6Wh1mRuqd4mF/x/lgBS7N7AbDhec=
8985
github.com/olekukonko/tablewriter v0.0.5/go.mod h1:hPp6KlRPjbx+hW8ykQs1w3UBbZlj6HuIJcUGPhkA7kY=
9086
github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
9187
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
9288
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
9389
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
94-
github.com/prometheus/client_golang v1.20.5 h1:cxppBPuYhUnsO6yo/aoRol4L7q7UFfdm+bR9r+8l63Y=
95-
github.com/prometheus/client_golang v1.20.5/go.mod h1:PIEt8X02hGcP8JWbeHyeZ53Y/jReSnHgO035n//V5WE=
96-
github.com/prometheus/client_model v0.6.1 h1:ZKSh/rekM+n3CeS952MLRAdFwIKqeY8b62p8ais2e9E=
97-
github.com/prometheus/client_model v0.6.1/go.mod h1:OrxVMOVHjw3lKMa8+x6HeMGkHMQyHDk9E3jmP2AmGiY=
98-
github.com/prometheus/common v0.55.0 h1:KEi6DK7lXW/m7Ig5i47x0vRzuBsHuvJdi5ee6Y3G1dc=
99-
github.com/prometheus/common v0.55.0/go.mod h1:2SECS4xJG1kd8XF9IcM1gMX6510RAEL65zxzNImwdc8=
100-
github.com/prometheus/procfs v0.15.1 h1:YagwOFzUgYfKKHX6Dr+sHT7km/hxC76UB0learggepc=
101-
github.com/prometheus/procfs v0.15.1/go.mod h1:fB45yRUv8NstnjriLhBQLuOUt+WW4BsoGhij/e3PBqk=
10290
github.com/prysmaticlabs/go-bitfield v0.0.0-20240618144021-706c95b2dd15 h1:lC8kiphgdOBTcbTvo8MwkvpKjO0SlAgjv4xIK5FGJ94=
10391
github.com/prysmaticlabs/go-bitfield v0.0.0-20240618144021-706c95b2dd15/go.mod h1:8svFBIKKu31YriBG/pNizo9N0Jr9i5PQ+dFkxWg3x5k=
10492
github.com/prysmaticlabs/gohashtree v0.0.4-beta h1:H/EbCuXPeTV3lpKeXGPpEV9gsUpkqOOVnWapUyeWro4=
@@ -128,6 +116,10 @@ github.com/trailofbits/go-fuzz-utils v0.0.0-20240830175354-474de707d2aa h1:jXdW8
128116
github.com/trailofbits/go-fuzz-utils v0.0.0-20240830175354-474de707d2aa/go.mod h1:/7KgvY5ghyUsjocUh9dMkLCwKtNxqe0kWl5SIdpLtO8=
129117
github.com/urfave/cli/v3 v3.2.0 h1:m8WIXY0U9LCuUl5r+0fqLWDhNYWt6qvlW+GcF4EoXf8=
130118
github.com/urfave/cli/v3 v3.2.0/go.mod h1:FJSKtM/9AiiTOJL4fJ6TbMUkxBXn7GO9guZqoZtpYpo=
119+
github.com/valyala/fastrand v1.1.0 h1:f+5HkLW4rsgzdNoleUOB69hyT9IlD2ZQh9GyDMfb5G8=
120+
github.com/valyala/fastrand v1.1.0/go.mod h1:HWqCzkrkg6QXT8V2EXWvXCoow7vLwOFN002oeRzjapQ=
121+
github.com/valyala/histogram v1.2.0 h1:wyYGAZZt3CpwUiIb9AU/Zbllg1llXyrtApRS815OLoQ=
122+
github.com/valyala/histogram v1.2.0/go.mod h1:Hb4kBwb4UxsaNbbbh+RRz8ZR6pdodR57tzWUS3BUzXY=
131123
github.com/yusufpapurcu/wmi v1.2.4 h1:zFUKzehAFReQwLys1b/iSMl+JQGSCSjtVqQn9bBrPo0=
132124
github.com/yusufpapurcu/wmi v1.2.4/go.mod h1:SBZ9tNy3G9/m5Oi98Zks0QjeHVDvuK0qfxQmPyzfmi0=
133125
go.uber.org/goleak v1.3.0 h1:2K3zAYmnTNqV73imy9J1T3WC+gmCePx2hEGkimedGto=
@@ -145,8 +137,6 @@ golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8/go.mod h1:oPkhp1MJrh7nUepCBc
145137
golang.org/x/sys v0.1.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
146138
golang.org/x/sys v0.32.0 h1:s77OFDvIQeibCmezSnk/q6iAfkdiQaJi4VzroCFrN20=
147139
golang.org/x/sys v0.32.0/go.mod h1:BJP2sWEmIv4KK5OTEluFJCKSidICx8ciO85XgH3Ak8k=
148-
google.golang.org/protobuf v1.34.2 h1:6xV6lTsCfpGD21XK49h7MhtcApnLqkfYgPcdHftf6hg=
149-
google.golang.org/protobuf v1.34.2/go.mod h1:qYOHts0dSfpeUzUFpOMr/WGzszTmLH+DiWniOlNbLDw=
150140
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
151141
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk=
152142
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q=

server/metrics.go

Lines changed: 28 additions & 127 deletions
Original file line numberDiff line numberDiff line change
@@ -1,157 +1,58 @@
11
package server
22

33
import (
4-
"sync"
4+
"fmt"
55

6-
"github.com/prometheus/client_golang/prometheus"
6+
"github.com/VictoriaMetrics/metrics"
77
)
88

9-
const Namespace = "mev_boost"
10-
11-
// labels
9+
var winningBidValue = metrics.NewHistogram("mev_boost_winning_bid_value")
1210

1311
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"}`
2919
)
3020

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-
11721
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()
12124
}
12225

12326
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)
12729
}
12830

12931
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()
13334
}
13435

13536
func RecordWinningBidValue(value float64) {
136-
if WinningBidValue != nil {
137-
WinningBidValue.WithLabelValues().Observe(value)
138-
}
37+
winningBidValue.Update(value)
13938
}
14039

14140
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)
14543
}
14644

14745
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()
15148
}
15249

15350
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)
15758
}

server/service.go

Lines changed: 5 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import (
1313
"sync/atomic"
1414
"time"
1515

16+
"github.com/VictoriaMetrics/metrics"
1617
"github.com/attestantio/go-eth2-client/spec/phase0"
1718
"github.com/flashbots/go-boost-utils/ssz"
1819
"github.com/flashbots/go-utils/httplogger"
@@ -21,9 +22,6 @@ import (
2122
"github.com/flashbots/mev-boost/server/types"
2223
"github.com/google/uuid"
2324
"github.com/gorilla/mux"
24-
"github.com/prometheus/client_golang/prometheus"
25-
"github.com/prometheus/client_golang/prometheus/collectors"
26-
"github.com/prometheus/client_golang/prometheus/promhttp"
2725
"github.com/sirupsen/logrus"
2826
goacceptheaders "github.com/timewasted/go-accept-headers"
2927
)
@@ -195,22 +193,12 @@ func (m *BoostService) StartHTTPServer() error {
195193
return err
196194
}
197195

198-
// StartMetricsServer starts the HTTP server for exporting open-metrics
196+
// StartMetricsServer starts the HTTP server for exporting metrics
199197
func (m *BoostService) StartMetricsServer() error {
200-
prometheusRegistry := prometheus.NewRegistry()
201-
if err := prometheusRegistry.Register(collectors.NewGoCollector()); err != nil {
202-
m.log.WithError(err).Error("failed to register metrics for GoCollector")
203-
}
204-
if err := prometheusRegistry.Register(collectors.NewProcessCollector(collectors.ProcessCollectorOpts{})); err != nil {
205-
m.log.WithError(err).Error("failed to register ProcessCollector")
206-
}
207-
RegisterMetrics(prometheusRegistry)
208-
209198
serveMux := http.NewServeMux()
210-
serveMux.Handle("/metrics", promhttp.HandlerFor(prometheusRegistry, promhttp.HandlerOpts{
211-
ErrorLog: m.log,
212-
EnableOpenMetrics: true,
213-
}))
199+
serveMux.HandleFunc("/metrics", func(w http.ResponseWriter, _ *http.Request) {
200+
metrics.WritePrometheus(w, true)
201+
})
214202
return http.ListenAndServe(m.metricsAddr, serveMux)
215203
}
216204

0 commit comments

Comments
 (0)